File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,29 +6,31 @@ import 'package:win32/win32.dart';
66class WindowUtils {
77 static final String _propName = "PureLive_InstanceID" ;
88
9- /// Corrected NativeCallable for WNDENUMPROC
109 static bool _findAndWake (int targetId) {
1110 bool found = false ;
12-
13- // The function signature MUST be (int, int) -> int for WNDENUMPROC
1411 final callback = NativeCallable <WNDENUMPROC >.isolateLocal ((int hwnd, int lParam) {
1512 final propPtr = _propName.toNativeUtf16 ();
1613 final val = GetProp (hwnd, propPtr);
1714 free (propPtr);
18-
19- if (val == targetId && val != 0 ) {
20- if (IsWindowVisible (hwnd) != 0 ) {
15+ if (val == targetId) {
16+ // 1. 先检查是否最小化
17+ if (IsIconic (hwnd) != 0 ) {
2118 ShowWindow (hwnd, SW_RESTORE );
22- SetForegroundWindow (hwnd);
23- found = true ;
24- return 0 ;
2519 }
20+ ShowWindow (hwnd, SW_SHOW );
21+ SetForegroundWindow (hwnd);
22+ found = true ;
23+ return 0 ; // 停止枚举
2624 }
27- return 1 ; // Continue
25+ return 1 ; // 继续
2826 }, exceptionalReturn: 0 );
2927
30- EnumWindows (callback.nativeFunction, 0 );
31- callback.close ();
28+ try {
29+ EnumWindows (callback.nativeFunction, 0 );
30+ } finally {
31+ callback.close ();
32+ }
33+
3234 return found;
3335 }
3436
You can’t perform that action at this time.
0 commit comments