fix: 移除showAndActivate避免误显示SystrayMonitor窗口
Release / build-macos (push) Canceled after 0s
Release / build-windows (push) Canceled after 0s
Release / release (push) Canceled after 0s

回退绕过GLFW遍历所有NSWindow的失败方案,恢复使用activateApp()+
showDockIcon()+window.Show()。保留真正生效的修复:正确selector
applicationShouldHandleReopen:hasVisibleWindows: + SetOnStarted延迟注册
This commit is contained in:
2026-07-09 00:49:53 +08:00
parent 96b1a8839c
commit 15af9ef72c
5 changed files with 7 additions and 31 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ GO = go
CGO_ENABLED = 1
WINDRES ?= x86_64-w64-mingw32-windres
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)
VERSION = $(SEMVER)-$(GIT_HASH)
LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION)
+4 -2
View File
@@ -122,7 +122,8 @@ func Run() {
for range focusCh {
fyne.Do(func() {
a.windowHidden = false
showAndActivate()
activateApp()
showDockIcon()
a.window.Show()
a.window.RequestFocus()
})
@@ -140,7 +141,8 @@ func Run() {
onAppActive = func() {
if a.windowHidden {
a.windowHidden = false
showAndActivate()
activateApp()
showDockIcon()
fyne.Do(func() {
if a.windowHidden {
return
-25
View File
@@ -37,29 +37,6 @@ static void cmActivateApp(void) {
((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:
// hasVisibleWindows: to the GLFWApplicationDelegate class at runtime
// (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 showAndActivate() { C.cmShowAndActivate() }
func registerReopenHandler() { C.cmRegisterReopenHandler() }
-2
View File
@@ -7,6 +7,4 @@ func hideDockIcon() {}
func activateApp() {}
func showAndActivate() {}
func registerReopenHandler() {}
+2 -1
View File
@@ -62,7 +62,8 @@ func (a *App) setupTray() {
menu := fyne.NewMenu(i18n.T("WindowTitle"),
fyne.NewMenuItem(i18n.T("TrayShowWindow"), func() {
a.windowHidden = false
showAndActivate()
activateApp()
showDockIcon()
a.window.Show()
a.window.RequestFocus()
}),