dsh-gufa-code 1.3.197 → 1.3.199
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +1 -1
- package/desktop/float/bin/win-x64/gufa-float-win.exe +0 -0
- package/desktop/float/win/main.cpp +136 -34
- package/host/dev.js +10 -7
- package/host/window-list-script.js +57 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
Binary file
|
|
@@ -94,6 +94,8 @@ constexpr int kControllerWatchdogMs = 12000;
|
|
|
94
94
|
const COLORREF kBackgroundColor = RGB(13, 15, 19);
|
|
95
95
|
|
|
96
96
|
HINSTANCE g_instance = nullptr;
|
|
97
|
+
class FloatApp;
|
|
98
|
+
FloatApp* g_activeFloatApp = nullptr;
|
|
97
99
|
std::wstring g_logPath;
|
|
98
100
|
/* 崩溃兜底:记录被隐藏的 DSH 窗口,异常退出前尽量恢复(全局变量便于崩溃过滤器访问) */
|
|
99
101
|
std::vector<HWND> g_crashRestoreWindows;
|
|
@@ -973,6 +975,8 @@ class FloatApp {
|
|
|
973
975
|
void OnFollowTimer();
|
|
974
976
|
void ApplyFollowFrame();
|
|
975
977
|
void ApplyClickThrough();
|
|
978
|
+
void ForwardMouseToUnderlying(UINT message, const MSLLHOOKSTRUCT* info);
|
|
979
|
+
static LRESULT CALLBACK LowLevelMouseProc(int code, WPARAM wparam, LPARAM lparam);
|
|
976
980
|
void OnHideDshTimer();
|
|
977
981
|
void HideDshWindows();
|
|
978
982
|
void RestoreDshWindows();
|
|
@@ -1044,8 +1048,11 @@ class FloatApp {
|
|
|
1044
1048
|
bool suppressWindowDestroy_ = false;
|
|
1045
1049
|
bool hideDshDone_ = false;
|
|
1046
1050
|
bool clickThrough_ = false;
|
|
1047
|
-
bool clickThroughLayered_ = false;
|
|
1048
1051
|
bool clickThroughHotkey_ = false;
|
|
1052
|
+
HHOOK mouseHook_ = nullptr;
|
|
1053
|
+
bool mouseHookInstalled_ = false;
|
|
1054
|
+
HWND forwardedTarget_ = nullptr;
|
|
1055
|
+
bool forwardedLeftDown_ = false;
|
|
1049
1056
|
};
|
|
1050
1057
|
|
|
1051
1058
|
namespace {
|
|
@@ -1091,6 +1098,7 @@ static void ShowFloatContextMenu(HWND owner, FloatApp* app) {
|
|
|
1091
1098
|
}
|
|
1092
1099
|
|
|
1093
1100
|
FloatApp::~FloatApp() {
|
|
1101
|
+
if (g_activeFloatApp == this) g_activeFloatApp = nullptr;
|
|
1094
1102
|
if (hostProcess_ != nullptr) {
|
|
1095
1103
|
CloseHandle(hostProcess_);
|
|
1096
1104
|
hostProcess_ = nullptr;
|
|
@@ -1362,6 +1370,8 @@ bool FloatApp::CreateMainWindow() {
|
|
|
1362
1370
|
bool FloatApp::CreateHostWindow(const RECT& rect, bool composition) {
|
|
1363
1371
|
hostingMode_ = composition ? HostingMode::Composition : HostingMode::Windowed;
|
|
1364
1372
|
DWORD extendedStyle = WS_EX_TOPMOST | WS_EX_TOOLWINDOW;
|
|
1373
|
+
/* 透明视觉继续用 NORD + DComp(per-pixel alpha 正确);穿透改为鼠标钩子转发,
|
|
1374
|
+
不再用 LAYERED 改变窗口合成路径(否则透明白底/黑底,摸鱼透明度会乱)。 */
|
|
1365
1375
|
if (composition) extendedStyle |= WS_EX_NOREDIRECTIONBITMAP;
|
|
1366
1376
|
const DWORD style = WS_POPUP | WS_THICKFRAME | WS_CLIPCHILDREN;
|
|
1367
1377
|
hwnd_ = CreateWindowExW(extendedStyle, kMainWindowClass, kWindowTitle, style, rect.left,
|
|
@@ -1372,6 +1382,7 @@ bool FloatApp::CreateHostWindow(const RECT& rect, bool composition) {
|
|
|
1372
1382
|
static_cast<unsigned long>(GetLastError()));
|
|
1373
1383
|
return false;
|
|
1374
1384
|
}
|
|
1385
|
+
g_activeFloatApp = this;
|
|
1375
1386
|
LogFmt(L"main-window-created composition=%d rect=(%ld,%ld)-(%ld,%ld) dpi=%u",
|
|
1376
1387
|
composition ? 1 : 0, static_cast<long>(rect.left), static_cast<long>(rect.top),
|
|
1377
1388
|
static_cast<long>(rect.right), static_cast<long>(rect.bottom), WindowDpi(hwnd_));
|
|
@@ -1690,9 +1701,8 @@ bool FloatApp::OnCompositionMouseMessage(UINT message, WPARAM wparam, LPARAM lpa
|
|
|
1690
1701
|
}
|
|
1691
1702
|
|
|
1692
1703
|
LRESULT FloatApp::HandleNcHitTest(HWND hwnd, LPARAM lparam) {
|
|
1693
|
-
/*
|
|
1694
|
-
WS_EX_TRANSPARENT
|
|
1695
|
-
if (clickThrough_) return HTTRANSPARENT;
|
|
1704
|
+
/* 注意:穿透不要在这里返回 HTTRANSPARENT —— 它只在同线程窗口间下传,
|
|
1705
|
+
跨进程会直接吞掉点击;跨进程穿透由 WS_EX_LAYERED|WS_EX_TRANSPARENT 负责。 */
|
|
1696
1706
|
POINT point;
|
|
1697
1707
|
point.x = GET_X_LPARAM(lparam);
|
|
1698
1708
|
point.y = GET_Y_LPARAM(lparam);
|
|
@@ -2532,40 +2542,122 @@ void FloatApp::ToggleClickThrough() {
|
|
|
2532
2542
|
|
|
2533
2543
|
void FloatApp::ApplyClickThrough() {
|
|
2534
2544
|
if (hwnd_ == nullptr) return;
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2545
|
+
/* 保持 NORD+DComp 的 per-pixel 透明,不切 LAYERED。
|
|
2546
|
+
穿透通过 WH_MOUSE_LL 钩子把鼠标消息转发给下层窗口实现(跨进程唯一不破坏透明的方式):
|
|
2547
|
+
- 点击/滚轮:临时隐藏自身 → WindowFromPoint 找下层窗口 → 显示自身 → SendMessage 转发;
|
|
2548
|
+
- 左键按住拖动期间保持隐藏,松开后恢复,drag 直接作用在下层 App。 */
|
|
2549
|
+
if (clickThrough_ && !mouseHookInstalled_) {
|
|
2550
|
+
mouseHook_ = SetWindowsHookExW(WH_MOUSE_LL, LowLevelMouseProc, g_instance, 0);
|
|
2551
|
+
mouseHookInstalled_ = mouseHook_ != nullptr;
|
|
2552
|
+
if (!mouseHookInstalled_) {
|
|
2553
|
+
LogFmt(L"click-through-hook=register-failed err=%lu", static_cast<unsigned long>(GetLastError()));
|
|
2554
|
+
clickThrough_ = false;
|
|
2555
|
+
}
|
|
2556
|
+
} else if (!clickThrough_ && mouseHookInstalled_) {
|
|
2557
|
+
if (mouseHook_ != nullptr) UnhookWindowsHookEx(mouseHook_);
|
|
2558
|
+
mouseHook_ = nullptr;
|
|
2559
|
+
mouseHookInstalled_ = false;
|
|
2560
|
+
forwardedTarget_ = nullptr;
|
|
2561
|
+
forwardedLeftDown_ = false;
|
|
2562
|
+
if (IsWindowVisible(hwnd_) == FALSE) ShowWindow(hwnd_, SW_SHOWNOACTIVATE);
|
|
2563
|
+
}
|
|
2564
|
+
LogFmt(L"click-through=%d mode=%s hook=%d", clickThrough_ ? 1 : 0,
|
|
2565
|
+
hostingMode_ == HostingMode::Composition ? L"composition" : L"windowed",
|
|
2566
|
+
mouseHookInstalled_ ? 1 : 0);
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
void FloatApp::ForwardMouseToUnderlying(UINT message, const MSLLHOOKSTRUCT* info) {
|
|
2570
|
+
if (hwnd_ == nullptr || info == nullptr) return;
|
|
2571
|
+
const POINT screenPoint = info->pt;
|
|
2572
|
+
auto sendToTarget = [&](HWND target, UINT msg, WPARAM wparam, LPARAM lparam) {
|
|
2573
|
+
if (target == nullptr) return;
|
|
2574
|
+
DWORD_PTR result = 0;
|
|
2575
|
+
SendMessageTimeoutW(target, msg, wparam, lparam, SMTO_ABORTIFHUNG, 200, &result);
|
|
2576
|
+
};
|
|
2577
|
+
auto findTarget = [&]() -> HWND {
|
|
2578
|
+
const bool wasVisible = IsWindowVisible(hwnd_) != FALSE;
|
|
2579
|
+
if (wasVisible) ShowWindow(hwnd_, SW_HIDE);
|
|
2580
|
+
HWND target = WindowFromPoint(screenPoint);
|
|
2581
|
+
if (wasVisible) ShowWindow(hwnd_, SW_SHOWNOACTIVATE);
|
|
2582
|
+
if (target == hwnd_ || (target != nullptr && IsChild(hwnd_, target))) return nullptr;
|
|
2583
|
+
return target;
|
|
2584
|
+
};
|
|
2585
|
+
auto clientLParam = [&](HWND target) -> LPARAM {
|
|
2586
|
+
POINT clientPoint = screenPoint;
|
|
2587
|
+
ScreenToClient(target, &clientPoint);
|
|
2588
|
+
return MAKELPARAM(static_cast<short>(clientPoint.x), static_cast<short>(clientPoint.y));
|
|
2589
|
+
};
|
|
2590
|
+
switch (message) {
|
|
2591
|
+
case WM_LBUTTONDOWN:
|
|
2592
|
+
forwardedTarget_ = findTarget();
|
|
2593
|
+
if (forwardedTarget_ == nullptr) return;
|
|
2594
|
+
forwardedLeftDown_ = true;
|
|
2595
|
+
if (IsWindowVisible(hwnd_) != FALSE) ShowWindow(hwnd_, SW_HIDE);
|
|
2596
|
+
sendToTarget(forwardedTarget_, WM_LBUTTONDOWN, MK_LBUTTON, clientLParam(forwardedTarget_));
|
|
2597
|
+
return;
|
|
2598
|
+
case WM_MOUSEMOVE:
|
|
2599
|
+
if (!forwardedLeftDown_ || forwardedTarget_ == nullptr) return;
|
|
2600
|
+
sendToTarget(forwardedTarget_, WM_MOUSEMOVE, MK_LBUTTON, clientLParam(forwardedTarget_));
|
|
2601
|
+
return;
|
|
2602
|
+
case WM_LBUTTONUP:
|
|
2603
|
+
if (!forwardedLeftDown_ || forwardedTarget_ == nullptr) return;
|
|
2604
|
+
sendToTarget(forwardedTarget_, WM_LBUTTONUP, 0, clientLParam(forwardedTarget_));
|
|
2605
|
+
forwardedTarget_ = nullptr;
|
|
2606
|
+
forwardedLeftDown_ = false;
|
|
2607
|
+
if (IsWindowVisible(hwnd_) == FALSE) ShowWindow(hwnd_, SW_SHOWNOACTIVATE);
|
|
2608
|
+
return;
|
|
2609
|
+
case WM_RBUTTONDOWN:
|
|
2610
|
+
case WM_RBUTTONUP:
|
|
2611
|
+
case WM_MBUTTONDOWN:
|
|
2612
|
+
case WM_MBUTTONUP:
|
|
2613
|
+
case WM_MOUSEWHEEL:
|
|
2614
|
+
case WM_MOUSEHWHEEL: {
|
|
2615
|
+
HWND target = findTarget();
|
|
2616
|
+
if (target == nullptr) return;
|
|
2617
|
+
const LPARAM clientPos = clientLParam(target);
|
|
2618
|
+
WPARAM wparam = 0;
|
|
2619
|
+
if (message == WM_MOUSEWHEEL || message == WM_MOUSEHWHEEL) {
|
|
2620
|
+
wparam = static_cast<WPARAM>(static_cast<short>(HIWORD(info->mouseData)));
|
|
2621
|
+
sendToTarget(target, message, wparam, MAKELPARAM(screenPoint.x, screenPoint.y));
|
|
2622
|
+
return;
|
|
2551
2623
|
}
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2624
|
+
if (message == WM_RBUTTONDOWN) wparam = MK_RBUTTON;
|
|
2625
|
+
if (message == WM_MBUTTONDOWN) wparam = MK_MBUTTON;
|
|
2626
|
+
sendToTarget(target, message, wparam, clientPos);
|
|
2627
|
+
return;
|
|
2555
2628
|
}
|
|
2629
|
+
default:
|
|
2630
|
+
return;
|
|
2556
2631
|
}
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
LRESULT CALLBACK FloatApp::LowLevelMouseProc(int code, WPARAM wparam, LPARAM lparam) {
|
|
2635
|
+
if (code < 0) return CallNextHookEx(nullptr, code, wparam, lparam);
|
|
2636
|
+
FloatApp* app = g_activeFloatApp;
|
|
2637
|
+
if (app == nullptr || app->hwnd_ == nullptr || !app->clickThrough_) return CallNextHookEx(nullptr, code, wparam, lparam);
|
|
2638
|
+
const MSLLHOOKSTRUCT* info = reinterpret_cast<const MSLLHOOKSTRUCT*>(lparam);
|
|
2639
|
+
if (info == nullptr) return CallNextHookEx(nullptr, code, wparam, lparam);
|
|
2640
|
+
/* 只拦截落在悬浮层范围内的鼠标 */
|
|
2641
|
+
RECT rect = {};
|
|
2642
|
+
if (!GetWindowRect(app->hwnd_, &rect)) return CallNextHookEx(nullptr, code, wparam, lparam);
|
|
2643
|
+
if (info->pt.x < rect.left || info->pt.x >= rect.right || info->pt.y < rect.top || info->pt.y >= rect.bottom) {
|
|
2644
|
+
return CallNextHookEx(nullptr, code, wparam, lparam);
|
|
2645
|
+
}
|
|
2646
|
+
switch (wparam) {
|
|
2647
|
+
case WM_LBUTTONDOWN:
|
|
2648
|
+
case WM_LBUTTONUP:
|
|
2649
|
+
case WM_MOUSEMOVE:
|
|
2650
|
+
case WM_RBUTTONDOWN:
|
|
2651
|
+
case WM_RBUTTONUP:
|
|
2652
|
+
case WM_MBUTTONDOWN:
|
|
2653
|
+
case WM_MBUTTONUP:
|
|
2654
|
+
case WM_MOUSEWHEEL:
|
|
2655
|
+
case WM_MOUSEHWHEEL:
|
|
2656
|
+
app->ForwardMouseToUnderlying(static_cast<UINT>(wparam), info);
|
|
2657
|
+
return 1;
|
|
2658
|
+
default:
|
|
2659
|
+
return CallNextHookEx(nullptr, code, wparam, lparam);
|
|
2561
2660
|
}
|
|
2562
|
-
int childCount = 0;
|
|
2563
|
-
EnumChildWindows(hwnd_, CountChildWindow, reinterpret_cast<LPARAM>(&childCount));
|
|
2564
|
-
EnumChildWindows(hwnd_, SetChildClickThrough, clickThrough_ ? 1 : 0);
|
|
2565
|
-
LogFmt(L"click-through=%d mode=%s layered=%d styleTransparent=%d children=%d", clickThrough_ ? 1 : 0,
|
|
2566
|
-
hostingMode_ == HostingMode::Composition ? L"composition" : L"windowed",
|
|
2567
|
-
clickThroughLayered_ ? 1 : 0,
|
|
2568
|
-
(GetWindowLongPtrW(hwnd_, GWL_EXSTYLE) & WS_EX_TRANSPARENT) != 0 ? 1 : 0, childCount);
|
|
2569
2661
|
}
|
|
2570
2662
|
|
|
2571
2663
|
void FloatApp::StopFollowing() {
|
|
@@ -2584,6 +2676,11 @@ void FloatApp::DoGracefulExit() {
|
|
|
2584
2676
|
return;
|
|
2585
2677
|
}
|
|
2586
2678
|
Log(L"graceful-exit-start");
|
|
2679
|
+
if (mouseHookInstalled_) {
|
|
2680
|
+
if (mouseHook_ != nullptr) UnhookWindowsHookEx(mouseHook_);
|
|
2681
|
+
mouseHook_ = nullptr;
|
|
2682
|
+
mouseHookInstalled_ = false;
|
|
2683
|
+
}
|
|
2587
2684
|
if (clickThroughHotkey_ && hwnd_ != nullptr) {
|
|
2588
2685
|
UnregisterHotKey(hwnd_, kHotkeyClickThrough);
|
|
2589
2686
|
clickThroughHotkey_ = false;
|
|
@@ -2604,6 +2701,11 @@ void FloatApp::DoGracefulExit() {
|
|
|
2604
2701
|
}
|
|
2605
2702
|
|
|
2606
2703
|
void FloatApp::OnWindowDestroyed() {
|
|
2704
|
+
if (mouseHookInstalled_) {
|
|
2705
|
+
if (mouseHook_ != nullptr) UnhookWindowsHookEx(mouseHook_);
|
|
2706
|
+
mouseHook_ = nullptr;
|
|
2707
|
+
mouseHookInstalled_ = false;
|
|
2708
|
+
}
|
|
2607
2709
|
if (clickThroughHotkey_ && hwnd_ != nullptr) {
|
|
2608
2710
|
UnregisterHotKey(hwnd_, kHotkeyClickThrough);
|
|
2609
2711
|
clickThroughHotkey_ = false;
|
package/host/dev.js
CHANGED
|
@@ -11,6 +11,7 @@ import { dirname, join } from 'node:path'
|
|
|
11
11
|
import { fileURLToPath } from 'node:url'
|
|
12
12
|
import { ApiError } from './context.js'
|
|
13
13
|
import { floatBinaryCandidates, parsePowerShellWindowList, parseTasklistPids, parseWmctrlWindowList } from './float-platform.js'
|
|
14
|
+
import { windowsWindowListScript } from './window-list-script.js'
|
|
14
15
|
|
|
15
16
|
const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
16
17
|
const DEBUG_LOG_PATH = '/tmp/gufa-code-debug.log'
|
|
@@ -71,6 +72,8 @@ export function debugLog(message) {
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
|
|
76
|
+
|
|
74
77
|
export function register(router, env) {
|
|
75
78
|
const startedAt = new Date().toISOString()
|
|
76
79
|
const ctx = env?.ctx ?? router.ctx
|
|
@@ -235,18 +238,18 @@ export function register(router, env) {
|
|
|
235
238
|
})
|
|
236
239
|
})
|
|
237
240
|
|
|
238
|
-
/** Windows:PowerShell 枚举有主窗口的进程。 */
|
|
239
241
|
const listFloatWindowsWin = async () => {
|
|
240
|
-
const script =
|
|
241
|
-
'$rows = @();',
|
|
242
|
-
"Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 -and $_.MainWindowTitle -ne '' } | ForEach-Object { $rows += [pscustomobject]@{ pid = $_.Id; owner = $_.ProcessName; title = $_.MainWindowTitle; bundleId = ''; windowNumber = [int64]$_.MainWindowHandle; frontmost = 0 } };",
|
|
243
|
-
"ConvertTo-Json -InputObject ([pscustomobject]@{ ok = $true; accessibility = $true; apps = @($rows) }) -Compress -Depth 5",
|
|
244
|
-
].join('\n')
|
|
242
|
+
const script = windowsWindowListScript()
|
|
245
243
|
const { stdout } = await runFile('powershell', ['-NoProfile', '-NonInteractive', '-Command', script], { timeout: 20_000, maxBuffer: 8 * 1024 * 1024 })
|
|
246
244
|
const parsed = parsePowerShellWindowList(stdout)
|
|
247
245
|
if (parsed === null) throw new ApiError('list-failed', '读取 Windows 窗口列表失败', 500)
|
|
248
246
|
const helperPids = new Set(await listFloatPids())
|
|
249
|
-
const apps = parsed.apps.filter((row) =>
|
|
247
|
+
const apps = parsed.apps.filter((row) => {
|
|
248
|
+
if (helperPids.has(Number(row.pid))) return false
|
|
249
|
+
const title = String(row.title ?? '')
|
|
250
|
+
if (title.includes('古法编程悬浮层')) return false
|
|
251
|
+
return true
|
|
252
|
+
})
|
|
250
253
|
return { ok: true, accessibility: true, apps }
|
|
251
254
|
}
|
|
252
255
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows 窗口枚举 PowerShell 脚本。
|
|
3
|
+
*
|
|
4
|
+
* 单独成文件是为了让 CI 在没有 npm 依赖的环境里直接 import 做真机验证;
|
|
5
|
+
* Host 侧 host/dev.js 复用同一个脚本。
|
|
6
|
+
*/
|
|
7
|
+
/** Windows 窗口枚举 PowerShell 脚本(同时供 CI 真机测试直接运行)。 */
|
|
8
|
+
export function windowsWindowListScript() {
|
|
9
|
+
const typeDef = [
|
|
10
|
+
'using System;',
|
|
11
|
+
'using System.Text;',
|
|
12
|
+
'using System.Runtime.InteropServices;',
|
|
13
|
+
'public static class GufaWinEnum {',
|
|
14
|
+
' public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);',
|
|
15
|
+
' [DllImport("user32.dll")] public static extern bool EnumWindows(EnumWindowsProc cb, IntPtr lParam);',
|
|
16
|
+
' [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd);',
|
|
17
|
+
' [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int max);',
|
|
18
|
+
' [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int GetWindowTextLength(IntPtr hWnd);',
|
|
19
|
+
' [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint pid);',
|
|
20
|
+
' [DllImport("user32.dll")] public static extern IntPtr GetWindow(IntPtr hWnd, uint cmd);',
|
|
21
|
+
' [DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr hWnd, int index);',
|
|
22
|
+
'}',
|
|
23
|
+
].join('\n')
|
|
24
|
+
const script = [
|
|
25
|
+
'$ErrorActionPreference = "SilentlyContinue";',
|
|
26
|
+
'[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;',
|
|
27
|
+
'$OutputEncoding = [System.Text.Encoding]::UTF8;',
|
|
28
|
+
"Add-Type -TypeDefinition @'",
|
|
29
|
+
typeDef,
|
|
30
|
+
"'@",
|
|
31
|
+
'$procs = @{};',
|
|
32
|
+
'Get-Process | ForEach-Object { $procs[[uint32]$_.Id] = $_.ProcessName }',
|
|
33
|
+
'$rows = New-Object System.Collections.ArrayList;',
|
|
34
|
+
'$cb = [GufaWinEnum+EnumWindowsProc]{ param($hWnd, $lParam)',
|
|
35
|
+
' if (-not [GufaWinEnum]::IsWindowVisible($hWnd)) { return $true };',
|
|
36
|
+
' $len = [GufaWinEnum]::GetWindowTextLength($hWnd);',
|
|
37
|
+
' if ($len -le 0) { return $true };',
|
|
38
|
+
' $sb = New-Object System.Text.StringBuilder ($len + 1);',
|
|
39
|
+
' [void][GufaWinEnum]::GetWindowText($hWnd, $sb, $sb.Capacity);',
|
|
40
|
+
' $title = $sb.ToString();',
|
|
41
|
+
' if ([string]::IsNullOrWhiteSpace($title)) { return $true };',
|
|
42
|
+
' $ex = [GufaWinEnum]::GetWindowLong($hWnd, -20);',
|
|
43
|
+
' if (($ex -band 0x00000080) -ne 0) { return $true };',
|
|
44
|
+
' if ([GufaWinEnum]::GetWindow($hWnd, 4) -ne [IntPtr]::Zero) { return $true };',
|
|
45
|
+
' $ownerPid = [uint32]0;',
|
|
46
|
+
' [void][GufaWinEnum]::GetWindowThreadProcessId($hWnd, [ref]$ownerPid);',
|
|
47
|
+
' $ownerName = $procs[$ownerPid];',
|
|
48
|
+
' if (-not $ownerName) { $ownerName = "" };',
|
|
49
|
+
' [void]$rows.Add([pscustomobject]@{ pid = [int64]$ownerPid; owner = $ownerName; title = $title; bundleId = ""; windowNumber = [int64]$hWnd; frontmost = 0 });',
|
|
50
|
+
' return $true',
|
|
51
|
+
'};',
|
|
52
|
+
'[void][GufaWinEnum]::EnumWindows($cb, [IntPtr]::Zero);',
|
|
53
|
+
'ConvertTo-Json -InputObject ([pscustomobject]@{ ok = $true; accessibility = $true; apps = @($rows) }) -Compress -Depth 5',
|
|
54
|
+
].join('\n')
|
|
55
|
+
return script
|
|
56
|
+
}
|
|
57
|
+
|
package/package.json
CHANGED