@jini-ai/desktop-host 0.1.1 → 0.4.0
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 +106 -0
- package/README.md +194 -0
- package/dist/bridge-testing.d.ts +2 -2
- package/dist/bridge-testing.js +3 -3
- package/dist/bridge.d.ts +33 -9
- package/dist/bridge.js +18 -17
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -1
- package/dist/electron/create-electron-desktop-host.js +5 -5
- package/dist/electron/electron-protocol.d.ts +3 -1
- package/dist/electron/electron-protocol.js +7 -7
- package/dist/electron/electron-render-service.d.ts +3 -1
- package/dist/electron/electron-render-service.js +21 -20
- package/dist/electron/electron-shell.js +8 -8
- package/dist/electron/electron-single-instance.d.ts +3 -1
- package/dist/electron/electron-single-instance.js +3 -3
- package/dist/electron/electron-surfaces.d.ts +71 -32
- package/dist/electron/electron-surfaces.js +3 -10
- package/dist/electron/electron-window-lifecycle.d.ts +3 -1
- package/dist/electron/electron-window-lifecycle.js +17 -16
- package/dist/electron/index.d.ts +17 -0
- package/dist/electron/index.js +17 -0
- package/dist/electron/navigation-policy/index.d.ts +3 -0
- package/dist/electron/navigation-policy/index.js +3 -0
- package/dist/electron/navigation-policy/webview-guest-policy.d.ts +32 -0
- package/dist/electron/navigation-policy/webview-guest-policy.js +31 -0
- package/dist/electron/navigation-policy/window-navigation-policy.d.ts +125 -0
- package/dist/electron/navigation-policy/window-navigation-policy.js +138 -0
- package/dist/electron/testing.d.ts +8 -6
- package/dist/electron/testing.js +22 -22
- package/dist/electron/updates/auto-update-controller.d.ts +146 -0
- package/dist/electron/updates/auto-update-controller.js +222 -0
- package/dist/electron/updates/index.d.ts +4 -0
- package/dist/electron/updates/index.js +4 -0
- package/dist/electron/updates/instance-presence.d.ts +68 -0
- package/dist/electron/updates/instance-presence.js +79 -0
- package/dist/electron/updates/update-policy.d.ts +66 -0
- package/dist/electron/updates/update-policy.js +65 -0
- package/dist/electron/usability/find-in-page-ipc.d.ts +88 -0
- package/dist/electron/usability/find-in-page-ipc.js +22 -0
- package/dist/electron/usability/find-menu.d.ts +43 -0
- package/dist/electron/usability/find-menu.js +22 -0
- package/dist/electron/usability/index.d.ts +6 -0
- package/dist/electron/usability/index.js +6 -0
- package/dist/electron/usability/spellcheck-menu.d.ts +92 -0
- package/dist/electron/usability/spellcheck-menu.js +52 -0
- package/dist/electron/usability/window-bounds-store.d.ts +76 -0
- package/dist/electron/usability/window-bounds-store.js +44 -0
- package/dist/electron/usability/zoom-menu.d.ts +41 -0
- package/dist/electron/usability/zoom-menu.js +19 -0
- package/dist/index.d.ts +8 -16
- package/dist/index.js +8 -16
- package/dist/logging.d.ts +26 -12
- package/dist/logging.js +21 -21
- package/dist/node-toolchain/index.d.ts +76 -0
- package/dist/node-toolchain/index.js +96 -0
- package/dist/paths.d.ts +4 -2
- package/dist/paths.js +5 -4
- package/dist/protocol.d.ts +20 -5
- package/dist/protocol.js +5 -5
- package/dist/render-service.d.ts +31 -7
- package/dist/render-service.js +10 -10
- package/dist/shell.d.ts +15 -7
- package/dist/shell.js +3 -3
- package/dist/shutdown/index.d.ts +4 -0
- package/dist/shutdown/index.js +4 -0
- package/dist/shutdown/quit-drain-gate.d.ts +19 -0
- package/dist/shutdown/quit-drain-gate.js +15 -0
- package/dist/shutdown/quit-signals.d.ts +36 -0
- package/dist/shutdown/quit-signals.js +27 -0
- package/dist/shutdown/shutdown-tracker.d.ts +19 -0
- package/dist/shutdown/shutdown-tracker.js +26 -0
- package/dist/sidecar.d.ts +20 -8
- package/dist/sidecar.js +39 -22
- package/dist/single-instance.d.ts +13 -4
- package/dist/single-instance.js +4 -4
- package/dist/speech/channels.d.ts +8 -0
- package/dist/speech/channels.js +5 -0
- package/dist/speech/index.d.ts +5 -0
- package/dist/speech/index.js +5 -0
- package/dist/speech/macos/index.d.ts +2 -0
- package/dist/speech/macos/index.js +2 -0
- package/dist/speech/macos/mac-on-device-transcriber.d.ts +97 -0
- package/dist/speech/macos/mac-on-device-transcriber.js +95 -0
- package/dist/speech/macos/speech-helper.swift +157 -0
- package/dist/speech/pcm-wav-encoder.d.ts +22 -0
- package/dist/speech/pcm-wav-encoder.js +50 -0
- package/dist/speech/speech-bridge.d.ts +33 -0
- package/dist/speech/speech-bridge.js +14 -0
- package/dist/speech/speech-ipc.d.ts +44 -0
- package/dist/speech/speech-ipc.js +50 -0
- package/dist/speech/transcription-port.d.ts +42 -0
- package/dist/speech/transcription-port.js +14 -0
- package/dist/tauri/create-tauri-desktop-host.js +5 -5
- package/dist/tauri/index.d.ts +19 -0
- package/dist/tauri/index.js +19 -0
- package/dist/tauri/not-implemented.d.ts +3 -1
- package/dist/tauri/not-implemented.js +1 -1
- package/dist/tauri/tauri-protocol.d.ts +1 -1
- package/dist/tauri/tauri-protocol.js +2 -2
- package/dist/tauri/tauri-render-service.d.ts +1 -1
- package/dist/tauri/tauri-render-service.js +2 -2
- package/dist/tauri/tauri-shell.js +8 -8
- package/dist/tauri/tauri-sidecar.d.ts +3 -1
- package/dist/tauri/tauri-sidecar.js +17 -16
- package/dist/tauri/tauri-single-instance.d.ts +3 -1
- package/dist/tauri/tauri-single-instance.js +3 -3
- package/dist/tauri/tauri-surfaces.d.ts +50 -14
- package/dist/tauri/tauri-surfaces.js +2 -1
- package/dist/tauri/tauri-window-lifecycle.d.ts +3 -1
- package/dist/tauri/tauri-window-lifecycle.js +33 -20
- package/dist/tauri/testing.d.ts +10 -7
- package/dist/tauri/testing.js +30 -23
- package/dist/tokens.js +6 -6
- package/dist/window-lifecycle.d.ts +10 -4
- package/dist/window-lifecycle.js +7 -7
- package/dist/windows-registry.d.ts +16 -6
- package/dist/windows-registry.js +8 -7
- package/package.json +73 -6
- package/dist/bridge-testing.d.ts.map +0 -1
- package/dist/bridge-testing.js.map +0 -1
- package/dist/bridge.d.ts.map +0 -1
- package/dist/bridge.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/electron/create-electron-desktop-host.d.ts.map +0 -1
- package/dist/electron/create-electron-desktop-host.js.map +0 -1
- package/dist/electron/electron-protocol.d.ts.map +0 -1
- package/dist/electron/electron-protocol.js.map +0 -1
- package/dist/electron/electron-render-service.d.ts.map +0 -1
- package/dist/electron/electron-render-service.js.map +0 -1
- package/dist/electron/electron-shell.d.ts.map +0 -1
- package/dist/electron/electron-shell.js.map +0 -1
- package/dist/electron/electron-single-instance.d.ts.map +0 -1
- package/dist/electron/electron-single-instance.js.map +0 -1
- package/dist/electron/electron-surfaces.d.ts.map +0 -1
- package/dist/electron/electron-surfaces.js.map +0 -1
- package/dist/electron/electron-window-lifecycle.d.ts.map +0 -1
- package/dist/electron/electron-window-lifecycle.js.map +0 -1
- package/dist/electron/testing.d.ts.map +0 -1
- package/dist/electron/testing.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logging.d.ts.map +0 -1
- package/dist/logging.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/ports.d.ts.map +0 -1
- package/dist/ports.js.map +0 -1
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js.map +0 -1
- package/dist/render-service.d.ts.map +0 -1
- package/dist/render-service.js.map +0 -1
- package/dist/shell.d.ts.map +0 -1
- package/dist/shell.js.map +0 -1
- package/dist/sidecar.d.ts.map +0 -1
- package/dist/sidecar.js.map +0 -1
- package/dist/single-instance.d.ts.map +0 -1
- package/dist/single-instance.js.map +0 -1
- package/dist/tauri/create-tauri-desktop-host.d.ts.map +0 -1
- package/dist/tauri/create-tauri-desktop-host.js.map +0 -1
- package/dist/tauri/not-implemented.d.ts.map +0 -1
- package/dist/tauri/not-implemented.js.map +0 -1
- package/dist/tauri/tauri-protocol.d.ts.map +0 -1
- package/dist/tauri/tauri-protocol.js.map +0 -1
- package/dist/tauri/tauri-render-service.d.ts.map +0 -1
- package/dist/tauri/tauri-render-service.js.map +0 -1
- package/dist/tauri/tauri-shell.d.ts.map +0 -1
- package/dist/tauri/tauri-shell.js.map +0 -1
- package/dist/tauri/tauri-sidecar.d.ts.map +0 -1
- package/dist/tauri/tauri-sidecar.js.map +0 -1
- package/dist/tauri/tauri-single-instance.d.ts.map +0 -1
- package/dist/tauri/tauri-single-instance.js.map +0 -1
- package/dist/tauri/tauri-surfaces.d.ts.map +0 -1
- package/dist/tauri/tauri-surfaces.js.map +0 -1
- package/dist/tauri/tauri-window-lifecycle.d.ts.map +0 -1
- package/dist/tauri/tauri-window-lifecycle.js.map +0 -1
- package/dist/tauri/testing.d.ts.map +0 -1
- package/dist/tauri/testing.js.map +0 -1
- package/dist/tokens.d.ts.map +0 -1
- package/dist/tokens.js.map +0 -1
- package/dist/window-lifecycle.d.ts.map +0 -1
- package/dist/window-lifecycle.js.map +0 -1
- package/dist/windows-registry.d.ts.map +0 -1
- package/dist/windows-registry.js.map +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { InstanceRecord } from './update-policy.js';
|
|
2
|
+
/**
|
|
3
|
+
* Concurrent instances need presence records because no single-instance lock tracks siblings:
|
|
4
|
+
* one updater owner downloads, and only the last live instance may install on quit.
|
|
5
|
+
* PID reuse can make a crashed instance look alive; delaying installation is the safe error.
|
|
6
|
+
* Owner election separately ignores stale heartbeats so such a record cannot block all checks.
|
|
7
|
+
*/
|
|
8
|
+
/** No locking: each process owns one atomic presence record, permitting concurrent instances. */
|
|
9
|
+
export interface InstancePresencePort {
|
|
10
|
+
write(input: {
|
|
11
|
+
record: InstanceRecord;
|
|
12
|
+
}): void;
|
|
13
|
+
readLive(): InstanceRecord[];
|
|
14
|
+
remove(input: {
|
|
15
|
+
pid: number;
|
|
16
|
+
}): void;
|
|
17
|
+
}
|
|
18
|
+
export interface PresenceFilesystemPort {
|
|
19
|
+
mkdirSync(requiredArgs: {
|
|
20
|
+
path: string;
|
|
21
|
+
}, optionalArgs?: {
|
|
22
|
+
recursive?: boolean;
|
|
23
|
+
}): unknown;
|
|
24
|
+
writeFileSync(requiredArgs: {
|
|
25
|
+
path: string;
|
|
26
|
+
data: string;
|
|
27
|
+
}): void;
|
|
28
|
+
renameSync(requiredArgs: {
|
|
29
|
+
oldPath: string;
|
|
30
|
+
newPath: string;
|
|
31
|
+
}): void;
|
|
32
|
+
unlinkSync(requiredArgs: {
|
|
33
|
+
path: string;
|
|
34
|
+
}): void;
|
|
35
|
+
readdirSync(requiredArgs: {
|
|
36
|
+
path: string;
|
|
37
|
+
}): string[];
|
|
38
|
+
readFileSync(requiredArgs: {
|
|
39
|
+
path: string;
|
|
40
|
+
encoding: 'utf8';
|
|
41
|
+
}): string;
|
|
42
|
+
}
|
|
43
|
+
export interface FileInstancePresenceInput {
|
|
44
|
+
directory: string;
|
|
45
|
+
filesystem: PresenceFilesystemPort;
|
|
46
|
+
isAlive: (args: {
|
|
47
|
+
pid: number;
|
|
48
|
+
}) => boolean;
|
|
49
|
+
writerPid: number;
|
|
50
|
+
}
|
|
51
|
+
/** Resolve a caller-named state directory. @complexity O(n) in path length. */
|
|
52
|
+
export declare function presenceDirPath({ userDataDir, directoryName }: {
|
|
53
|
+
userDataDir: string;
|
|
54
|
+
directoryName: string;
|
|
55
|
+
}): string;
|
|
56
|
+
/** Signal-zero liveness probe; EPERM still means alive. @complexity O(1). */
|
|
57
|
+
export declare function isPidAlive({ pid, probe }: {
|
|
58
|
+
pid: number;
|
|
59
|
+
probe: (args: {
|
|
60
|
+
pid: number;
|
|
61
|
+
signal: 0;
|
|
62
|
+
}) => unknown;
|
|
63
|
+
}): boolean;
|
|
64
|
+
/** Atomic filesystem adapter. Writes propagate errors; reads and removals tolerate missing files.
|
|
65
|
+
* @complexity O(1) to construct; O(n) files and probes per read.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createFileInstancePresence({ directory, filesystem, isAlive, writerPid }: FileInstancePresenceInput): InstancePresencePort;
|
|
68
|
+
//# sourceMappingURL=instance-presence.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/** Resolve a caller-named state directory. @complexity O(n) in path length. */
|
|
3
|
+
export function presenceDirPath({ userDataDir, directoryName }) {
|
|
4
|
+
return path.join(userDataDir, directoryName);
|
|
5
|
+
}
|
|
6
|
+
/** Signal-zero liveness probe; EPERM still means alive. @complexity O(1). */
|
|
7
|
+
export function isPidAlive({ pid, probe }) {
|
|
8
|
+
try {
|
|
9
|
+
probe({ pid, signal: 0 });
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
return error?.code === 'EPERM';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Unreadable, partial and malformed records are ignored rather than deleted. @complexity O(n) in text length. */
|
|
17
|
+
function parseRecord(text) {
|
|
18
|
+
try {
|
|
19
|
+
const record = JSON.parse(text);
|
|
20
|
+
if (!record || ![record.pid, record.startedAt, record.heartbeatAt].every(value => typeof value === 'number' && Number.isFinite(value)))
|
|
21
|
+
return null;
|
|
22
|
+
return record;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Atomic filesystem adapter. Writes propagate errors; reads and removals tolerate missing files.
|
|
29
|
+
* @complexity O(1) to construct; O(n) files and probes per read.
|
|
30
|
+
*/
|
|
31
|
+
export function createFileInstancePresence({ directory, filesystem, isAlive, writerPid }) {
|
|
32
|
+
const fileFor = (pid) => path.join(directory, `${pid}.json`);
|
|
33
|
+
function remove({ pid }) {
|
|
34
|
+
try {
|
|
35
|
+
filesystem.unlinkSync({ path: fileFor(pid) });
|
|
36
|
+
}
|
|
37
|
+
catch { /* Removal on exit is best effort. */ }
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
write({ record }) {
|
|
41
|
+
// Publish by rename so a sibling never reads a half-written JSON record.
|
|
42
|
+
filesystem.mkdirSync({ path: directory }, { recursive: true });
|
|
43
|
+
const target = fileFor(record.pid);
|
|
44
|
+
const temporary = `${target}.${writerPid}.tmp`;
|
|
45
|
+
filesystem.writeFileSync({ path: temporary, data: JSON.stringify(record) });
|
|
46
|
+
filesystem.renameSync({ oldPath: temporary, newPath: target });
|
|
47
|
+
},
|
|
48
|
+
remove,
|
|
49
|
+
readLive() {
|
|
50
|
+
let names;
|
|
51
|
+
try {
|
|
52
|
+
names = filesystem.readdirSync({ path: directory }).filter(name => /^\d+\.json$/.test(name));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const live = [];
|
|
58
|
+
for (const name of names) {
|
|
59
|
+
let record;
|
|
60
|
+
try {
|
|
61
|
+
record = parseRecord(filesystem.readFileSync({ path: path.join(directory, name), encoding: 'utf8' }));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Leave unreadable/malformed records alone: a sibling may be writing on a filesystem
|
|
67
|
+
// without atomic rename. Remove confirmed dead PIDs so crashes do not linger.
|
|
68
|
+
if (record === null || name !== `${record.pid}.json`)
|
|
69
|
+
continue;
|
|
70
|
+
if (isAlive({ pid: record.pid }))
|
|
71
|
+
live.push(record);
|
|
72
|
+
else
|
|
73
|
+
remove({ pid: record.pid });
|
|
74
|
+
}
|
|
75
|
+
return live;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=instance-presence.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Pure update eligibility, owner election and last-instance installation decisions. Constants are reference defaults; callers may override timing. */
|
|
2
|
+
declare const UPDATE_CHECK_INTERVAL_MS: number;
|
|
3
|
+
declare const UPDATER_TICK_MS: number;
|
|
4
|
+
declare const FIRST_CHECK_DELAY_MS: number;
|
|
5
|
+
declare const PRESENCE_STALE_MS: number;
|
|
6
|
+
interface UpdaterEnvironment {
|
|
7
|
+
isPackaged: boolean;
|
|
8
|
+
windowsStore: boolean;
|
|
9
|
+
platform: NodeJS.Platform;
|
|
10
|
+
disabledByEnv: boolean;
|
|
11
|
+
/** A headless self-test must never download updates or prompt the operator. */
|
|
12
|
+
selftest: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Evaluate launch eligibility with host-selected platforms and reason wording. @complexity O(1) beyond platform membership. */
|
|
15
|
+
declare function updaterSkipReason({ environment: env, supportedPlatforms, reasons }: {
|
|
16
|
+
environment: UpdaterEnvironment;
|
|
17
|
+
supportedPlatforms: readonly NodeJS.Platform[];
|
|
18
|
+
reasons: {
|
|
19
|
+
notPackaged: string;
|
|
20
|
+
windowsStore: string;
|
|
21
|
+
unsupportedPlatform: (args: {
|
|
22
|
+
platform: NodeJS.Platform;
|
|
23
|
+
}) => string;
|
|
24
|
+
disabled: string;
|
|
25
|
+
selftest: string;
|
|
26
|
+
};
|
|
27
|
+
}): string | null;
|
|
28
|
+
interface InstanceRecord {
|
|
29
|
+
pid: number;
|
|
30
|
+
startedAt: number;
|
|
31
|
+
heartbeatAt: number;
|
|
32
|
+
}
|
|
33
|
+
/** Elect the oldest fresh instance, breaking equal start times by lowest pid. @complexity O(n) instances. */
|
|
34
|
+
declare function electUpdaterOwner({ instances, now, staleMs }: {
|
|
35
|
+
instances: readonly InstanceRecord[];
|
|
36
|
+
now: number;
|
|
37
|
+
staleMs: number;
|
|
38
|
+
}): number | null;
|
|
39
|
+
interface CheckInput {
|
|
40
|
+
isOwner: boolean;
|
|
41
|
+
lastCheckAt: number | null;
|
|
42
|
+
now: number;
|
|
43
|
+
busy: boolean;
|
|
44
|
+
intervalMs: number;
|
|
45
|
+
}
|
|
46
|
+
/** Check only when the owner is idle and the caller-selected interval has elapsed. @complexity O(1). */
|
|
47
|
+
declare function shouldCheckNow(input: CheckInput): boolean;
|
|
48
|
+
type FinalQuitAction = "proceed" | "install-on-quit" | "stage-then-quit" | "install-and-relaunch";
|
|
49
|
+
interface FinalQuitInput {
|
|
50
|
+
platform: NodeJS.Platform;
|
|
51
|
+
updateReady: boolean;
|
|
52
|
+
otherInstances: number;
|
|
53
|
+
restartRequested: boolean;
|
|
54
|
+
installStarted: boolean;
|
|
55
|
+
}
|
|
56
|
+
/** Install only from the last instance after draining; an already-started installation proceeds normally. @complexity O(1). */
|
|
57
|
+
declare function decideFinalQuit(input: FinalQuitInput): FinalQuitAction;
|
|
58
|
+
type RestartClickAction = "restart" | "others-open" | "not-ready";
|
|
59
|
+
/** Restart only for a ready update with no live siblings. @complexity O(1). */
|
|
60
|
+
declare function decideRestartClick({ updateReady, otherInstances }: {
|
|
61
|
+
updateReady: boolean;
|
|
62
|
+
otherInstances: number;
|
|
63
|
+
}): RestartClickAction;
|
|
64
|
+
export { FIRST_CHECK_DELAY_MS, PRESENCE_STALE_MS, UPDATE_CHECK_INTERVAL_MS, UPDATER_TICK_MS, decideFinalQuit, decideRestartClick, electUpdaterOwner, shouldCheckNow, updaterSkipReason, };
|
|
65
|
+
export type { CheckInput, FinalQuitAction, FinalQuitInput, InstanceRecord, RestartClickAction, UpdaterEnvironment };
|
|
66
|
+
//# sourceMappingURL=update-policy.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Pure update eligibility, owner election and last-instance installation decisions. Constants are reference defaults; callers may override timing. */
|
|
2
|
+
const UPDATE_CHECK_INTERVAL_MS = 4 * 60 * 60 * 1000;
|
|
3
|
+
const UPDATER_TICK_MS = 15 * 60 * 1000;
|
|
4
|
+
// Periodically re-elect so a new owner takes over within minutes of the old one quitting.
|
|
5
|
+
const FIRST_CHECK_DELAY_MS = 30 * 1000;
|
|
6
|
+
// Delay the first check so network/update work does not compete with application boot.
|
|
7
|
+
const PRESENCE_STALE_MS = 3 * UPDATER_TICK_MS;
|
|
8
|
+
/** Evaluate launch eligibility with host-selected platforms and reason wording. @complexity O(1) beyond platform membership. */
|
|
9
|
+
function updaterSkipReason({ environment: env, supportedPlatforms, reasons }) {
|
|
10
|
+
// Development has no installed release to update; Store packages are updated by the Store and
|
|
11
|
+
// must not be overwritten by a standalone installer. Published platforms are host policy.
|
|
12
|
+
if (!env.isPackaged)
|
|
13
|
+
return reasons.notPackaged;
|
|
14
|
+
if (env.windowsStore)
|
|
15
|
+
return reasons.windowsStore;
|
|
16
|
+
if (!supportedPlatforms.includes(env.platform))
|
|
17
|
+
return reasons.unsupportedPlatform({ platform: env.platform });
|
|
18
|
+
if (env.disabledByEnv)
|
|
19
|
+
return reasons.disabled;
|
|
20
|
+
if (env.selftest)
|
|
21
|
+
return reasons.selftest;
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/** Elect the oldest fresh instance, breaking equal start times by lowest pid. @complexity O(n) instances. */
|
|
25
|
+
function electUpdaterOwner({ instances, now, staleMs }) {
|
|
26
|
+
// Elect only one downloader so sibling instances cannot race into the shared update cache.
|
|
27
|
+
let owner = null;
|
|
28
|
+
for (const instance of instances) {
|
|
29
|
+
if (now - instance.heartbeatAt > staleMs)
|
|
30
|
+
continue;
|
|
31
|
+
if (owner === null || startedBefore(instance, owner))
|
|
32
|
+
owner = instance;
|
|
33
|
+
}
|
|
34
|
+
return owner === null ? null : owner.pid;
|
|
35
|
+
}
|
|
36
|
+
function startedBefore(a, b) {
|
|
37
|
+
return a.startedAt === b.startedAt ? a.pid < b.pid : a.startedAt < b.startedAt;
|
|
38
|
+
}
|
|
39
|
+
/** Check only when the owner is idle and the caller-selected interval has elapsed. @complexity O(1). */
|
|
40
|
+
function shouldCheckNow(input) {
|
|
41
|
+
if (!input.isOwner || input.busy)
|
|
42
|
+
return false;
|
|
43
|
+
if (input.lastCheckAt === null)
|
|
44
|
+
return true;
|
|
45
|
+
return input.now - input.lastCheckAt >= input.intervalMs;
|
|
46
|
+
}
|
|
47
|
+
/** Install only from the last instance after draining; an already-started installation proceeds normally. @complexity O(1). */
|
|
48
|
+
function decideFinalQuit(input) {
|
|
49
|
+
// Installers replace the shared bundle or terminate sibling processes. Only the last drained
|
|
50
|
+
// instance may install. Do not feed Squirrel at download time: once staged it installs on ANY exit,
|
|
51
|
+
// including an exit while siblings are still open; stage only at this final quit boundary.
|
|
52
|
+
if (input.installStarted || !input.updateReady || input.otherInstances > 0)
|
|
53
|
+
return "proceed";
|
|
54
|
+
if (input.restartRequested)
|
|
55
|
+
return "install-and-relaunch";
|
|
56
|
+
return input.platform === "darwin" ? "stage-then-quit" : "install-on-quit";
|
|
57
|
+
}
|
|
58
|
+
/** Restart only for a ready update with no live siblings. @complexity O(1). */
|
|
59
|
+
function decideRestartClick({ updateReady, otherInstances }) {
|
|
60
|
+
if (!updateReady)
|
|
61
|
+
return "not-ready";
|
|
62
|
+
return otherInstances > 0 ? "others-open" : "restart";
|
|
63
|
+
}
|
|
64
|
+
export { FIRST_CHECK_DELAY_MS, PRESENCE_STALE_MS, UPDATE_CHECK_INTERVAL_MS, UPDATER_TICK_MS, decideFinalQuit, decideRestartClick, electUpdaterOwner, shouldCheckNow, updaterSkipReason, };
|
|
65
|
+
//# sourceMappingURL=update-policy.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Mirrors the Electron options used for browser-style search: omitting matchCase keeps
|
|
2
|
+
* searches case-insensitive. findNext retains Electron's counterintuitive convention:
|
|
3
|
+
* true starts a NEW search session for a fresh query; false steps within the current session. */
|
|
4
|
+
/**
|
|
5
|
+
* Guest webviews can search directly from their renderer; the host window's top-level page
|
|
6
|
+
* needs main-process webContents, so only that surface uses these IPC handlers.
|
|
7
|
+
* Resolve the sender's window for each call rather than retaining a tracked window reference;
|
|
8
|
+
* this permits one global registration after readiness without window-scoped handler state.
|
|
9
|
+
*/
|
|
10
|
+
export interface FindInPageQuery {
|
|
11
|
+
text: string;
|
|
12
|
+
forward: boolean;
|
|
13
|
+
findNext: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Electron reports activeMatchOrdinal as 1-based and matches as the total count, including
|
|
16
|
+
* zero when nothing matched; consumers must preserve those display semantics. */
|
|
17
|
+
export interface FindInPageResult {
|
|
18
|
+
activeMatchOrdinal: number;
|
|
19
|
+
matches: number;
|
|
20
|
+
}
|
|
21
|
+
export interface FindWebContentsPort {
|
|
22
|
+
findInPage(args: {
|
|
23
|
+
text: string;
|
|
24
|
+
}, options?: {
|
|
25
|
+
forward?: boolean;
|
|
26
|
+
findNext?: boolean;
|
|
27
|
+
}): unknown;
|
|
28
|
+
stopFindInPage(args: {
|
|
29
|
+
action: "clearSelection";
|
|
30
|
+
}): void;
|
|
31
|
+
}
|
|
32
|
+
export interface FindWindowLookup<Sender = unknown> {
|
|
33
|
+
fromWebContents(args: {
|
|
34
|
+
sender: Sender;
|
|
35
|
+
}): {
|
|
36
|
+
webContents: FindWebContentsPort;
|
|
37
|
+
} | null;
|
|
38
|
+
}
|
|
39
|
+
export interface FindIpcPort<Sender = unknown> {
|
|
40
|
+
handle(args: {
|
|
41
|
+
channel: string;
|
|
42
|
+
listener: (args: {
|
|
43
|
+
event: {
|
|
44
|
+
sender: Sender;
|
|
45
|
+
};
|
|
46
|
+
query: FindInPageQuery;
|
|
47
|
+
}) => unknown;
|
|
48
|
+
}): unknown;
|
|
49
|
+
removeHandler?(args: {
|
|
50
|
+
channel: string;
|
|
51
|
+
}): unknown;
|
|
52
|
+
}
|
|
53
|
+
/** Register top-level searches against the calling window. Returns an IPC disposer. */
|
|
54
|
+
export declare function registerFindInPageIpc<Sender>({ ipcMain, browserWindow, channels }: {
|
|
55
|
+
ipcMain: FindIpcPort<Sender>;
|
|
56
|
+
browserWindow: FindWindowLookup<Sender>;
|
|
57
|
+
channels: {
|
|
58
|
+
find: string;
|
|
59
|
+
stop: string;
|
|
60
|
+
};
|
|
61
|
+
}): () => void;
|
|
62
|
+
export interface FindResultSource {
|
|
63
|
+
on(args: {
|
|
64
|
+
event: "found-in-page";
|
|
65
|
+
listener: (args: {
|
|
66
|
+
result: FindInPageResult;
|
|
67
|
+
}) => void;
|
|
68
|
+
}): unknown;
|
|
69
|
+
removeListener?(args: {
|
|
70
|
+
event: "found-in-page";
|
|
71
|
+
listener: (args: {
|
|
72
|
+
result: FindInPageResult;
|
|
73
|
+
}) => void;
|
|
74
|
+
}): unknown;
|
|
75
|
+
send(args: {
|
|
76
|
+
channel: string;
|
|
77
|
+
payload: FindInPageResult;
|
|
78
|
+
}): void;
|
|
79
|
+
}
|
|
80
|
+
/** Relay only match counts from a live window, and return an event disposer. */
|
|
81
|
+
export declare function relayFindResults({ window, resultChannel }: {
|
|
82
|
+
window: {
|
|
83
|
+
webContents: FindResultSource;
|
|
84
|
+
isDestroyed(): boolean;
|
|
85
|
+
};
|
|
86
|
+
resultChannel: string;
|
|
87
|
+
}): () => void;
|
|
88
|
+
//# sourceMappingURL=find-in-page-ipc.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Invocation is fire-and-forget: results arrive later through found-in-page, not the return value.
|
|
2
|
+
/** Register top-level searches against the calling window. Returns an IPC disposer. */
|
|
3
|
+
export function registerFindInPageIpc({ ipcMain, browserWindow, channels }) {
|
|
4
|
+
ipcMain.handle({ channel: channels.find, listener: ({ event, query }) => {
|
|
5
|
+
browserWindow.fromWebContents({ sender: event.sender })?.webContents.findInPage({ text: query.text }, { forward: query.forward, findNext: query.findNext });
|
|
6
|
+
} });
|
|
7
|
+
ipcMain.handle({ channel: channels.stop, listener: ({ event }) => {
|
|
8
|
+
browserWindow.fromWebContents({ sender: event.sender })?.webContents.stopFindInPage({ action: "clearSelection" });
|
|
9
|
+
} });
|
|
10
|
+
return () => { ipcMain.removeHandler?.({ channel: channels.find }); ipcMain.removeHandler?.({ channel: channels.stop }); };
|
|
11
|
+
}
|
|
12
|
+
/** Relay only match counts from a live window, and return an event disposer. */
|
|
13
|
+
export function relayFindResults({ window, resultChannel }) {
|
|
14
|
+
const listener = ({ result }) => {
|
|
15
|
+
if (window.isDestroyed())
|
|
16
|
+
return;
|
|
17
|
+
window.webContents.send({ channel: resultChannel, payload: { activeMatchOrdinal: result.activeMatchOrdinal, matches: result.matches } });
|
|
18
|
+
};
|
|
19
|
+
window.webContents.on({ event: "found-in-page", listener });
|
|
20
|
+
return () => { window.webContents.removeListener?.({ event: "found-in-page", listener }); };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=find-in-page-ipc.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A native menu accelerator still fires when focus is in a webview guest, where the host page's
|
|
3
|
+
* DOM key listener cannot see Cmd+F. Only opening the bar needs main's help; once focused,
|
|
4
|
+
* its input handles typing, Enter, Shift+Enter and Escape in the renderer document.
|
|
5
|
+
* Structural ports keep this menu policy independent of a runtime Electron import.
|
|
6
|
+
*/
|
|
7
|
+
interface FindCommandWindow {
|
|
8
|
+
isDestroyed(): boolean;
|
|
9
|
+
webContents?: {
|
|
10
|
+
send(args: {
|
|
11
|
+
channel: string;
|
|
12
|
+
}): void;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
interface FindMenuItem {
|
|
16
|
+
label: string;
|
|
17
|
+
accelerator: string;
|
|
18
|
+
click: (args: {
|
|
19
|
+
window: FindCommandWindow | undefined;
|
|
20
|
+
}) => void;
|
|
21
|
+
}
|
|
22
|
+
interface FindMenu {
|
|
23
|
+
label: string;
|
|
24
|
+
submenu: [FindMenuItem];
|
|
25
|
+
}
|
|
26
|
+
/** Send the caller-configured toggle channel to a live focused window. */
|
|
27
|
+
declare function sendFindToggle({ window, channel }: {
|
|
28
|
+
window: FindCommandWindow | undefined;
|
|
29
|
+
channel: string;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/** Build a Find menu with host-owned labels and channel. */
|
|
32
|
+
declare function findMenu({ channel, labels }: {
|
|
33
|
+
channel: string;
|
|
34
|
+
labels: {
|
|
35
|
+
menu: string;
|
|
36
|
+
item: string;
|
|
37
|
+
};
|
|
38
|
+
}, { accelerator }?: {
|
|
39
|
+
accelerator?: string;
|
|
40
|
+
}): FindMenu;
|
|
41
|
+
export { sendFindToggle, findMenu };
|
|
42
|
+
export type { FindCommandWindow, FindMenu, FindMenuItem };
|
|
43
|
+
//# sourceMappingURL=find-menu.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Send the caller-configured toggle channel to a live focused window. */
|
|
2
|
+
function sendFindToggle({ window, channel }) {
|
|
3
|
+
if (!window || window.isDestroyed() || !window.webContents)
|
|
4
|
+
return false;
|
|
5
|
+
window.webContents.send({ channel });
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
/** Build a Find menu with host-owned labels and channel. */
|
|
9
|
+
function findMenu({ channel, labels }, { accelerator = "CmdOrCtrl+F" } = {}) {
|
|
10
|
+
return {
|
|
11
|
+
label: labels.menu,
|
|
12
|
+
submenu: [
|
|
13
|
+
{
|
|
14
|
+
label: labels.item,
|
|
15
|
+
accelerator,
|
|
16
|
+
click: ({ window }) => void sendFindToggle({ window, channel }),
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export { sendFindToggle, findMenu };
|
|
22
|
+
//# sourceMappingURL=find-menu.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Electron supplies spelling data in context-menu events but shows no browser-style native
|
|
2
|
+
* menu itself. Register for both shell contents and editing webview guests; spellcheck is enabled
|
|
3
|
+
* by Electron's default preferences, while this module supplies the missing popup behavior.
|
|
4
|
+
* Keep decisions separate from registration and inject Menu/webContents so no native runtime is
|
|
5
|
+
* needed to exercise them. The host already owns Menu, so a module-level import adds no capability. */
|
|
6
|
+
export interface MenuItemConstructorOptions {
|
|
7
|
+
label?: string;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
type?: "separator";
|
|
10
|
+
click?: () => void;
|
|
11
|
+
}
|
|
12
|
+
export interface SpellCheckLabels {
|
|
13
|
+
noSuggestions: string;
|
|
14
|
+
addToDictionary: string;
|
|
15
|
+
cut: string;
|
|
16
|
+
copy: string;
|
|
17
|
+
paste: string;
|
|
18
|
+
selectAll: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SpellCheckContextMenuParams {
|
|
21
|
+
isEditable: boolean;
|
|
22
|
+
misspelledWord: string;
|
|
23
|
+
dictionarySuggestions: string[];
|
|
24
|
+
editFlags: {
|
|
25
|
+
canCut: boolean;
|
|
26
|
+
canCopy: boolean;
|
|
27
|
+
canPaste: boolean;
|
|
28
|
+
canSelectAll: boolean;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Build spelling suggestions followed by enabled edit commands. */
|
|
32
|
+
export declare function buildSpellCheckMenuTemplate({ params, handlers, labels }: {
|
|
33
|
+
params: SpellCheckContextMenuParams;
|
|
34
|
+
handlers: SpellCheckMenuHandlers;
|
|
35
|
+
labels: SpellCheckLabels;
|
|
36
|
+
}, { maxSuggestions }?: {
|
|
37
|
+
maxSuggestions?: number;
|
|
38
|
+
}): MenuItemConstructorOptions[];
|
|
39
|
+
export interface SpellCheckMenuHandlers {
|
|
40
|
+
replace: (args: {
|
|
41
|
+
word: string;
|
|
42
|
+
}) => void;
|
|
43
|
+
addToDictionary: (args: {
|
|
44
|
+
word: string;
|
|
45
|
+
}) => void;
|
|
46
|
+
cut: () => void;
|
|
47
|
+
copy: () => void;
|
|
48
|
+
paste: () => void;
|
|
49
|
+
selectAll: () => void;
|
|
50
|
+
}
|
|
51
|
+
export interface SpellCheckWebContents {
|
|
52
|
+
on(args: {
|
|
53
|
+
event: "context-menu";
|
|
54
|
+
listener: (args: {
|
|
55
|
+
params: SpellCheckContextMenuParams;
|
|
56
|
+
}) => void;
|
|
57
|
+
}): unknown;
|
|
58
|
+
removeListener?(args: {
|
|
59
|
+
event: "context-menu";
|
|
60
|
+
listener: (args: {
|
|
61
|
+
params: SpellCheckContextMenuParams;
|
|
62
|
+
}) => void;
|
|
63
|
+
}): unknown;
|
|
64
|
+
replaceMisspelling(args: {
|
|
65
|
+
text: string;
|
|
66
|
+
}): void;
|
|
67
|
+
cut(): void;
|
|
68
|
+
copy(): void;
|
|
69
|
+
paste(): void;
|
|
70
|
+
selectAll(): void;
|
|
71
|
+
session: {
|
|
72
|
+
addWordToSpellCheckerDictionary(args: {
|
|
73
|
+
word: string;
|
|
74
|
+
}): void;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface MenuBuilder {
|
|
78
|
+
buildFromTemplate(args: {
|
|
79
|
+
template: MenuItemConstructorOptions[];
|
|
80
|
+
}): {
|
|
81
|
+
popup(): void;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Register native spelling/edit actions on one content session. Returns a disposer. */
|
|
85
|
+
export declare function registerSpellCheckContextMenu({ webContents, menuBuilder, labels }: {
|
|
86
|
+
webContents: SpellCheckWebContents;
|
|
87
|
+
menuBuilder: MenuBuilder;
|
|
88
|
+
labels: SpellCheckLabels;
|
|
89
|
+
}, options?: {
|
|
90
|
+
maxSuggestions?: number;
|
|
91
|
+
}): () => void;
|
|
92
|
+
//# sourceMappingURL=spellcheck-menu.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Five matches the browser cap: further alternatives mostly add noise to a small context menu.
|
|
2
|
+
const MAX_SUGGESTIONS = 5;
|
|
3
|
+
/** Build spelling suggestions followed by enabled edit commands. */
|
|
4
|
+
export function buildSpellCheckMenuTemplate({ params, handlers, labels }, { maxSuggestions = MAX_SUGGESTIONS } = {}) {
|
|
5
|
+
const spelling = spellingItems(params, handlers, labels, maxSuggestions);
|
|
6
|
+
if (!params.isEditable)
|
|
7
|
+
return spelling;
|
|
8
|
+
const separator = spelling.length > 0 ? [{ type: "separator" }] : [];
|
|
9
|
+
return [...spelling, ...separator, ...editItems(params, handlers, labels)];
|
|
10
|
+
}
|
|
11
|
+
function spellingItems(params, handlers, labels, maxSuggestions) {
|
|
12
|
+
if (params.misspelledWord.length === 0)
|
|
13
|
+
return [];
|
|
14
|
+
const suggestions = params.dictionarySuggestions.slice(0, maxSuggestions);
|
|
15
|
+
const suggestionItems = suggestions.length === 0
|
|
16
|
+
? [{ label: labels.noSuggestions, enabled: false }]
|
|
17
|
+
: suggestions.map((suggestion) => ({ label: suggestion, click: () => handlers.replace({ word: suggestion }) }));
|
|
18
|
+
return [
|
|
19
|
+
...suggestionItems,
|
|
20
|
+
{ type: "separator" },
|
|
21
|
+
{ label: labels.addToDictionary, click: () => handlers.addToDictionary({ word: params.misspelledWord }) },
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
function editItems(params, handlers, labels) {
|
|
25
|
+
return [
|
|
26
|
+
{ label: labels.cut, enabled: params.editFlags.canCut, click: () => handlers.cut() },
|
|
27
|
+
{ label: labels.copy, enabled: params.editFlags.canCopy, click: () => handlers.copy() },
|
|
28
|
+
{ label: labels.paste, enabled: params.editFlags.canPaste, click: () => handlers.paste() },
|
|
29
|
+
{ type: "separator" },
|
|
30
|
+
{ label: labels.selectAll, enabled: params.editFlags.canSelectAll, click: () => handlers.selectAll() },
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
/** Register native spelling/edit actions on one content session. Returns a disposer. */
|
|
34
|
+
export function registerSpellCheckContextMenu({ webContents, menuBuilder, labels }, options = {}) {
|
|
35
|
+
const listener = ({ params }) => {
|
|
36
|
+
const template = buildSpellCheckMenuTemplate({ params, labels, handlers: {
|
|
37
|
+
replace: ({ word }) => webContents.replaceMisspelling({ text: word }),
|
|
38
|
+
addToDictionary: ({ word }) => webContents.session.addWordToSpellCheckerDictionary({ word }),
|
|
39
|
+
cut: () => webContents.cut(),
|
|
40
|
+
copy: () => webContents.copy(),
|
|
41
|
+
paste: () => webContents.paste(),
|
|
42
|
+
selectAll: () => webContents.selectAll(),
|
|
43
|
+
} }, options);
|
|
44
|
+
// A click with neither a misspelling nor editable commands should show no popup, not an empty menu.
|
|
45
|
+
if (template.length === 0)
|
|
46
|
+
return;
|
|
47
|
+
menuBuilder.buildFromTemplate({ template }).popup();
|
|
48
|
+
};
|
|
49
|
+
webContents.on({ event: "context-menu", listener });
|
|
50
|
+
return () => { webContents.removeListener?.({ event: "context-menu", listener }); };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=spellcheck-menu.js.map
|