desktop open: a hidden tray copy that is already running counts once its window is visible (Windows), graceful stop wait 3 s on Windows

This commit is contained in:
CRTkafa 2026-10-23 22:42:12 +08:00
parent d4cf1ad3a1
commit 8df41a26b0
5 changed files with 58 additions and 17 deletions

View file

@ -1,5 +1,5 @@
import { describe, expect, test } from 'bun:test';
import { appExe, listCommand, logDir, matchByPath, mismatchMessage, notOpenedMessage, parseProcs, peVersion, startedHidden, stopCommand, versionMatches } from '../cli/lib/desktop-proc';
import { appExe, graceMs, openState, listCommand, logDir, matchByPath, mismatchMessage, notOpenedMessage, parseProcs, peVersion, startedHidden, stopCommand, versionMatches } from '../cli/lib/desktop-proc';
/** A tiny fake PE: "MZ", padding, then a VS_FIXEDFILEINFO with the given product version. */
function fakePe(a: number, b: number, c: number, d = 0, at = 128): Uint8Array {
@ -82,3 +82,25 @@ describe('desktop open: the log the message points to', () => {
expect(notOpenedMessage('hidden', 'x.exe', 'L')).toContain('hidden (tray)');
});
});
describe('desktop open: a hidden tray copy that is already running', () => {
const exe = "D:/app/storebound-desktop.exe";
const hidden = { pid: 1, exe, args: `"${exe}" --hidden` };
test('Windows: the visible window decides, read from the CIM/Get-Process JSON', () => {
const rows = parseProcs('win32', JSON.stringify([{ ProcessId: 1, ExecutablePath: exe, CommandLine: `"${exe}" --hidden`, Window: false }, { ProcessId: 2, ExecutablePath: exe, CommandLine: `"${exe}"`, Window: true }]));
expect(rows.map(r => r.window)).toEqual([false, true]);
expect(openState('win32', [rows[0]!], true)).toBe('hidden');
expect(openState('win32', rows, false)).toBe('ok');
expect(openState('win32', [], true)).toBe('none');
expect(listCommand('win32').join(' ')).toContain('MainWindowHandle');
});
test('elsewhere: a visible start, or a hidden copy the new start handed over to', () => {
expect(openState('linux', [hidden], false)).toBe('hidden');
expect(openState('linux', [hidden], true)).toBe('ok');
expect(openState('darwin', [{ pid: 3, exe: '', args: '/x/storebound-desktop' }], false)).toBe('ok');
expect(openState('darwin', [], true)).toBe('none');
});
test('a tray app only hides on close: short graceful wait on Windows', () => {
expect(graceMs('win32')).toBeLessThan(graceMs('linux'));
});
});