@jini-ai/desktop-host 0.7.3-next.1 → 0.7.3-next.3
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/CHANGELOG.md +6 -0
- package/README.md +217 -1
- package/dist/electron/electron-shell.js +5 -7
- package/dist/electron/handoff/index.d.ts +54 -0
- package/dist/electron/handoff/index.js +32 -0
- package/dist/electron/memory-sampler.d.ts +28 -0
- package/dist/electron/memory-sampler.js +41 -0
- package/dist/electron/partitions/cache-maintenance.d.ts +280 -0
- package/dist/electron/partitions/cache-maintenance.js +239 -0
- package/dist/electron/partitions/claim-sources.d.ts +54 -0
- package/dist/electron/partitions/claim-sources.js +36 -0
- package/dist/electron/partitions/holder-registry.d.ts +116 -0
- package/dist/electron/partitions/holder-registry.js +130 -0
- package/dist/electron/partitions/index.d.ts +10 -0
- package/dist/electron/partitions/index.js +10 -0
- package/dist/electron/partitions/maintenance-marker.d.ts +61 -0
- package/dist/electron/partitions/maintenance-marker.js +85 -0
- package/dist/electron/partitions/partition-inventory.d.ts +23 -0
- package/dist/electron/partitions/partition-inventory.js +19 -0
- package/dist/electron/partitions/partition-pass.d.ts +114 -0
- package/dist/electron/partitions/partition-pass.js +414 -0
- package/dist/electron/partitions/partition-root.d.ts +42 -0
- package/dist/electron/partitions/partition-root.js +52 -0
- package/dist/electron/partitions/profile-interlock.d.ts +141 -0
- package/dist/electron/partitions/profile-interlock.js +273 -0
- package/dist/electron/partitions/retirement-ledger.d.ts +116 -0
- package/dist/electron/partitions/retirement-ledger.js +149 -0
- package/dist/electron/preferences/index.d.ts +5 -0
- package/dist/electron/preferences/index.js +5 -0
- package/dist/electron/preferences/ipc.d.ts +35 -0
- package/dist/electron/preferences/ipc.js +21 -0
- package/dist/electron/preferences/menu.d.ts +103 -0
- package/dist/electron/preferences/menu.js +67 -0
- package/dist/electron/preferences/preference-file.d.ts +63 -0
- package/dist/electron/preferences/preference-file.js +51 -0
- package/dist/electron/preferences/values.d.ts +25 -0
- package/dist/electron/preferences/values.js +18 -0
- package/dist/electron/preload/index.d.ts +3 -0
- package/dist/electron/preload/index.js +2 -0
- package/dist/electron/preload/ipc-subscribe.d.ts +34 -0
- package/dist/electron/preload/ipc-subscribe.js +18 -0
- package/dist/electron/selftest/index.d.ts +3 -0
- package/dist/electron/selftest/index.js +3 -0
- package/dist/electron/selftest/selftest-tracker.d.ts +82 -0
- package/dist/electron/selftest/selftest-tracker.js +67 -0
- package/dist/electron/session-bootstrap/exchange.d.ts +50 -0
- package/dist/electron/session-bootstrap/exchange.js +41 -0
- package/dist/electron/session-bootstrap/header-arming.d.ts +18 -0
- package/dist/electron/session-bootstrap/header-arming.js +13 -0
- package/dist/electron/session-bootstrap/index.d.ts +11 -0
- package/dist/electron/session-bootstrap/index.js +10 -0
- package/dist/electron/session-bootstrap/partition.d.ts +17 -0
- package/dist/electron/session-bootstrap/partition.js +24 -0
- package/dist/electron/session-bootstrap/probe.d.ts +40 -0
- package/dist/electron/session-bootstrap/probe.js +29 -0
- package/dist/electron/session-bootstrap/types.d.ts +62 -0
- package/dist/electron/session-bootstrap/types.js +7 -0
- package/dist/electron/updates/desktop-updater.d.ts +90 -0
- package/dist/electron/updates/desktop-updater.js +124 -0
- package/dist/electron/updates/index.d.ts +4 -0
- package/dist/electron/updates/index.js +4 -0
- package/dist/electron/updates/instance-presence-strict.d.ts +27 -0
- package/dist/electron/updates/instance-presence-strict.js +46 -0
- package/dist/electron/updates/native-notices.d.ts +89 -0
- package/dist/electron/updates/native-notices.js +41 -0
- package/dist/electron/updates/update-check-now.d.ts +117 -0
- package/dist/electron/updates/update-check-now.js +88 -0
- package/dist/electron/usability/find-in-page-ipc.d.ts +3 -6
- package/dist/electron/usability/window-bounds-store.js +14 -12
- package/dist/electron/usability/zoom-menu.d.ts +1 -1
- package/dist/electron/webview/index.d.ts +2 -0
- package/dist/electron/webview/index.js +2 -0
- package/dist/electron/webview/webview-types.d.ts +66 -0
- package/dist/electron/webview/webview-types.js +12 -0
- package/dist/electron/windows/app-window.d.ts +83 -0
- package/dist/electron/windows/app-window.js +62 -0
- package/dist/electron/windows/dock-icon.d.ts +34 -0
- package/dist/electron/windows/dock-icon.js +32 -0
- package/dist/electron/windows/index.d.ts +3 -0
- package/dist/electron/windows/index.js +3 -0
- package/dist/logging.js +3 -1
- package/dist/node-toolchain/boot-setup.d.ts +63 -0
- package/dist/node-toolchain/boot-setup.js +59 -0
- package/dist/node-toolchain/index.d.ts +2 -0
- package/dist/node-toolchain/index.js +1 -0
- package/dist/shell/auto-update-controller.d.ts +34 -0
- package/dist/shell/auto-update-controller.js +27 -0
- package/dist/shell/copied-site-databases.d.ts +71 -0
- package/dist/shell/copied-site-databases.js +60 -0
- package/dist/shell/find-in-page-verify.d.ts +33 -0
- package/dist/shell/find-in-page-verify.js +30 -0
- package/dist/shell/find-menu.d.ts +33 -0
- package/dist/shell/find-menu.js +36 -0
- package/dist/shell/guest-navigation.d.ts +47 -0
- package/dist/shell/guest-navigation.js +58 -0
- package/dist/shell/instance-presence.d.ts +20 -0
- package/dist/shell/instance-presence.js +26 -0
- package/dist/shell/js-backslide-guard.d.ts +42 -0
- package/dist/shell/js-backslide-guard.js +44 -0
- package/dist/shell/node-toolchain.d.ts +34 -0
- package/dist/shell/node-toolchain.js +50 -0
- package/dist/shell/pty-helpers.d.ts +25 -0
- package/dist/shell/pty-helpers.js +50 -0
- package/dist/shell/site-presence.d.ts +32 -0
- package/dist/shell/site-presence.js +42 -0
- package/dist/shell/speech/mac-on-device-transcriber.d.ts +24 -0
- package/dist/shell/speech/mac-on-device-transcriber.js +81 -0
- package/dist/shell/speech/speech-ipc.d.ts +52 -0
- package/dist/shell/speech/speech-ipc.js +40 -0
- package/dist/shell/spellcheck-menu.d.ts +84 -0
- package/dist/shell/spellcheck-menu.js +63 -0
- package/dist/shell/supervised-site-url.d.ts +20 -0
- package/dist/shell/supervised-site-url.js +22 -0
- package/dist/speech/macos/mac-on-device-transcriber.d.ts +2 -1
- package/dist/speech/speech-bridge.d.ts +1 -8
- package/dist/speech/transcription-port.d.ts +1 -9
- package/dist/tauri/tauri-shell.js +8 -10
- package/package.json +154 -7
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** Native menu items that persist before they apply, and in-place refresh of installed menus. */
|
|
2
|
+
/** A checkbox whose click saves first; a failed save restores the last saved state. */
|
|
3
|
+
export interface PersistedCheckboxItem {
|
|
4
|
+
type: 'checkbox';
|
|
5
|
+
label: string;
|
|
6
|
+
checked: boolean;
|
|
7
|
+
click: (item: {
|
|
8
|
+
checked: boolean;
|
|
9
|
+
}) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A native checkbox that keeps the last successfully saved state, so a failed save puts back the
|
|
13
|
+
* value that is actually on disk rather than the one the menu was built with. O(1) per click.
|
|
14
|
+
*/
|
|
15
|
+
export declare function persistedCheckbox({ label, checked, save, onError }: {
|
|
16
|
+
label: string;
|
|
17
|
+
checked: boolean;
|
|
18
|
+
save: (args: {
|
|
19
|
+
checked: boolean;
|
|
20
|
+
}) => void;
|
|
21
|
+
onError: (args: {
|
|
22
|
+
error: unknown;
|
|
23
|
+
}) => void;
|
|
24
|
+
}, _optional?: {}): PersistedCheckboxItem;
|
|
25
|
+
interface RadioState {
|
|
26
|
+
id: string;
|
|
27
|
+
checked: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** One radio of a persisted group; Electron passes the clicked item and, with it, its menu. */
|
|
30
|
+
export interface PersistedRadioItem extends RadioState {
|
|
31
|
+
type: 'radio';
|
|
32
|
+
label: string;
|
|
33
|
+
click: (item: {
|
|
34
|
+
checked: boolean;
|
|
35
|
+
menu?: {
|
|
36
|
+
items: RadioState[];
|
|
37
|
+
};
|
|
38
|
+
}) => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A native radio group that saves before it applies. A failed save re-checks the last saved radio
|
|
42
|
+
* across the whole group, because Electron has already moved the check to the clicked one.
|
|
43
|
+
* @complexity O(values) to build and per failed click.
|
|
44
|
+
*/
|
|
45
|
+
export declare function persistedRadioGroup<T>({ values, checked, idOf, labelOf, save, onError }: {
|
|
46
|
+
values: readonly T[];
|
|
47
|
+
checked: T;
|
|
48
|
+
idOf: (args: {
|
|
49
|
+
value: T;
|
|
50
|
+
}) => string;
|
|
51
|
+
labelOf: (args: {
|
|
52
|
+
value: T;
|
|
53
|
+
}) => string;
|
|
54
|
+
save: (args: {
|
|
55
|
+
value: T;
|
|
56
|
+
}) => void;
|
|
57
|
+
onError: (args: {
|
|
58
|
+
error: unknown;
|
|
59
|
+
}) => void;
|
|
60
|
+
}, _optional?: {}): PersistedRadioItem[];
|
|
61
|
+
/** Electron's `Menu` statics, narrowed to finding the installed menu's items by id. */
|
|
62
|
+
export interface RadioMenuPort {
|
|
63
|
+
getApplicationMenu(): {
|
|
64
|
+
getMenuItemById(id: string): {
|
|
65
|
+
checked: boolean;
|
|
66
|
+
} | null;
|
|
67
|
+
} | null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check the installed radio matching `checked`, so a choice saved elsewhere never disagrees with the
|
|
71
|
+
* native menu. Electron leaves sibling radios alone when one is set from code, so each is set.
|
|
72
|
+
* No installed menu is a no-op. O(values).
|
|
73
|
+
*/
|
|
74
|
+
export declare function refreshRadioGroup<T>({ menu, values, idOf, checked }: {
|
|
75
|
+
menu: RadioMenuPort;
|
|
76
|
+
values: readonly T[];
|
|
77
|
+
idOf: (args: {
|
|
78
|
+
value: T;
|
|
79
|
+
}) => string;
|
|
80
|
+
checked: T;
|
|
81
|
+
}, _optional?: {}): void;
|
|
82
|
+
/** The slice of an installed Electron `Menu` a label refresh walks. */
|
|
83
|
+
export interface CheckableMenu {
|
|
84
|
+
items: {
|
|
85
|
+
submenu?: {
|
|
86
|
+
items: {
|
|
87
|
+
label: string;
|
|
88
|
+
checked: boolean;
|
|
89
|
+
}[];
|
|
90
|
+
} | null;
|
|
91
|
+
}[];
|
|
92
|
+
}
|
|
93
|
+
/** Electron's `Menu` statics: the installed application menu, if any. */
|
|
94
|
+
export interface ApplicationMenuPort {
|
|
95
|
+
getApplicationMenu(): CheckableMenu | null;
|
|
96
|
+
}
|
|
97
|
+
/** Set each labelled checkbox in the installed menu's submenus without rebuilding any menu. O(items). */
|
|
98
|
+
export declare function refreshCheckboxesByLabel({ menu, checked }: {
|
|
99
|
+
menu: ApplicationMenuPort;
|
|
100
|
+
checked: Readonly<Record<string, boolean>>;
|
|
101
|
+
}, _optional?: {}): void;
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=menu.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Native menu items that persist before they apply, and in-place refresh of installed menus. */
|
|
2
|
+
/**
|
|
3
|
+
* A native checkbox that keeps the last successfully saved state, so a failed save puts back the
|
|
4
|
+
* value that is actually on disk rather than the one the menu was built with. O(1) per click.
|
|
5
|
+
*/
|
|
6
|
+
export function persistedCheckbox({ label, checked, save, onError }, _optional = {}) {
|
|
7
|
+
let saved = checked;
|
|
8
|
+
return {
|
|
9
|
+
type: 'checkbox', label, checked,
|
|
10
|
+
click(item) {
|
|
11
|
+
try {
|
|
12
|
+
save({ checked: item.checked });
|
|
13
|
+
saved = item.checked;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
item.checked = saved;
|
|
17
|
+
onError({ error });
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A native radio group that saves before it applies. A failed save re-checks the last saved radio
|
|
24
|
+
* across the whole group, because Electron has already moved the check to the clicked one.
|
|
25
|
+
* @complexity O(values) to build and per failed click.
|
|
26
|
+
*/
|
|
27
|
+
export function persistedRadioGroup({ values, checked, idOf, labelOf, save, onError }, _optional = {}) {
|
|
28
|
+
let saved = checked;
|
|
29
|
+
const items = values.map(value => ({
|
|
30
|
+
id: idOf({ value }), label: labelOf({ value }), type: 'radio', checked: value === saved,
|
|
31
|
+
click(item) {
|
|
32
|
+
try {
|
|
33
|
+
save({ value });
|
|
34
|
+
saved = value;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
for (const radio of item.menu?.items ?? items)
|
|
38
|
+
radio.checked = radio.id === idOf({ value: saved });
|
|
39
|
+
item.checked = value === saved;
|
|
40
|
+
onError({ error });
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}));
|
|
44
|
+
return items;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check the installed radio matching `checked`, so a choice saved elsewhere never disagrees with the
|
|
48
|
+
* native menu. Electron leaves sibling radios alone when one is set from code, so each is set.
|
|
49
|
+
* No installed menu is a no-op. O(values).
|
|
50
|
+
*/
|
|
51
|
+
export function refreshRadioGroup({ menu, values, idOf, checked }, _optional = {}) {
|
|
52
|
+
const installed = menu.getApplicationMenu();
|
|
53
|
+
for (const value of values) {
|
|
54
|
+
const radio = installed?.getMenuItemById(idOf({ value }));
|
|
55
|
+
if (radio)
|
|
56
|
+
radio.checked = value === checked;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Set each labelled checkbox in the installed menu's submenus without rebuilding any menu. O(items). */
|
|
60
|
+
export function refreshCheckboxesByLabel({ menu, checked }, _optional = {}) {
|
|
61
|
+
const items = menu.getApplicationMenu()?.items.flatMap(item => item.submenu?.items ?? []) ?? [];
|
|
62
|
+
for (const item of items) {
|
|
63
|
+
if (Object.hasOwn(checked, item.label))
|
|
64
|
+
item.checked = checked[item.label];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=menu.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Read and update one key of a host's JSON preferences file through injected durable-file effects. */
|
|
2
|
+
/** One read of the preferences file, as the host's durable JSON store reports it. */
|
|
3
|
+
export type PreferenceFileRead = {
|
|
4
|
+
state: 'ok';
|
|
5
|
+
value: unknown;
|
|
6
|
+
} | {
|
|
7
|
+
state: 'missing';
|
|
8
|
+
} | {
|
|
9
|
+
state: 'unreadable';
|
|
10
|
+
};
|
|
11
|
+
/** The durable-file effects a host binds: a read, a cross-process lock and an atomic replace. */
|
|
12
|
+
export interface PreferenceFilePort {
|
|
13
|
+
read(args: {
|
|
14
|
+
filePath: string;
|
|
15
|
+
}): PreferenceFileRead;
|
|
16
|
+
withLock(args: {
|
|
17
|
+
filePath: string;
|
|
18
|
+
critical: () => void;
|
|
19
|
+
}): void;
|
|
20
|
+
writeAtomic(args: {
|
|
21
|
+
filePath: string;
|
|
22
|
+
value: unknown;
|
|
23
|
+
}): void;
|
|
24
|
+
}
|
|
25
|
+
/** Why a read fell back: unparsable bytes, valid JSON that is not an object, or a rejected value. */
|
|
26
|
+
export type PreferenceProblem = 'unreadable' | 'not-an-object' | 'invalid-value';
|
|
27
|
+
/** Thrown by a write that finds unreadable bytes; the bytes are left untouched. */
|
|
28
|
+
export declare const PREFERENCES_UNREADABLE = "DESKTOP_PREFERENCES_UNREADABLE";
|
|
29
|
+
/** The whole settings object; anything but a readable JSON object reads as no settings. O(file bytes). */
|
|
30
|
+
export declare function readPreferenceSettings({ file, filePath }: {
|
|
31
|
+
file: PreferenceFilePort;
|
|
32
|
+
filePath: string;
|
|
33
|
+
}, _optional?: {}): Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* One saved value. A missing file or key reads `fallback` silently; every other fallback names its
|
|
36
|
+
* problem so the host can word its own warning. `parse` answers undefined to reject a stored value.
|
|
37
|
+
* @complexity O(file bytes) time and space.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readPreferenceValue<T>({ file, filePath, key, parse, fallback }: {
|
|
40
|
+
file: PreferenceFilePort;
|
|
41
|
+
filePath: string;
|
|
42
|
+
key: string;
|
|
43
|
+
parse: (args: {
|
|
44
|
+
value: unknown;
|
|
45
|
+
}) => T | undefined;
|
|
46
|
+
fallback: T;
|
|
47
|
+
}, { onProblem }?: {
|
|
48
|
+
onProblem?: (args: {
|
|
49
|
+
problem: PreferenceProblem;
|
|
50
|
+
}) => void;
|
|
51
|
+
}): T;
|
|
52
|
+
/**
|
|
53
|
+
* Save one key under the file lock, keeping every other setting. Unreadable bytes are preserved
|
|
54
|
+
* rather than silently replaced: the write throws `PREFERENCES_UNREADABLE` instead.
|
|
55
|
+
* @complexity O(file bytes) time and space, one atomic write.
|
|
56
|
+
*/
|
|
57
|
+
export declare function writePreferenceValue({ file, filePath, key, value }: {
|
|
58
|
+
file: PreferenceFilePort;
|
|
59
|
+
filePath: string;
|
|
60
|
+
key: string;
|
|
61
|
+
value: unknown;
|
|
62
|
+
}, _optional?: {}): void;
|
|
63
|
+
//# sourceMappingURL=preference-file.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Read and update one key of a host's JSON preferences file through injected durable-file effects. */
|
|
2
|
+
/** Thrown by a write that finds unreadable bytes; the bytes are left untouched. */
|
|
3
|
+
export const PREFERENCES_UNREADABLE = 'DESKTOP_PREFERENCES_UNREADABLE';
|
|
4
|
+
function settingsObject({ value }, _optional = {}) {
|
|
5
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
6
|
+
}
|
|
7
|
+
/** The whole settings object; anything but a readable JSON object reads as no settings. O(file bytes). */
|
|
8
|
+
export function readPreferenceSettings({ file, filePath }, _optional = {}) {
|
|
9
|
+
const read = file.read({ filePath });
|
|
10
|
+
return (read.state === 'ok' ? settingsObject({ value: read.value }) : undefined) ?? {};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One saved value. A missing file or key reads `fallback` silently; every other fallback names its
|
|
14
|
+
* problem so the host can word its own warning. `parse` answers undefined to reject a stored value.
|
|
15
|
+
* @complexity O(file bytes) time and space.
|
|
16
|
+
*/
|
|
17
|
+
export function readPreferenceValue({ file, filePath, key, parse, fallback }, { onProblem = () => { } } = {}) {
|
|
18
|
+
const read = file.read({ filePath });
|
|
19
|
+
if (read.state === 'missing')
|
|
20
|
+
return fallback;
|
|
21
|
+
if (read.state === 'unreadable') {
|
|
22
|
+
onProblem({ problem: 'unreadable' });
|
|
23
|
+
return fallback;
|
|
24
|
+
}
|
|
25
|
+
const settings = settingsObject({ value: read.value });
|
|
26
|
+
if (!settings) {
|
|
27
|
+
onProblem({ problem: 'not-an-object' });
|
|
28
|
+
return fallback;
|
|
29
|
+
}
|
|
30
|
+
const value = settings[key];
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
return fallback;
|
|
33
|
+
const parsed = parse({ value });
|
|
34
|
+
if (parsed !== undefined)
|
|
35
|
+
return parsed;
|
|
36
|
+
onProblem({ problem: 'invalid-value' });
|
|
37
|
+
return fallback;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Save one key under the file lock, keeping every other setting. Unreadable bytes are preserved
|
|
41
|
+
* rather than silently replaced: the write throws `PREFERENCES_UNREADABLE` instead.
|
|
42
|
+
* @complexity O(file bytes) time and space, one atomic write.
|
|
43
|
+
*/
|
|
44
|
+
export function writePreferenceValue({ file, filePath, key, value }, _optional = {}) {
|
|
45
|
+
file.withLock({ filePath, critical: () => {
|
|
46
|
+
if (file.read({ filePath }).state === 'unreadable')
|
|
47
|
+
throw new Error(PREFERENCES_UNREADABLE);
|
|
48
|
+
file.writeAtomic({ filePath, value: { ...readPreferenceSettings({ file, filePath }), [key]: value } });
|
|
49
|
+
} });
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=preference-file.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Pure checks for numeric and enumerated preference values; the host owns the bounds and choices. */
|
|
2
|
+
/** Inclusive whole-number bounds a host chooses for a stepper or radio group. */
|
|
3
|
+
export interface WholeNumberBounds {
|
|
4
|
+
min: number;
|
|
5
|
+
max: number;
|
|
6
|
+
}
|
|
7
|
+
/** The value when it is a safe whole number above zero, else undefined. O(1). */
|
|
8
|
+
export declare function positiveWholeNumber({ value }: {
|
|
9
|
+
value: unknown;
|
|
10
|
+
}, _optional?: {}): number | undefined;
|
|
11
|
+
/** Clamp into the inclusive bounds; callers validate that `value` is a whole number first. O(1). */
|
|
12
|
+
export declare function clampWholeNumber({ value, bounds }: {
|
|
13
|
+
value: number;
|
|
14
|
+
bounds: WholeNumberBounds;
|
|
15
|
+
}, _optional?: {}): number;
|
|
16
|
+
/** Every whole number from min to max, in order. O(max - min). */
|
|
17
|
+
export declare function wholeNumberSteps({ bounds }: {
|
|
18
|
+
bounds: WholeNumberBounds;
|
|
19
|
+
}, _optional?: {}): number[];
|
|
20
|
+
/** The shipped choice equal to `value`, or undefined. O(choices). */
|
|
21
|
+
export declare function choiceOf<T>({ value, choices }: {
|
|
22
|
+
value: unknown;
|
|
23
|
+
choices: readonly T[];
|
|
24
|
+
}, _optional?: {}): T | undefined;
|
|
25
|
+
//# sourceMappingURL=values.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Pure checks for numeric and enumerated preference values; the host owns the bounds and choices. */
|
|
2
|
+
/** The value when it is a safe whole number above zero, else undefined. O(1). */
|
|
3
|
+
export function positiveWholeNumber({ value }, _optional = {}) {
|
|
4
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined;
|
|
5
|
+
}
|
|
6
|
+
/** Clamp into the inclusive bounds; callers validate that `value` is a whole number first. O(1). */
|
|
7
|
+
export function clampWholeNumber({ value, bounds }, _optional = {}) {
|
|
8
|
+
return Math.min(bounds.max, Math.max(bounds.min, value));
|
|
9
|
+
}
|
|
10
|
+
/** Every whole number from min to max, in order. O(max - min). */
|
|
11
|
+
export function wholeNumberSteps({ bounds }, _optional = {}) {
|
|
12
|
+
return Array.from({ length: bounds.max - bounds.min + 1 }, (_, index) => bounds.min + index);
|
|
13
|
+
}
|
|
14
|
+
/** The shipped choice equal to `value`, or undefined. O(choices). */
|
|
15
|
+
export function choiceOf({ value, choices }, _optional = {}) {
|
|
16
|
+
return choices.find(choice => choice === value);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The raw `(event, payload)` callback Electron's `ipcRenderer.on` registers. */
|
|
2
|
+
export type PreloadIpcHandler = (event: unknown, payload: unknown) => void;
|
|
3
|
+
/**
|
|
4
|
+
* The two `ipcRenderer` listener methods a preload subscriber needs, args-object shaped. The host
|
|
5
|
+
* adapts Electron's positional `ipcRenderer.on(channel, handler)` / `removeListener(channel, handler)`
|
|
6
|
+
* and must pass `handler` through unchanged: cleanup relies on removing that exact function.
|
|
7
|
+
*/
|
|
8
|
+
export interface PreloadIpcListenerPort {
|
|
9
|
+
on(args: {
|
|
10
|
+
channel: string;
|
|
11
|
+
handler: PreloadIpcHandler;
|
|
12
|
+
}): unknown;
|
|
13
|
+
removeListener(args: {
|
|
14
|
+
channel: string;
|
|
15
|
+
handler: PreloadIpcHandler;
|
|
16
|
+
}): unknown;
|
|
17
|
+
}
|
|
18
|
+
/** Subscribes one renderer listener to one main-to-renderer push channel; returns its teardown. */
|
|
19
|
+
export type PreloadSubscribe = <Payload>(args: {
|
|
20
|
+
channel: string;
|
|
21
|
+
listener: (payload: Payload) => void;
|
|
22
|
+
}, _optional?: Record<string, unknown>) => () => void;
|
|
23
|
+
/**
|
|
24
|
+
* Builds the preload's channel subscriber. The channel allowlist stays with the host: the host's
|
|
25
|
+
* preload calls this only with its own fixed contract channels and never exposes it to the page.
|
|
26
|
+
*
|
|
27
|
+
* The raw `IpcRendererEvent` is dropped rather than forwarded: it carries `sender`, which is a live
|
|
28
|
+
* handle into IPC that the page has no business holding, and returning the unsubscribe function is
|
|
29
|
+
* what lets the renderer detach a pane without leaking a listener per remount.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPreloadSubscriber({ ipcRenderer }: {
|
|
32
|
+
ipcRenderer: PreloadIpcListenerPort;
|
|
33
|
+
}, _optional?: {}): PreloadSubscribe;
|
|
34
|
+
//# sourceMappingURL=ipc-subscribe.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the preload's channel subscriber. The channel allowlist stays with the host: the host's
|
|
3
|
+
* preload calls this only with its own fixed contract channels and never exposes it to the page.
|
|
4
|
+
*
|
|
5
|
+
* The raw `IpcRendererEvent` is dropped rather than forwarded: it carries `sender`, which is a live
|
|
6
|
+
* handle into IPC that the page has no business holding, and returning the unsubscribe function is
|
|
7
|
+
* what lets the renderer detach a pane without leaking a listener per remount.
|
|
8
|
+
*/
|
|
9
|
+
export function createPreloadSubscriber({ ipcRenderer }, _optional = {}) {
|
|
10
|
+
return ({ channel, listener }, _optional = {}) => {
|
|
11
|
+
const handler = (_event, payload) => listener(payload);
|
|
12
|
+
ipcRenderer.on({ channel, handler });
|
|
13
|
+
return () => {
|
|
14
|
+
ipcRenderer.removeListener({ channel, handler });
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ipc-subscribe.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Tracks window load outcomes for the host's desktop self-test mode, split out of `main.ts` so the
|
|
3
|
+
* completion/failure semantics are directly testable under plain `node --test` — this module has no
|
|
4
|
+
* `electron` import at all; it only needs a window shaped `{ webContents: { once(event, cb),
|
|
5
|
+
* getURL(), getTitle() } }`, which a fake object can satisfy just as well as a real `BrowserWindow`.
|
|
6
|
+
*
|
|
7
|
+
* Reporting and process control (the `console.log`/`process.exitCode`/`app.quit()` a real self-test
|
|
8
|
+
* run needs) are NOT done here — they are the three injected callbacks below — so this file stays a
|
|
9
|
+
* pure completion tracker and `main.ts` keeps the only code that actually touches Electron or the
|
|
10
|
+
* process.
|
|
11
|
+
*
|
|
12
|
+
* Two, not one, ordering hazards had to be closed together — fixing only the first re-created the
|
|
13
|
+
* second, confirmed live (2026-09-05) against a real 2-site launch:
|
|
14
|
+
*
|
|
15
|
+
* 1. **Registration must happen per-window, at creation time, not after the whole batch is open.**
|
|
16
|
+
* A single-site launch's own window finishes loading in well under a second; a multi-site
|
|
17
|
+
* launch's FIRST window can finish loading while its SECOND site's server is still booting
|
|
18
|
+
* (`loadURL` is fire-and-forget, and `main.ts` opens each site in its startup loop sequentially).
|
|
19
|
+
* Registering `did-finish-load` listeners only after every window in the batch exists would miss
|
|
20
|
+
* an earlier window's event entirely — Electron does not replay a past event to a listener
|
|
21
|
+
* attached after the fact. `main.ts`'s `createWindow` therefore calls this tracker's `add()` the
|
|
22
|
+
* INSTANT each window is created, before that window's own `loadURL` call.
|
|
23
|
+
* 2. **The expected window COUNT must be fixed upfront, not incremented as each window is added.**
|
|
24
|
+
* Fixing (1) alone by incrementing a counter inside `add()` reintroduced a worse failure: if
|
|
25
|
+
* window 1 finishes loading before window 2 is even created (exactly the ordering (1) describes),
|
|
26
|
+
* an incrementally-built counter reads "1 of 1 done" and quits immediately — before window 2's
|
|
27
|
+
* site ever gets a chance to open at all. Seeding `remaining` from the caller's own already-known
|
|
28
|
+
* total (it always knows how many sites it is about to open) up front makes early completions
|
|
29
|
+
* correctly WAIT rather than conclude the batch is done.
|
|
30
|
+
*/
|
|
31
|
+
/** The slice of Electron's `WebContents` this tracker touches. Overloaded per event, as Electron's own
|
|
32
|
+
* declaration is, so a real `BrowserWindow` and a test fake both satisfy it. */
|
|
33
|
+
interface SelftestWebContents {
|
|
34
|
+
on(event: "did-fail-load", listener: (event: unknown, code: number, description: string, validatedURL: string, isMainFrame: boolean) => void): unknown;
|
|
35
|
+
once(event: "did-finish-load", listener: () => void): unknown;
|
|
36
|
+
getURL(): string;
|
|
37
|
+
getTitle(): string;
|
|
38
|
+
}
|
|
39
|
+
/** A window as this tracker sees it: `BrowserWindow`, or a fake with the same `webContents` slice. */
|
|
40
|
+
interface SelftestWindow {
|
|
41
|
+
webContents: SelftestWebContents;
|
|
42
|
+
}
|
|
43
|
+
/** The three effects {@link createSelftestTracker} leaves to its caller. */
|
|
44
|
+
interface SelftestCallbacks {
|
|
45
|
+
onWindowLoaded(info: {
|
|
46
|
+
url: string;
|
|
47
|
+
title: string;
|
|
48
|
+
}): void;
|
|
49
|
+
onWindowFailed(info: {
|
|
50
|
+
url: string;
|
|
51
|
+
code: number;
|
|
52
|
+
description: string;
|
|
53
|
+
}): void;
|
|
54
|
+
onAllSettled(info: {
|
|
55
|
+
failed: boolean;
|
|
56
|
+
}): void;
|
|
57
|
+
}
|
|
58
|
+
/** What {@link createSelftestTracker} returns. */
|
|
59
|
+
interface SelftestTracker {
|
|
60
|
+
add(window: SelftestWindow): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @param input.expectedCount how many windows this launch will open, known by the caller before any of
|
|
64
|
+
* them exist (e.g. `siteDirs.length`) — see this file's own header, hazard 2.
|
|
65
|
+
* @param input.callbacks.onWindowLoaded `({ url, title }) => void` — called once per window that finishes
|
|
66
|
+
* loading successfully.
|
|
67
|
+
* @param input.callbacks.onWindowFailed `({ url, code, description }) => void` — called at most once, for
|
|
68
|
+
* the first window (if any) that fails to load.
|
|
69
|
+
* @param input.callbacks.onAllSettled `({ failed }) => void` — called exactly once, either once every
|
|
70
|
+
* expected window has loaded successfully (`failed: false`) or as soon as any one fails
|
|
71
|
+
* (`failed: true`) — never both.
|
|
72
|
+
* @returns `{ add(window) }` — call once per window, as soon as it is created; must be called
|
|
73
|
+
* exactly `expectedCount` times over this tracker's lifetime.
|
|
74
|
+
* @complexity O(1) to construct; `add()` is O(1) per call.
|
|
75
|
+
*/
|
|
76
|
+
declare function createSelftestTracker({ expectedCount, callbacks }: {
|
|
77
|
+
expectedCount: number;
|
|
78
|
+
callbacks: SelftestCallbacks;
|
|
79
|
+
}, _options?: Record<string, never>): SelftestTracker;
|
|
80
|
+
export { createSelftestTracker };
|
|
81
|
+
export type { SelftestCallbacks, SelftestTracker, SelftestWebContents, SelftestWindow };
|
|
82
|
+
//# sourceMappingURL=selftest-tracker.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Tracks window load outcomes for the host's desktop self-test mode, split out of `main.ts` so the
|
|
3
|
+
* completion/failure semantics are directly testable under plain `node --test` — this module has no
|
|
4
|
+
* `electron` import at all; it only needs a window shaped `{ webContents: { once(event, cb),
|
|
5
|
+
* getURL(), getTitle() } }`, which a fake object can satisfy just as well as a real `BrowserWindow`.
|
|
6
|
+
*
|
|
7
|
+
* Reporting and process control (the `console.log`/`process.exitCode`/`app.quit()` a real self-test
|
|
8
|
+
* run needs) are NOT done here — they are the three injected callbacks below — so this file stays a
|
|
9
|
+
* pure completion tracker and `main.ts` keeps the only code that actually touches Electron or the
|
|
10
|
+
* process.
|
|
11
|
+
*
|
|
12
|
+
* Two, not one, ordering hazards had to be closed together — fixing only the first re-created the
|
|
13
|
+
* second, confirmed live (2026-09-05) against a real 2-site launch:
|
|
14
|
+
*
|
|
15
|
+
* 1. **Registration must happen per-window, at creation time, not after the whole batch is open.**
|
|
16
|
+
* A single-site launch's own window finishes loading in well under a second; a multi-site
|
|
17
|
+
* launch's FIRST window can finish loading while its SECOND site's server is still booting
|
|
18
|
+
* (`loadURL` is fire-and-forget, and `main.ts` opens each site in its startup loop sequentially).
|
|
19
|
+
* Registering `did-finish-load` listeners only after every window in the batch exists would miss
|
|
20
|
+
* an earlier window's event entirely — Electron does not replay a past event to a listener
|
|
21
|
+
* attached after the fact. `main.ts`'s `createWindow` therefore calls this tracker's `add()` the
|
|
22
|
+
* INSTANT each window is created, before that window's own `loadURL` call.
|
|
23
|
+
* 2. **The expected window COUNT must be fixed upfront, not incremented as each window is added.**
|
|
24
|
+
* Fixing (1) alone by incrementing a counter inside `add()` reintroduced a worse failure: if
|
|
25
|
+
* window 1 finishes loading before window 2 is even created (exactly the ordering (1) describes),
|
|
26
|
+
* an incrementally-built counter reads "1 of 1 done" and quits immediately — before window 2's
|
|
27
|
+
* site ever gets a chance to open at all. Seeding `remaining` from the caller's own already-known
|
|
28
|
+
* total (it always knows how many sites it is about to open) up front makes early completions
|
|
29
|
+
* correctly WAIT rather than conclude the batch is done.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* @param input.expectedCount how many windows this launch will open, known by the caller before any of
|
|
33
|
+
* them exist (e.g. `siteDirs.length`) — see this file's own header, hazard 2.
|
|
34
|
+
* @param input.callbacks.onWindowLoaded `({ url, title }) => void` — called once per window that finishes
|
|
35
|
+
* loading successfully.
|
|
36
|
+
* @param input.callbacks.onWindowFailed `({ url, code, description }) => void` — called at most once, for
|
|
37
|
+
* the first window (if any) that fails to load.
|
|
38
|
+
* @param input.callbacks.onAllSettled `({ failed }) => void` — called exactly once, either once every
|
|
39
|
+
* expected window has loaded successfully (`failed: false`) or as soon as any one fails
|
|
40
|
+
* (`failed: true`) — never both.
|
|
41
|
+
* @returns `{ add(window) }` — call once per window, as soon as it is created; must be called
|
|
42
|
+
* exactly `expectedCount` times over this tracker's lifetime.
|
|
43
|
+
* @complexity O(1) to construct; `add()` is O(1) per call.
|
|
44
|
+
*/
|
|
45
|
+
function createSelftestTracker({ expectedCount, callbacks }, _options = {}) {
|
|
46
|
+
let remaining = expectedCount;
|
|
47
|
+
let failed = false;
|
|
48
|
+
return {
|
|
49
|
+
add(window) {
|
|
50
|
+
window.webContents.on("did-fail-load", (_event, code, description, _validatedURL, isMainFrame) => {
|
|
51
|
+
if (failed || !isMainFrame || code === -3)
|
|
52
|
+
return;
|
|
53
|
+
failed = true;
|
|
54
|
+
callbacks.onWindowFailed({ url: window.webContents.getURL(), code, description });
|
|
55
|
+
callbacks.onAllSettled({ failed: true });
|
|
56
|
+
});
|
|
57
|
+
window.webContents.once("did-finish-load", () => {
|
|
58
|
+
callbacks.onWindowLoaded({ url: window.webContents.getURL(), title: window.webContents.getTitle() });
|
|
59
|
+
remaining -= 1;
|
|
60
|
+
if (remaining === 0 && !failed)
|
|
61
|
+
callbacks.onAllSettled({ failed: false });
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export { createSelftestTracker };
|
|
67
|
+
//# sourceMappingURL=selftest-tracker.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The cookie exchange: one request bound to a partition's `Session`, so whatever cookie the
|
|
3
|
+
* server answers with lands in that partition's own jar.
|
|
4
|
+
*
|
|
5
|
+
* `useSessionCookies: true` is what makes this work without any manual `Set-Cookie` parsing or
|
|
6
|
+
* `cookies.set()` call: the request goes through Chromium's network stack bound to that session, so
|
|
7
|
+
* the response's cookie is stored exactly as it would be for a real navigation, including the
|
|
8
|
+
* `Secure` attribute, which Chromium accepts over loopback because `127.0.0.1` is a trustworthy
|
|
9
|
+
* origin. Dropping it makes the whole mechanism a silent no-op while every other signal still looks
|
|
10
|
+
* healthy, so a test is pinned to it.
|
|
11
|
+
*
|
|
12
|
+
* Never rejects for an auth or transport outcome: a non-`200` and a transport error both resolve
|
|
13
|
+
* `{ok: false}`, so the host falls through to its ordinary login screen. The host owns the URL (and
|
|
14
|
+
* must guard it, e.g. loopback-only, BEFORE calling), the body, the outcome label, and the text a
|
|
15
|
+
* transport error becomes (`describeError`): the caught error goes to the host raw.
|
|
16
|
+
*/
|
|
17
|
+
import type { SessionBodyRequest, SessionNet, SessionOutcome } from './types.js';
|
|
18
|
+
/** The host's text for a transport error, stored as the outcome's `reason`. */
|
|
19
|
+
type DescribeTransportError = (args: {
|
|
20
|
+
error: Error;
|
|
21
|
+
}) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Send a body-less request through `required.session`'s cookie jar and report its outcome.
|
|
24
|
+
* @param required.label names the exchange in a non-`200` reason (`"<label> responded <status>"`).
|
|
25
|
+
* @param required.describeError the host's `reason` text for a transport error.
|
|
26
|
+
* @complexity O(1) — one request.
|
|
27
|
+
*/
|
|
28
|
+
export declare function exchangeSessionRequest<TSession>(required: {
|
|
29
|
+
net: SessionNet<TSession>;
|
|
30
|
+
session: TSession;
|
|
31
|
+
method: 'GET' | 'POST';
|
|
32
|
+
url: string;
|
|
33
|
+
label: string;
|
|
34
|
+
describeError: DescribeTransportError;
|
|
35
|
+
}, _optional?: Record<string, never>): Promise<SessionOutcome>;
|
|
36
|
+
/**
|
|
37
|
+
* POST an already-serialised JSON `body` through `required.session`'s cookie jar and report its
|
|
38
|
+
* outcome — the exchange that redeems a credential for a session cookie.
|
|
39
|
+
* @complexity O(1) — one request.
|
|
40
|
+
*/
|
|
41
|
+
export declare function exchangeSessionJson<TSession>(required: {
|
|
42
|
+
net: SessionNet<TSession, SessionBodyRequest>;
|
|
43
|
+
session: TSession;
|
|
44
|
+
url: string;
|
|
45
|
+
body: string;
|
|
46
|
+
label: string;
|
|
47
|
+
describeError: DescribeTransportError;
|
|
48
|
+
}, _optional?: Record<string, never>): Promise<SessionOutcome>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=exchange.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Attach the outcome listeners. Resolves only on `end`: headers and a partial body are not a
|
|
2
|
+
* completed exchange. */
|
|
3
|
+
function settle({ request, label, describeError, resolve }, _optional = {}) {
|
|
4
|
+
request.on('response', (response) => {
|
|
5
|
+
// Drained rather than parsed: nothing here needs the body, and an undrained response holds the
|
|
6
|
+
// socket open.
|
|
7
|
+
response.on('data', () => { });
|
|
8
|
+
response.on('end', () => resolve(response.statusCode === 200
|
|
9
|
+
? { ok: true, status: 200 }
|
|
10
|
+
: { ok: false, status: response.statusCode, reason: `${label} responded ${response.statusCode}` }));
|
|
11
|
+
});
|
|
12
|
+
request.on('error', (error) => resolve({ ok: false, reason: describeError({ error }) }));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Send a body-less request through `required.session`'s cookie jar and report its outcome.
|
|
16
|
+
* @param required.label names the exchange in a non-`200` reason (`"<label> responded <status>"`).
|
|
17
|
+
* @param required.describeError the host's `reason` text for a transport error.
|
|
18
|
+
* @complexity O(1) — one request.
|
|
19
|
+
*/
|
|
20
|
+
export function exchangeSessionRequest(required, _optional = {}) {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
const request = required.net.request({ method: required.method, url: required.url, session: required.session, useSessionCookies: true });
|
|
23
|
+
settle({ request, label: required.label, describeError: required.describeError, resolve });
|
|
24
|
+
request.end();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* POST an already-serialised JSON `body` through `required.session`'s cookie jar and report its
|
|
29
|
+
* outcome — the exchange that redeems a credential for a session cookie.
|
|
30
|
+
* @complexity O(1) — one request.
|
|
31
|
+
*/
|
|
32
|
+
export function exchangeSessionJson(required, _optional = {}) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
const request = required.net.request({ method: 'POST', url: required.url, session: required.session, useSessionCookies: true });
|
|
35
|
+
request.setHeader('Content-Type', 'application/json');
|
|
36
|
+
settle({ request, label: required.label, describeError: required.describeError, resolve });
|
|
37
|
+
request.write(required.body);
|
|
38
|
+
request.end();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=exchange.js.map
|