fix: 移除showAndActivate避免误显示SystrayMonitor窗口
回退绕过GLFW遍历所有NSWindow的失败方案,恢复使用activateApp()+ showDockIcon()+window.Show()。保留真正生效的修复:正确selector applicationShouldHandleReopen:hasVisibleWindows: + SetOnStarted延迟注册
This commit is contained in:
@@ -11,7 +11,7 @@ GO = go
|
|||||||
CGO_ENABLED = 1
|
CGO_ENABLED = 1
|
||||||
WINDRES ?= x86_64-w64-mingw32-windres
|
WINDRES ?= x86_64-w64-mingw32-windres
|
||||||
MINGW_CC ?= x86_64-w64-mingw32-gcc
|
MINGW_CC ?= x86_64-w64-mingw32-gcc
|
||||||
SEMVER ?= 0.4.6
|
SEMVER ?= 0.4.7
|
||||||
GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
VERSION = $(SEMVER)-$(GIT_HASH)
|
VERSION = $(SEMVER)-$(GIT_HASH)
|
||||||
LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION)
|
LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION)
|
||||||
|
|||||||
+4
-2
@@ -122,7 +122,8 @@ func Run() {
|
|||||||
for range focusCh {
|
for range focusCh {
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
a.windowHidden = false
|
a.windowHidden = false
|
||||||
showAndActivate()
|
activateApp()
|
||||||
|
showDockIcon()
|
||||||
a.window.Show()
|
a.window.Show()
|
||||||
a.window.RequestFocus()
|
a.window.RequestFocus()
|
||||||
})
|
})
|
||||||
@@ -140,7 +141,8 @@ func Run() {
|
|||||||
onAppActive = func() {
|
onAppActive = func() {
|
||||||
if a.windowHidden {
|
if a.windowHidden {
|
||||||
a.windowHidden = false
|
a.windowHidden = false
|
||||||
showAndActivate()
|
activateApp()
|
||||||
|
showDockIcon()
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
if a.windowHidden {
|
if a.windowHidden {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -37,29 +37,6 @@ static void cmActivateApp(void) {
|
|||||||
((void (*)(id, SEL, BOOL))objc_msgSend)(app, sel_getUid("activateIgnoringOtherApps:"), YES);
|
((void (*)(id, SEL, BOOL))objc_msgSend)(app, sel_getUid("activateIgnoringOtherApps:"), YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmShowAndActivate switches to regular activation policy (dock icon
|
|
||||||
// visible), activates the app, and makes every NSWindow key+front.
|
|
||||||
// This bypasses GLFW's glfwShowWindow (which uses orderFront:nil and
|
|
||||||
// is unreliable during NSApplication activation-policy transitions).
|
|
||||||
static void cmShowAndActivate(void) {
|
|
||||||
Class cls = objc_getClass("NSApplication");
|
|
||||||
id app = ((id (*)(Class, SEL))objc_msgSend)(cls, sel_getUid("sharedApplication"));
|
|
||||||
// Regular activation policy (dock icon visible).
|
|
||||||
((void (*)(id, SEL, long))objc_msgSend)(app, sel_getUid("setActivationPolicy:"), 0);
|
|
||||||
// Bring app to foreground.
|
|
||||||
((void (*)(id, SEL, BOOL))objc_msgSend)(app, sel_getUid("activateIgnoringOtherApps:"), YES);
|
|
||||||
// Make every window key and visible. NSArray* windows = [app windows];
|
|
||||||
id windows = ((id (*)(id, SEL))objc_msgSend)(app, sel_getUid("windows"));
|
|
||||||
// NSUInteger count = [windows count];
|
|
||||||
unsigned long count = ((unsigned long (*)(id, SEL))objc_msgSend)(windows, sel_getUid("count"));
|
|
||||||
for (unsigned long i = 0; i < count; i++) {
|
|
||||||
// id w = [windows objectAtIndex:i];
|
|
||||||
id w = ((id (*)(id, SEL, unsigned long))objc_msgSend)(windows, sel_getUid("objectAtIndex:"), i);
|
|
||||||
// [w makeKeyAndOrderFront:nil];
|
|
||||||
((void (*)(id, SEL, id))objc_msgSend)(w, sel_getUid("makeKeyAndOrderFront:"), nil);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// cmRegisterReopenHandler adds applicationShouldHandleReopen:
|
// cmRegisterReopenHandler adds applicationShouldHandleReopen:
|
||||||
// hasVisibleWindows: to the GLFWApplicationDelegate class at runtime
|
// hasVisibleWindows: to the GLFWApplicationDelegate class at runtime
|
||||||
// (class_addMethod). This lets us detect when macOS re-opens the
|
// (class_addMethod). This lets us detect when macOS re-opens the
|
||||||
@@ -81,6 +58,4 @@ func hideDockIcon() { C.setDockIconVisible(0) }
|
|||||||
|
|
||||||
func activateApp() { C.cmActivateApp() }
|
func activateApp() { C.cmActivateApp() }
|
||||||
|
|
||||||
func showAndActivate() { C.cmShowAndActivate() }
|
|
||||||
|
|
||||||
func registerReopenHandler() { C.cmRegisterReopenHandler() }
|
func registerReopenHandler() { C.cmRegisterReopenHandler() }
|
||||||
|
|||||||
@@ -7,6 +7,4 @@ func hideDockIcon() {}
|
|||||||
|
|
||||||
func activateApp() {}
|
func activateApp() {}
|
||||||
|
|
||||||
func showAndActivate() {}
|
|
||||||
|
|
||||||
func registerReopenHandler() {}
|
func registerReopenHandler() {}
|
||||||
|
|||||||
+2
-1
@@ -62,7 +62,8 @@ func (a *App) setupTray() {
|
|||||||
menu := fyne.NewMenu(i18n.T("WindowTitle"),
|
menu := fyne.NewMenu(i18n.T("WindowTitle"),
|
||||||
fyne.NewMenuItem(i18n.T("TrayShowWindow"), func() {
|
fyne.NewMenuItem(i18n.T("TrayShowWindow"), func() {
|
||||||
a.windowHidden = false
|
a.windowHidden = false
|
||||||
showAndActivate()
|
activateApp()
|
||||||
|
showDockIcon()
|
||||||
a.window.Show()
|
a.window.Show()
|
||||||
a.window.RequestFocus()
|
a.window.RequestFocus()
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user