@takboo/dsh-coopanion 0.4.16 → 0.4.17
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/README.md +2 -2
- package/desktop/always-on-top.cjs +32 -0
- package/desktop/main.cjs +4 -3
- package/dist/build-info.json +2 -2
- package/docs/desktop-recovery-contract.md +2 -0
- package/docs/development.md +3 -0
- package/docs/release-notes.md +12 -0
- package/docs/usage.md +5 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/tests/always-on-top.test.js +67 -0
- package/tests/windows-topmost-native.mjs +112 -0
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
打开侧边栏 **插件 → 添加插件**,在「包名或地址」中填入:
|
|
59
59
|
|
|
60
60
|
```text
|
|
61
|
-
@takboo/dsh-coopanion@0.4.
|
|
61
|
+
@takboo/dsh-coopanion@0.4.17
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
点击安装,完成后启用 `dsh-coopanion`,再完全退出并重新打开 Harness。
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
使用 **Desktop 自带的 `dsh` 命令**。先启动 Desktop 一次完成初始化,完全退出应用后执行:
|
|
71
71
|
|
|
72
72
|
```bash
|
|
73
|
-
dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.
|
|
73
|
+
dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.17
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
完成后重新打开 Desktop。其他 profile 的安装方法见[使用指南](docs/usage.md#通过-dsh-命令行安装)。
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Windows can lose TOPMOST without a corresponding Electron window event.
|
|
2
|
+
// Check periodically while shown, but only repair a missing flag: repeatedly
|
|
3
|
+
// raising an already-topmost window changes its order among other overlays.
|
|
4
|
+
module.exports.installAlwaysOnTop = (win, { platform = process.platform, isSuspended = () => false } = {}) => {
|
|
5
|
+
win.setAlwaysOnTop(true, platform === 'win32' ? 'screen-saver' : 'floating');
|
|
6
|
+
if (platform !== 'win32') return () => {};
|
|
7
|
+
let disposed = false, timer, pending;
|
|
8
|
+
const pause = () => { clearInterval(timer); timer = undefined; clearImmediate(pending); pending = undefined; };
|
|
9
|
+
const repair = () => {
|
|
10
|
+
if (disposed || win.isDestroyed() || !win.isVisible() || win.isMinimized() || isSuspended()) return;
|
|
11
|
+
if (!win.isAlwaysOnTop()) win.setAlwaysOnTop(true, 'screen-saver');
|
|
12
|
+
};
|
|
13
|
+
const reconcile = () => {
|
|
14
|
+
pending = undefined;
|
|
15
|
+
if (disposed || win.isDestroyed() || !win.isVisible() || win.isMinimized()) { pause(); return; }
|
|
16
|
+
repair();
|
|
17
|
+
timer ??= setInterval(repair, 3000);
|
|
18
|
+
timer.unref?.();
|
|
19
|
+
};
|
|
20
|
+
const schedule = () => { if (!disposed && pending === undefined) pending = setImmediate(reconcile); };
|
|
21
|
+
const events = ['show', 'restore', 'focus', 'blur'];
|
|
22
|
+
const dispose = () => {
|
|
23
|
+
if (disposed) return;
|
|
24
|
+
disposed = true; pause();
|
|
25
|
+
for (const event of events) win.off(event, schedule);
|
|
26
|
+
win.off('hide', pause); win.off('minimize', pause); win.off('closed', dispose);
|
|
27
|
+
};
|
|
28
|
+
for (const event of events) win.on(event, schedule);
|
|
29
|
+
win.on('hide', pause); win.on('minimize', pause); win.once('closed', dispose);
|
|
30
|
+
reconcile();
|
|
31
|
+
return dispose;
|
|
32
|
+
};
|
package/desktop/main.cjs
CHANGED
|
@@ -14,6 +14,7 @@ const { CharacterStore } = require('../dist/character-store.cjs');
|
|
|
14
14
|
const { createPetServer } = require('../dist/figure-server.cjs');
|
|
15
15
|
const { trayState, trayLocale } = require('./tray-state.cjs');
|
|
16
16
|
const { createDisplayController } = require('./display-controller.cjs');
|
|
17
|
+
const { installAlwaysOnTop } = require('./always-on-top.cjs');
|
|
17
18
|
const { petCopy, petLanguage } = require('../web/locale.js');
|
|
18
19
|
app.setName(petCopy('en').defaultName);
|
|
19
20
|
if (process.env.DSH_PET_TEST_DATA_DIR) {
|
|
@@ -34,7 +35,7 @@ if (process.env.DSH_PET_TEST_DEBUG_PORT) {
|
|
|
34
35
|
const displayTest = process.env.DSH_PET_TEST_NO_SANDBOX === '1' && !!process.env.DSH_PET_TEST_DEBUG_PORT;
|
|
35
36
|
const keyboardActivity = require('./keyboard-activity.cjs').createKeyboardActivity();
|
|
36
37
|
const { initialLockState } = require('./lifecycle-state.cjs');
|
|
37
|
-
let win, tray, options, lastFrame, poll, assetServer, characters, companions, displays, diagnostics, diagnosticRead;
|
|
38
|
+
let win, tray, options, lastFrame, poll, assetServer, characters, companions, displays, diagnostics, diagnosticRead, disposeAlwaysOnTop;
|
|
38
39
|
let lifecycle = { locks: 0, unlocks: 0, suspends: 0, resumes: 0 };
|
|
39
40
|
const configureDiagnostics = () => {
|
|
40
41
|
if (options?.diagnostics !== true) {
|
|
@@ -216,7 +217,7 @@ app.whenReady().then(async () => {
|
|
|
216
217
|
return characters.import(new Uint8Array(value));
|
|
217
218
|
});
|
|
218
219
|
win = new BrowserWindow({ ...screen.getPrimaryDisplay().workArea, transparent: true, frame: false, resizable: false, skipTaskbar: true, hasShadow: false, show: false, alwaysOnTop: true, backgroundColor: '#00000000', webPreferences: { additionalArguments: displayTest ? ['--dsh-pet-display-test'] : [], preload: join(__dirname, 'preload.cjs'), sandbox: true, contextIsolation: true, nodeIntegration: false } });
|
|
219
|
-
win
|
|
220
|
+
disposeAlwaysOnTop = installAlwaysOnTop(win, { isSuspended: () => suspended });
|
|
220
221
|
win.on('show', visibility); win.on('hide', visibility);
|
|
221
222
|
win.webContents.on('render-process-gone', () => app.exit(1));
|
|
222
223
|
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
|
|
@@ -280,5 +281,5 @@ app.whenReady().then(async () => {
|
|
|
280
281
|
if (process.connected) process.send(failure, () => app.exit(1)); else app.exit(1);
|
|
281
282
|
});
|
|
282
283
|
|
|
283
|
-
app.on('before-quit', () => { if (userClosed) process.send?.({ type: 'closed' }); clearInterval(poll); keyboardActivity.configure(false); if (diagnosticRead) { clearTimeout(diagnosticRead.timer); diagnosticRead.resolve(null); diagnosticRead = undefined; } diagnostics?.release(); void diagnostics?.close(); assetServer?.close(); tray?.destroy(); });
|
|
284
|
+
app.on('before-quit', () => { if (userClosed) process.send?.({ type: 'closed' }); disposeAlwaysOnTop?.(); clearInterval(poll); keyboardActivity.configure(false); if (diagnosticRead) { clearTimeout(diagnosticRead.timer); diagnosticRead.resolve(null); diagnosticRead = undefined; } diagnostics?.release(); void diagnostics?.close(); assetServer?.close(); tray?.destroy(); });
|
|
284
285
|
app.on('window-all-closed', () => { userClosed = true; app.quit(); });
|
package/dist/build-info.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
|
-
"commit": "
|
|
3
|
+
"commit": "d8b930bddd060c516b8757f7c417e41a66d7be57",
|
|
4
4
|
"dirty": false,
|
|
5
|
-
"productDigest": "
|
|
5
|
+
"productDigest": "a777e132bc1fb41588a60ad7a288d2958b5fc2daa3930920a71980c1de2986d7"
|
|
6
6
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 桌面异常恢复契约
|
|
2
2
|
|
|
3
|
+
Windows 窗口使用 `screen-saver` 置顶层级;macOS/Linux 保留 `floating`。Windows 在显示/还原/焦点变化后复核原生置顶标志,并在可见期间每三秒检查,以覆盖没有 Electron 事件的系统置顶丢失;标志仍有效时不重复提升窗口。隐藏、最小化时取消检查,锁屏/休眠时不修复,不调用显示或焦点接口;关闭窗口和退出应用均解除定时器、排队回调及监听。此恢复只维护可见窗口的置顶资格,不改变用户的显示意图。
|
|
4
|
+
|
|
3
5
|
默认 Electron 路径解析不执行会同步下载的 `electron/index.js`。已有二进制直接复用;缺失时异步运行官方安装器,继承网络/镜像环境,最多准备四分钟,随后仍按 20 秒检查原生 ready。Host 启动总期限为 265 秒,包含准备和窗口启动;自定义测试期限可覆盖。准备阶段保持 `starting`,停止/停用立即取消安装器并等待其退出,不启动迟到的窗口;下载失败直接显示可手动重试的错误,不触发自动恢复风暴。
|
|
4
6
|
|
|
5
7
|
Host 的 `PetControls` 独占恢复调度。意外退出(包括没有主动关闭回执的 exit 0)及明确标记为可恢复的启动失败,最多自动重试三次,依次等待 1、3、10 秒;连续运行 60 秒后清零。休眠或锁屏中不计算稳定时间。时间参数可注入。未知错误、缺少图形环境、无效或不可执行的运行时路径直接进入 error;清理未确认成功也不启动新进程。
|
package/docs/development.md
CHANGED
|
@@ -50,9 +50,12 @@ macOS CI 固定使用 `macos-15` Apple Silicon 标准 runner。浏览器回归
|
|
|
50
50
|
| 拖放与小窝 | `tests/npc-drag-ui.mjs`:真实指针轨迹、两侧边缘、区域外停留、旧路线取消、按住及释放后小窝锚点 |
|
|
51
51
|
| 自主循环与互动存档 | `tests/npc-life.test.js`、`tests/npc-life-native.mjs`、`tests/companionship-ui.mjs`、`tests/companionship-native.mjs` |
|
|
52
52
|
| 原生冷启动 | `tests/lifecycle-startup-native.mjs`:受控 unknown/locked 与实际系统状态分别检查 |
|
|
53
|
+
| Windows 置顶 | `tests/always-on-top.test.js`、`tests/windows-topmost-native.mjs`:平台策略、寿命清理与真实 Win32 TOPMOST 丢失/恢复 |
|
|
53
54
|
|
|
54
55
|
原生 NPC 用例控制时钟、粗粒度输入和鼠标感知;身体移动及 arrived/interrupted 保持真实。受控循环通过与物理输入、自然体验分别报告。
|
|
55
56
|
|
|
57
|
+
Windows 置顶回归由 CI 的隔离 Windows runner 串行运行 `node tests/windows-topmost-native.mjs`。它启动真实 Electron 窗口,用 Win32 读取 `WS_EX_TOPMOST`,主动清除标志后核对恢复和前台焦点保持,并检查隐藏/显示、最小化/还原与正常退出。失败也保留 `artifacts/windows-topmost-native.json`,绑定实际提交、构建与 Electron 版本。系统置顶丢失为受控注入;它不代替 Windows 11 物理设备、独占全屏游戏或长期桌面体验验收。本地缺少 Windows VM 时可使用此 CI 检查,本地 macOS 原生测试仍使用主项目虚拟机。
|
|
58
|
+
|
|
56
59
|
Windows 的 125% 缩放与任务栏回归可在已登录、解锁的隔离控制台运行 `node tests/windows-geometry-native.mjs`。先通过系统显示设置选择 125%;脚本核对 Electron 读取的真实 DPI,不强制 Chromium 比例。它通过 Windows Shell API 切换任务栏自动隐藏、核对实际工作区及 viewport,再注入过期边界检查重同步与角色保持,结束时恢复原任务栏状态。NPC 时钟和感知为受控输入;这项 VM 检查不代替物理多屏或用户体验验收。RDP 会话不允许更改显示缩放时,先在虚拟机控制台设置并验证实际比例。
|
|
57
60
|
|
|
58
61
|
同一控制台运行 `node tests/windows-pointer-native.mjs` 可核对真实 125% 下的右键菜单及面板点击;在 100% 下用 `DSH_WINDOWS_EXPECT_SCALE=1` 明确对应预期比例。Windows 输入辅助线程先启用 Per-Monitor V2 DPI 感知,再使用 Electron 换算出的物理坐标移动并读回光标,避免 DPI-unaware 辅助进程的坐标虚拟化造成误判。此检查同时使用 OS 光标和 CDP 点击,不代替物理混合 DPI 实机验收。
|
package/docs/release-notes.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# v0.4.17
|
|
2
|
+
|
|
3
|
+
修复 Windows 桌宠失去置顶后不能恢复的问题(#31)。
|
|
4
|
+
|
|
5
|
+
- Windows 单独使用 `screen-saver` 层级;显示期间定期检查丢失的置顶标志,并在窗口事件后复核。仍有效时不重复提升,不抢当前应用焦点;隐藏、最小化、锁屏或休眠时不修复,窗口关闭与应用退出时清理回调和监听。
|
|
6
|
+
- macOS/Linux 保留 `floating` 层级及既有行为。
|
|
7
|
+
- 新增真实 Windows Win32 样式位与焦点回归,以及平台策略和寿命清理测试。Windows CI 的受控置顶丢失验证与物理设备/独占全屏体验分别记录。
|
|
8
|
+
|
|
9
|
+
问题定位与修复方向参考 @zhuhuaikuan 提供的 #31/#33 数据。
|
|
10
|
+
|
|
11
|
+
安装包:`dsh-coopanion-0.4.17.tgz`;npm 与 GitHub Release 使用同一份发布 CI 验证的压缩包。
|
|
12
|
+
|
|
1
13
|
# v0.4.16
|
|
2
14
|
|
|
3
15
|
## DSH 0.2.1-rc.5 兼容与自动检查
|
package/docs/usage.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
### 在 Harness 中从 npm 安装
|
|
12
12
|
|
|
13
|
-
打开侧边栏 **插件 → 添加插件**,在「包名或地址」输入 **`@takboo/dsh-coopanion@0.4.
|
|
13
|
+
打开侧边栏 **插件 → 添加插件**,在「包名或地址」输入 **`@takboo/dsh-coopanion@0.4.17`**,点击安装,再启用 `dsh-coopanion`。显式版本可以避免发布首日的裸包名解析回退,原因见下方。安装方式见 [Harness 官方插件管理说明](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/client/ui-plugin-manager/README.zh.md#安装一个组合包)。
|
|
14
14
|
|
|
15
15
|
### 安装版本与发布时间保护
|
|
16
16
|
|
|
@@ -23,7 +23,7 @@ pnpm 11 的 `minimumReleaseAge` 默认为 1440 分钟(24 小时)。详情页
|
|
|
23
23
|
**Desktop:** 使用 Desktop 自带的 `dsh` 命令。先启动 Desktop 一次初始化 profile,完全退出应用,再执行:
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.
|
|
26
|
+
dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.17
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
npm 安装的 dsh 不能管理 Desktop 所拥有的 profile;若系统找不到 Desktop 的命令,先在 Desktop 的菜单栏中使用 **Manage dsh command/管理 dsh 命令** 安装命令入口。
|
|
@@ -31,7 +31,7 @@ npm 安装的 dsh 不能管理 Desktop 所拥有的 profile;若系统找不到
|
|
|
31
31
|
**本机 Web profile:** 使用 npm 安装的 dsh 时,向实际使用的 profile 安装。例如默认 `web` profile:
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
dsh plugin --profile web add @takboo/dsh-coopanion@0.4.
|
|
34
|
+
dsh plugin --profile web add @takboo/dsh-coopanion@0.4.17
|
|
35
35
|
dsh --profile web
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -51,6 +51,8 @@ dsh plugin --profile desktop add /absolute/path/dsh-coopanion.tgz
|
|
|
51
51
|
|
|
52
52
|
完全退出并重新打开 Harness。首次启动会下载并校验 Electron 44 运行时;在 **Settings → 桌宠** 查看运行状态,打开一段会话后双击角色即可聊天。
|
|
53
53
|
|
|
54
|
+
Windows 桌宠显示期间会在失去置顶后自动恢复,恢复时不抢当前应用焦点;隐藏或最小化后不会因此重新显示。macOS/Linux 的窗口层级保持原有行为。
|
|
55
|
+
|
|
54
56
|
### Electron 运行时准备
|
|
55
57
|
|
|
56
58
|
首次安装或升级 Electron 后,桌宠在独立子进程中下载、校验并解压运行时;准备期间设置页显示“正在启动”,Harness 的窗口、服务和其他插件继续响应,也可随时关闭桌宠来取消准备。准备最多等待四分钟,失败后设置页显示错误;检查网络后点击启动重试。运行时准备完成后才开始原生窗口的 20 秒启动检查。
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takboo/dsh-coopanion",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.17",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@takboo/dsh-coopanion",
|
|
9
|
-
"version": "0.4.
|
|
9
|
+
"version": "0.4.17",
|
|
10
10
|
"license": "AGPL-3.0-or-later",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"dompurify": "3.4.17",
|
package/package.json
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
const { installAlwaysOnTop } = createRequire(import.meta.url)('../desktop/always-on-top.cjs');
|
|
5
|
+
function window() {
|
|
6
|
+
const win = new EventEmitter();
|
|
7
|
+
Object.assign(win, { visible: true, minimized: false, destroyed: false, topmost: false,
|
|
8
|
+
isDestroyed: () => win.destroyed,
|
|
9
|
+
isVisible: () => { if (win.destroyed) throw Error('destroyed'); return win.visible; },
|
|
10
|
+
isMinimized: () => { if (win.destroyed) throw Error('destroyed'); return win.minimized; },
|
|
11
|
+
isAlwaysOnTop: () => { if (win.destroyed) throw Error('destroyed'); return win.topmost; },
|
|
12
|
+
setAlwaysOnTop: vi.fn(() => { if (win.destroyed) throw Error('destroyed'); win.topmost = true; }),
|
|
13
|
+
focus: vi.fn(), show: vi.fn(), showInactive: vi.fn(),
|
|
14
|
+
});
|
|
15
|
+
return win;
|
|
16
|
+
}
|
|
17
|
+
beforeEach(() => vi.useFakeTimers());
|
|
18
|
+
afterEach(() => { vi.clearAllTimers(); vi.useRealTimers(); });
|
|
19
|
+
it.each(['darwin', 'linux'])('%s retains floating and installs no Windows recovery', platform => {
|
|
20
|
+
const win = window(), dispose = installAlwaysOnTop(win, { platform });
|
|
21
|
+
expect(win.setAlwaysOnTop.mock.calls).toEqual([[true, 'floating']]);
|
|
22
|
+
expect(win.eventNames()).toEqual([]); expect(vi.getTimerCount()).toBe(0);
|
|
23
|
+
dispose();
|
|
24
|
+
});
|
|
25
|
+
it('repairs actual Windows flag loss while leaving an intact topmost window and focus alone', () => {
|
|
26
|
+
const win = window(), dispose = installAlwaysOnTop(win, { platform: 'win32' });
|
|
27
|
+
expect(win.setAlwaysOnTop.mock.calls).toEqual([[true, 'screen-saver']]);
|
|
28
|
+
vi.advanceTimersByTime(6000); expect(win.setAlwaysOnTop).toHaveBeenCalledTimes(1);
|
|
29
|
+
win.topmost = false; vi.advanceTimersByTime(3000);
|
|
30
|
+
expect(win.topmost).toBe(true); expect(win.setAlwaysOnTop).toHaveBeenCalledTimes(2);
|
|
31
|
+
expect(win.focus).not.toHaveBeenCalled(); expect(win.show).not.toHaveBeenCalled(); expect(win.showInactive).not.toHaveBeenCalled();
|
|
32
|
+
dispose(); expect(vi.getTimerCount()).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
it('does not revive a hidden window through queued events or polling, and repairs on show', () => {
|
|
35
|
+
const win = window(), dispose = installAlwaysOnTop(win, { platform: 'win32' });
|
|
36
|
+
win.topmost = false; win.emit('blur'); win.emit('focus');
|
|
37
|
+
win.visible = false; win.emit('hide'); vi.advanceTimersByTime(6000);
|
|
38
|
+
expect(win.topmost).toBe(false); expect(vi.getTimerCount()).toBe(0);
|
|
39
|
+
win.visible = true; win.emit('show'); vi.advanceTimersByTime(1);
|
|
40
|
+
expect(win.topmost).toBe(true); expect(vi.getTimerCount()).toBe(1);
|
|
41
|
+
dispose();
|
|
42
|
+
});
|
|
43
|
+
it('skips suspended state and resumes repair without replaying window activation', () => {
|
|
44
|
+
const win = window(); let suspended = false;
|
|
45
|
+
const dispose = installAlwaysOnTop(win, { platform: 'win32', isSuspended: () => suspended });
|
|
46
|
+
win.topmost = false; suspended = true; win.emit('blur'); vi.advanceTimersByTime(6000);
|
|
47
|
+
expect(win.topmost).toBe(false);
|
|
48
|
+
suspended = false; vi.advanceTimersByTime(3000); expect(win.topmost).toBe(true);
|
|
49
|
+
expect(win.focus).not.toHaveBeenCalled(); dispose();
|
|
50
|
+
});
|
|
51
|
+
it('pauses minimized windows and repairs after restore', () => {
|
|
52
|
+
const win = window(), dispose = installAlwaysOnTop(win, { platform: 'win32' });
|
|
53
|
+
win.topmost = false; win.minimized = true; win.emit('minimize'); vi.advanceTimersByTime(6000);
|
|
54
|
+
expect(win.topmost).toBe(false); expect(vi.getTimerCount()).toBe(0);
|
|
55
|
+
win.minimized = false; win.emit('restore'); vi.advanceTimersByTime(1);
|
|
56
|
+
expect(win.topmost).toBe(true); dispose();
|
|
57
|
+
});
|
|
58
|
+
it('cancels queued work and subscriptions on destruction or explicit app shutdown', () => {
|
|
59
|
+
for (const destroy of [true, false]) {
|
|
60
|
+
const win = window(), dispose = installAlwaysOnTop(win, { platform: 'win32' });
|
|
61
|
+
win.topmost = false; win.emit('focus');
|
|
62
|
+
if (destroy) { win.destroyed = true; win.emit('closed'); } else dispose();
|
|
63
|
+
dispose(); win.emit('show'); win.emit('restore'); vi.advanceTimersByTime(6000);
|
|
64
|
+
expect(win.setAlwaysOnTop).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(win.eventNames()).toEqual([]); expect(vi.getTimerCount()).toBe(0);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { mkdtemp, readFile, mkdir, rm, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join, resolve } from 'node:path';
|
|
8
|
+
import { _electron } from 'playwright-core';
|
|
9
|
+
|
|
10
|
+
assert.equal(process.platform, 'win32', 'Run on an isolated Windows interactive desktop');
|
|
11
|
+
const require = createRequire(import.meta.url), run = promisify(execFile);
|
|
12
|
+
const root = await mkdtemp(join(tmpdir(), 'dsh-windows-topmost-'));
|
|
13
|
+
const report = { commit: execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim(), build: JSON.parse(await readFile('dist/build-info.json', 'utf8')), platform: process.platform, samples: [], physicalFullscreenAcceptance: false };
|
|
14
|
+
let app, handle;
|
|
15
|
+
const pause = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
16
|
+
const until = async (check, message) => {
|
|
17
|
+
const deadline = Date.now() + 6000;
|
|
18
|
+
do { if (await check()) return; await pause(50); } while (Date.now() < deadline);
|
|
19
|
+
assert.fail(message);
|
|
20
|
+
};
|
|
21
|
+
async function native(stage, clear = false) {
|
|
22
|
+
assert.match(handle, /^\d+$/);
|
|
23
|
+
const script = `
|
|
24
|
+
Add-Type -TypeDefinition @'
|
|
25
|
+
using System;
|
|
26
|
+
using System.Runtime.InteropServices;
|
|
27
|
+
public static class TopmostProbe {
|
|
28
|
+
[DllImport("user32.dll", EntryPoint="GetWindowLongPtrW")] public static extern IntPtr GetWindowLongPtr(IntPtr hwnd, int index);
|
|
29
|
+
[DllImport("user32.dll", SetLastError=true)] public static extern bool SetWindowPos(IntPtr hwnd, IntPtr after, int x, int y, int cx, int cy, uint flags);
|
|
30
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
31
|
+
}
|
|
32
|
+
'@
|
|
33
|
+
$hwnd = [IntPtr][long]${handle}
|
|
34
|
+
${clear ? 'if (![TopmostProbe]::SetWindowPos($hwnd, [IntPtr](-2), 0, 0, 0, 0, 0x213)) { throw "SetWindowPos failed" }' : ''}
|
|
35
|
+
$style = [TopmostProbe]::GetWindowLongPtr($hwnd, -20).ToInt64()
|
|
36
|
+
@{ exstyle=$style; topmost=(($style -band 8) -ne 0); foreground=[TopmostProbe]::GetForegroundWindow().ToInt64().ToString() } | ConvertTo-Json -Compress
|
|
37
|
+
`;
|
|
38
|
+
const { stdout } = await run('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')], { windowsHide: true });
|
|
39
|
+
const sample = { stage, ...JSON.parse(stdout.replace(/^\uFEFF/, '')) };
|
|
40
|
+
report.samples.push(sample); return sample;
|
|
41
|
+
}
|
|
42
|
+
const petState = () => app.evaluate(({ BrowserWindow }) => {
|
|
43
|
+
const win = BrowserWindow.getAllWindows().find(w => w.webContents.getURL().startsWith('http://127.0.0.1:'));
|
|
44
|
+
return { topmost: win.isAlwaysOnTop(), visible: win.isVisible(), minimized: win.isMinimized() };
|
|
45
|
+
});
|
|
46
|
+
const pet = expression => app.evaluate(({ BrowserWindow }, expression) => {
|
|
47
|
+
const win = BrowserWindow.getAllWindows().find(w => w.webContents.getURL().startsWith('http://127.0.0.1:'));
|
|
48
|
+
if (expression === 'hide') win.hide();
|
|
49
|
+
if (expression === 'show') win.showInactive();
|
|
50
|
+
if (expression === 'minimize') win.minimize();
|
|
51
|
+
if (expression === 'restore') win.restore();
|
|
52
|
+
}, expression);
|
|
53
|
+
try {
|
|
54
|
+
app = await _electron.launch({ executablePath: require('electron'), args: ['--no-sandbox', resolve('desktop/main.cjs')], env: { ...process.env, DSH_PET_TEST_DATA_DIR: root, DSH_PET_TEST_NO_SANDBOX: '1', DSH_PET_TEST_DEBUG_PORT: '0' } });
|
|
55
|
+
const page = await app.firstWindow();
|
|
56
|
+
await page.waitForURL(/^http:\/\/127\.0\.0\.1:/, { waitUntil: 'load' });
|
|
57
|
+
await app.evaluate(() => process.emit('message', { type: 'init', baseline: true, options: { size: 150, roam: false, notifications: false }, snapshot: { mood: 'idle', active: false, sessions: [], results: [] } }));
|
|
58
|
+
await until(async () => (await petState()).visible, 'pet must become visible');
|
|
59
|
+
handle = await app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows()[0].getNativeWindowHandle().readBigUInt64LE().toString());
|
|
60
|
+
report.electron = await app.evaluate(() => process.versions.electron);
|
|
61
|
+
report.systemIdleState = await app.evaluate(({ powerMonitor }) => powerMonitor.getSystemIdleState(1));
|
|
62
|
+
assert.equal((await native('initial')).topmost, true, 'visible pet must carry WS_EX_TOPMOST');
|
|
63
|
+
assert.equal((await petState()).topmost, true);
|
|
64
|
+
|
|
65
|
+
// A real competing window owns foreground focus. Controlled Win32 loss of
|
|
66
|
+
// TOPMOST must be repaired without promoting the pet to foreground focus.
|
|
67
|
+
await app.evaluate(async ({ BrowserWindow }) => {
|
|
68
|
+
const other = new BrowserWindow({ width: 320, height: 200, show: false, webPreferences: { sandbox: true } });
|
|
69
|
+
await other.loadURL('data:text/html,<title>Topmost regression foreground</title>');
|
|
70
|
+
other.show(); other.focus();
|
|
71
|
+
});
|
|
72
|
+
const cleared = await native('cleared-visible', true);
|
|
73
|
+
assert.equal(cleared.topmost, false, 'probe must actually remove WS_EX_TOPMOST');
|
|
74
|
+
assert.notEqual(cleared.foreground, handle, 'another window must own foreground focus');
|
|
75
|
+
const started = Date.now();
|
|
76
|
+
await until(async () => (await petState()).topmost, 'visible pet must recover lost TOPMOST within two 3-second polls');
|
|
77
|
+
report.recoveryMs = Date.now() - started;
|
|
78
|
+
const repaired = await native('repaired-visible');
|
|
79
|
+
assert.equal(repaired.topmost, true);
|
|
80
|
+
assert.equal(repaired.foreground, cleared.foreground, 'repair must not steal foreground focus');
|
|
81
|
+
|
|
82
|
+
await pet('hide');
|
|
83
|
+
await until(async () => !(await petState()).visible, 'pet must hide');
|
|
84
|
+
assert.equal((await native('cleared-hidden', true)).topmost, false);
|
|
85
|
+
await pause(3500);
|
|
86
|
+
assert.equal((await native('still-hidden')).topmost, false, 'hidden pet must not reassert TOPMOST');
|
|
87
|
+
assert.equal((await petState()).visible, false);
|
|
88
|
+
await pet('show');
|
|
89
|
+
await until(async () => (await petState()).topmost && (await petState()).visible, 'show must restore TOPMOST');
|
|
90
|
+
assert.equal((await native('shown')).topmost, true);
|
|
91
|
+
|
|
92
|
+
await pet('minimize');
|
|
93
|
+
await until(async () => (await petState()).minimized, 'pet must minimize');
|
|
94
|
+
await native('cleared-minimized', true);
|
|
95
|
+
await pet('restore');
|
|
96
|
+
await until(async () => !(await petState()).minimized && (await petState()).topmost, 'restore must restore TOPMOST');
|
|
97
|
+
assert.equal((await native('restored')).topmost, true);
|
|
98
|
+
const closing = Date.now();
|
|
99
|
+
let exitTimer;
|
|
100
|
+
try { await Promise.race([app.close(), new Promise((_, reject) => { exitTimer = setTimeout(() => reject(new Error('native app must exit within 10 seconds')), 10000); })]); }
|
|
101
|
+
finally { clearTimeout(exitTimer); }
|
|
102
|
+
report.exitMs = Date.now() - closing; app = undefined;
|
|
103
|
+
report.status = 'passed';
|
|
104
|
+
console.log('Windows TOPMOST passed: Win32 style, controlled loss/recovery, unchanged foreground, hide/show, minimize/restore and normal exit.');
|
|
105
|
+
} catch (error) { report.status = 'failed'; report.error = String(error.stack ?? error); throw error; }
|
|
106
|
+
finally {
|
|
107
|
+
try { await app?.close(); } finally {
|
|
108
|
+
await mkdir('artifacts', { recursive: true });
|
|
109
|
+
await writeFile('artifacts/windows-topmost-native.json', JSON.stringify(report, null, 2) + '\n');
|
|
110
|
+
await rm(root, { recursive: true, force: true });
|
|
111
|
+
}
|
|
112
|
+
}
|