mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-05 05:21:03 +08:00
Revert "Merge branch 'v3-alpha-linux-systray' into v3-alpha"
This reverts commit92b26488da
, reversing changes made to1c48d567e1
.
This commit is contained in:
parent
d8e27aa5f9
commit
dbcf65b2d6
@ -79,7 +79,6 @@ func (m *linuxApp) getApplicationMenu() pointer {
|
|||||||
|
|
||||||
menu := globalApplication.ApplicationMenu
|
menu := globalApplication.ApplicationMenu
|
||||||
if menu != nil {
|
if menu != nil {
|
||||||
menu.impl = newMenuBarImpl(menu)
|
|
||||||
InvokeSync(func() {
|
InvokeSync(func() {
|
||||||
menu.Update()
|
menu.Update()
|
||||||
})
|
})
|
||||||
|
@ -4,9 +4,6 @@ package application
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -15,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0 ayatana-appindicator3-0.1
|
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
@ -23,15 +20,12 @@ import (
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef G_APPLICATION_DEFAULT_FLAGS
|
#ifdef G_APPLICATION_DEFAULT_FLAGS
|
||||||
#define APPLICATION_DEFAULT_FLAGS G_APPLICATION_DEFAULT_FLAGS
|
#define APPLICATION_DEFAULT_FLAGS G_APPLICATION_DEFAULT_FLAGS
|
||||||
#else
|
#else
|
||||||
#define APPLICATION_DEFAULT_FLAGS G_APPLICATION_FLAGS_NONE
|
#define APPLICATION_DEFAULT_FLAGS G_APPLICATION_FLAGS_NONE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <libayatana-appindicator/app-indicator.h>
|
|
||||||
|
|
||||||
typedef struct CallbackID
|
typedef struct CallbackID
|
||||||
{
|
{
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
@ -297,11 +291,10 @@ func menuAddSeparator(menu *Menu) {
|
|||||||
C.gtk_separator_menu_item_new())
|
C.gtk_separator_menu_item_new())
|
||||||
}
|
}
|
||||||
|
|
||||||
func menuAppend(parent *Menu, item *MenuItem) {
|
func menuAppend(parent *Menu, menu *MenuItem) {
|
||||||
|
|
||||||
C.gtk_menu_shell_append(
|
C.gtk_menu_shell_append(
|
||||||
(*C.GtkMenuShell)((parent.impl).(*linuxMenu).native),
|
(*C.GtkMenuShell)((parent.impl).(*linuxMenu).native),
|
||||||
(*C.GtkWidget)((item.impl).(*linuxMenuItem).native),
|
(*C.GtkWidget)((menu.impl).(*linuxMenuItem).native),
|
||||||
)
|
)
|
||||||
/* gtk4
|
/* gtk4
|
||||||
C.gtk_menu_item_set_submenu(
|
C.gtk_menu_item_set_submenu(
|
||||||
@ -379,17 +372,13 @@ func menuItemChecked(widget pointer) bool {
|
|||||||
func menuItemNew(label string) pointer {
|
func menuItemNew(label string) pointer {
|
||||||
cLabel := C.CString(label)
|
cLabel := C.CString(label)
|
||||||
defer C.free(unsafe.Pointer(cLabel))
|
defer C.free(unsafe.Pointer(cLabel))
|
||||||
item := C.gtk_menu_item_new_with_label(cLabel)
|
return pointer(C.gtk_menu_item_new_with_label(cLabel))
|
||||||
C.gtk_widget_show((*C.GtkWidget)(item))
|
|
||||||
return pointer(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func menuCheckItemNew(label string) pointer {
|
func menuCheckItemNew(label string) pointer {
|
||||||
cLabel := C.CString(label)
|
cLabel := C.CString(label)
|
||||||
defer C.free(unsafe.Pointer(cLabel))
|
defer C.free(unsafe.Pointer(cLabel))
|
||||||
item := C.gtk_check_menu_item_new_with_label(cLabel)
|
return pointer(C.gtk_check_menu_item_new_with_label(cLabel))
|
||||||
C.gtk_widget_show((*C.GtkWidget)(item))
|
|
||||||
return pointer(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func menuItemSetChecked(widget pointer, checked bool) {
|
func menuItemSetChecked(widget pointer, checked bool) {
|
||||||
@ -629,7 +618,7 @@ func windowMinimize(window pointer) {
|
|||||||
C.gtk_window_iconify((*C.GtkWindow)(window))
|
C.gtk_window_iconify((*C.GtkWindow)(window))
|
||||||
}
|
}
|
||||||
|
|
||||||
func windowNew(application pointer, menuBar pointer, windowId uint, gpuPolicy int) (window, webview, vbox pointer) {
|
func windowNew(application pointer, menu pointer, windowId uint, gpuPolicy int) (window, webview, vbox pointer) {
|
||||||
window = pointer(C.gtk_application_window_new((*C.GtkApplication)(application)))
|
window = pointer(C.gtk_application_window_new((*C.GtkApplication)(application)))
|
||||||
C.g_object_ref_sink(C.gpointer(window))
|
C.g_object_ref_sink(C.gpointer(window))
|
||||||
webview = windowNewWebview(windowId, gpuPolicy)
|
webview = windowNewWebview(windowId, gpuPolicy)
|
||||||
@ -637,9 +626,10 @@ func windowNew(application pointer, menuBar pointer, windowId uint, gpuPolicy in
|
|||||||
name := C.CString("webview-box")
|
name := C.CString("webview-box")
|
||||||
defer C.free(unsafe.Pointer(name))
|
defer C.free(unsafe.Pointer(name))
|
||||||
C.gtk_widget_set_name((*C.GtkWidget)(vbox), name)
|
C.gtk_widget_set_name((*C.GtkWidget)(vbox), name)
|
||||||
|
|
||||||
C.gtk_container_add((*C.GtkContainer)(window), (*C.GtkWidget)(vbox))
|
C.gtk_container_add((*C.GtkContainer)(window), (*C.GtkWidget)(vbox))
|
||||||
if menuBar != nil {
|
if menu != nil {
|
||||||
C.gtk_box_pack_start((*C.GtkBox)(vbox), (*C.GtkWidget)(menuBar), 0, 0, 0)
|
C.gtk_box_pack_start((*C.GtkBox)(vbox), (*C.GtkWidget)(menu), 0, 0, 0)
|
||||||
}
|
}
|
||||||
C.gtk_box_pack_start((*C.GtkBox)(unsafe.Pointer(vbox)), (*C.GtkWidget)(webview), 1, 1, 0)
|
C.gtk_box_pack_start((*C.GtkBox)(unsafe.Pointer(vbox)), (*C.GtkWidget)(webview), 1, 1, 0)
|
||||||
return
|
return
|
||||||
@ -1169,58 +1159,3 @@ func runSaveFileDialog(dialog *SaveFileDialogStruct) (chan string, error) {
|
|||||||
|
|
||||||
return results, err
|
return results, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// systray
|
|
||||||
func systrayDestroy(tray pointer) {
|
|
||||||
// FIXME: this is not the correct way to remove our systray
|
|
||||||
// C.g_object_unref(C.gpointer(tray))
|
|
||||||
}
|
|
||||||
|
|
||||||
func systrayNew(label string) pointer {
|
|
||||||
labelStr := C.CString(label)
|
|
||||||
defer C.free(unsafe.Pointer(labelStr))
|
|
||||||
emptyStr := C.CString("")
|
|
||||||
defer C.free(unsafe.Pointer(emptyStr))
|
|
||||||
indicator := C.app_indicator_new(labelStr, labelStr, C.APP_INDICATOR_CATEGORY_APPLICATION_STATUS)
|
|
||||||
C.app_indicator_set_status(indicator, C.APP_INDICATOR_STATUS_ACTIVE)
|
|
||||||
iconStr := C.CString("wails-systray-icon")
|
|
||||||
defer C.free(unsafe.Pointer(iconStr))
|
|
||||||
C.app_indicator_set_icon_full(indicator, iconStr, emptyStr)
|
|
||||||
systraySetLabel(pointer(indicator), label)
|
|
||||||
return pointer(indicator)
|
|
||||||
}
|
|
||||||
|
|
||||||
func systraySetTitle(tray pointer, title string) {
|
|
||||||
titleStr := C.CString(title)
|
|
||||||
defer C.free(unsafe.Pointer(titleStr))
|
|
||||||
C.app_indicator_set_title((*C.AppIndicator)(tray), titleStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func systraySetLabel(tray pointer, label string) {
|
|
||||||
labelStr := C.CString(label)
|
|
||||||
defer C.free(unsafe.Pointer(labelStr))
|
|
||||||
emptyStr := C.CString("")
|
|
||||||
defer C.free(unsafe.Pointer(emptyStr))
|
|
||||||
C.app_indicator_set_label((*C.AppIndicator)(tray), labelStr, labelStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func systrayMenuSet(tray pointer, menu pointer) {
|
|
||||||
C.app_indicator_set_menu(
|
|
||||||
(*C.AppIndicator)(tray),
|
|
||||||
(*C.GtkMenu)(unsafe.Pointer(menu)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func systraySetTemplateIcon(tray pointer, icon []byte) {
|
|
||||||
dirname, err := os.UserHomeDir()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
file := filepath.Join(dirname, ".icons", "wails-systray-icon.png")
|
|
||||||
if err := os.WriteFile(file, icon, 0666); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
systrayStr := C.CString("wails-systray-icon")
|
|
||||||
defer C.free(unsafe.Pointer(systrayStr))
|
|
||||||
|
|
||||||
C.app_indicator_set_attention_icon_full((*C.AppIndicator)(tray), systrayStr, systrayStr)
|
|
||||||
}
|
|
||||||
|
@ -8,14 +8,6 @@ type linuxMenu struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newMenuImpl(menu *Menu) *linuxMenu {
|
func newMenuImpl(menu *Menu) *linuxMenu {
|
||||||
result := &linuxMenu{
|
|
||||||
menu: menu,
|
|
||||||
native: menuNew(),
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMenuBarImpl(menu *Menu) *linuxMenu {
|
|
||||||
result := &linuxMenu{
|
result := &linuxMenu{
|
||||||
menu: menu,
|
menu: menu,
|
||||||
native: menuBarNew(),
|
native: menuBarNew(),
|
||||||
|
@ -103,7 +103,6 @@ func newMenuItemImpl(item *MenuItem) *linuxMenuItem {
|
|||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("Unknown menu type: %v", item.itemType))
|
panic(fmt.Sprintf("Unknown menu type: %v", item.itemType))
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setDisabled(result.menuItem.disabled)
|
result.setDisabled(result.menuItem.disabled)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
//go:build linux
|
//go:build linux
|
||||||
|
|
||||||
package application
|
package application
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
type linuxSystemTray struct {
|
type linuxSystemTray struct {
|
||||||
id uint
|
id uint
|
||||||
label string
|
label string
|
||||||
@ -10,8 +12,6 @@ type linuxSystemTray struct {
|
|||||||
|
|
||||||
iconPosition int
|
iconPosition int
|
||||||
isTemplateIcon bool
|
isTemplateIcon bool
|
||||||
tray pointer
|
|
||||||
nativeMenu pointer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) setIconPosition(position int) {
|
func (s *linuxSystemTray) setIconPosition(position int) {
|
||||||
@ -19,10 +19,8 @@ func (s *linuxSystemTray) setIconPosition(position int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) setMenu(menu *Menu) {
|
func (s *linuxSystemTray) setMenu(menu *Menu) {
|
||||||
|
fmt.Println("linuxSystemTray.SetMenu")
|
||||||
s.menu = menu
|
s.menu = menu
|
||||||
s.menu.impl = newMenuImpl(menu)
|
|
||||||
menu.Update()
|
|
||||||
systrayMenuSet(s.tray, (menu.impl).(*linuxMenu).native)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) positionWindow(window *WebviewWindow, offset int) error {
|
func (s *linuxSystemTray) positionWindow(window *WebviewWindow, offset int) error {
|
||||||
@ -39,49 +37,49 @@ func (s *linuxSystemTray) bounds() (*Rect, error) {
|
|||||||
|
|
||||||
func (s *linuxSystemTray) run() {
|
func (s *linuxSystemTray) run() {
|
||||||
InvokeSync(func() {
|
InvokeSync(func() {
|
||||||
label := s.label
|
|
||||||
if label == "" {
|
|
||||||
label = "Wails"
|
|
||||||
}
|
|
||||||
s.tray = systrayNew(label)
|
|
||||||
|
|
||||||
// if s.nsStatusItem != nil {
|
// if s.nsStatusItem != nil {
|
||||||
// Fatal("System tray '%d' already running", s.id)
|
// Fatal("System tray '%d' already running", s.id)
|
||||||
// }
|
// }
|
||||||
// s.nsStatusItem = unsafe.Pointer(C.systemTrayNew())
|
// s.nsStatusItem = unsafe.Pointer(C.systemTrayNew())
|
||||||
if s.label != "" {
|
if s.label != "" {
|
||||||
systraySetTitle(s.tray, s.label)
|
// C.systemTraySetLabel(s.nsStatusItem, C.CString(s.label))
|
||||||
}
|
}
|
||||||
if s.icon != nil {
|
if s.icon != nil {
|
||||||
s.setIcon(s.icon)
|
// s.nsImage = unsafe.Pointer(C.imageFromBytes((*C.uchar)(&s.icon[0]), C.int(len(s.icon))))
|
||||||
|
// C.systemTraySetIcon(s.nsStatusItem, s.nsImage, C.int(s.iconPosition), C.bool(s.isTemplateIcon))
|
||||||
}
|
}
|
||||||
if s.menu != nil {
|
if s.menu != nil {
|
||||||
// s.menu.Update()
|
s.menu.Update()
|
||||||
s.setMenu(s.menu)
|
// Convert impl to macosMenu object
|
||||||
|
// s.nsMenu = (s.menu.impl).(*macosMenu).nsMenu
|
||||||
|
// C.systemTraySetMenu(s.nsStatusItem, s.nsMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) setIcon(icon []byte) {
|
func (s *linuxSystemTray) setIcon(icon []byte) {
|
||||||
s.icon = icon
|
s.icon = icon
|
||||||
InvokeSync(func() {
|
InvokeSync(func() {
|
||||||
systraySetTemplateIcon(s.tray, icon)
|
// s.nsImage = unsafe.Pointer(C.imageFromBytes((*C.uchar)(&icon[0]), C.int(len(icon))))
|
||||||
|
// C.systemTraySetIcon(s.nsStatusItem, s.nsImage, C.int(s.iconPosition), C.bool(s.isTemplateIcon))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) setDarkModeIcon(icon []byte) {
|
func (s *linuxSystemTray) setDarkModeIcon(icon []byte) {
|
||||||
s.icon = icon
|
s.icon = icon
|
||||||
InvokeSync(func() {
|
InvokeSync(func() {
|
||||||
systraySetTemplateIcon(s.tray, icon)
|
// s.nsImage = unsafe.Pointer(C.imageFromBytes((*C.uchar)(&icon[0]), C.int(len(icon))))
|
||||||
|
// C.systemTraySetIcon(s.nsStatusItem, s.nsImage, C.int(s.iconPosition), C.bool(s.isTemplateIcon))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) setTemplateIcon(icon []byte) {
|
func (s *linuxSystemTray) setTemplateIcon(icon []byte) {
|
||||||
s.icon = icon
|
s.icon = icon
|
||||||
s.isTemplateIcon = true
|
s.isTemplateIcon = true
|
||||||
|
|
||||||
globalApplication.dispatchOnMainThread(func() {
|
globalApplication.dispatchOnMainThread(func() {
|
||||||
systraySetTemplateIcon(s.tray, icon)
|
// s.nsImage = unsafe.Pointer(C.imageFromBytes((*C.uchar)(&icon[0]), C.int(len(icon))))
|
||||||
|
// C.systemTraySetIcon(s.nsStatusItem, s.nsImage, C.int(s.iconPosition), C.bool(s.isTemplateIcon))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,17 +93,16 @@ func newSystemTrayImpl(s *SystemTray) systemTrayImpl {
|
|||||||
isTemplateIcon: s.isTemplateIcon,
|
isTemplateIcon: s.isTemplateIcon,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) openMenu() {
|
func (s *linuxSystemTray) openMenu() {
|
||||||
if s.tray == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) setLabel(label string) {
|
func (s *linuxSystemTray) setLabel(label string) {
|
||||||
s.label = label
|
s.label = label
|
||||||
systraySetLabel(s.tray, label)
|
// C.systemTraySetLabel(s.nsStatusItem, C.CString(label))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxSystemTray) destroy() {
|
func (s *linuxSystemTray) destroy() {
|
||||||
systrayDestroy(s.tray)
|
// Remove the status item from the status bar and its associated menu
|
||||||
|
// C.systemTrayDestroy(s.nsStatusItem)
|
||||||
}
|
}
|
||||||
|
@ -353,8 +353,9 @@ func (w *linuxWebviewWindow) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app := getNativeApplication()
|
app := getNativeApplication()
|
||||||
nativeMenu := app.getApplicationMenu()
|
|
||||||
w.window, w.webview, w.vbox = windowNew(app.application, nativeMenu, w.parent.id, 1)
|
menu := app.getApplicationMenu()
|
||||||
|
w.window, w.webview, w.vbox = windowNew(app.application, menu, w.parent.id, 1)
|
||||||
app.registerWindow(w.window, w.parent.id) // record our mapping
|
app.registerWindow(w.window, w.parent.id) // record our mapping
|
||||||
w.connectSignals()
|
w.connectSignals()
|
||||||
if w.parent.options.EnableDragAndDrop {
|
if w.parent.options.EnableDragAndDrop {
|
||||||
|
Loading…
Reference in New Issue
Block a user