@jini-ai/desktop-host 0.1.2 → 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 +71 -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,138 @@
|
|
|
1
|
+
function isNativeContents(contents) {
|
|
2
|
+
// Electron's EventEmitter takes event + listener; the old registration object takes one arg.
|
|
3
|
+
return contents.on.length !== 1;
|
|
4
|
+
}
|
|
5
|
+
/** A callable carrying its own handler supports the popup-only legacy surface as well as Electron.
|
|
6
|
+
* No signature cast or Electron dependency is needed; both paths receive the identical callback.
|
|
7
|
+
*/
|
|
8
|
+
function registerWindowOpen(contents, handler) {
|
|
9
|
+
contents.setWindowOpenHandler(Object.assign(handler, { handler }));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Opaque origins such as file:, data: and javascript: all serialize as "null".
|
|
13
|
+
* That shared string cannot prove two pages have the same origin.
|
|
14
|
+
*/
|
|
15
|
+
function parseOrigin(raw) {
|
|
16
|
+
let origin;
|
|
17
|
+
try {
|
|
18
|
+
origin = new URL(raw).origin;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return origin === "null" ? null : origin;
|
|
24
|
+
}
|
|
25
|
+
/** Compare parsed, non-opaque origins; malformed URLs fail closed. @complexity O(n) in URL lengths. */
|
|
26
|
+
function isSameOrigin({ candidate, reference }) {
|
|
27
|
+
const origin = parseOrigin(candidate);
|
|
28
|
+
return origin !== null && origin === parseOrigin(reference);
|
|
29
|
+
}
|
|
30
|
+
/** Admit only parseable HTTP and HTTPS browser URLs. @complexity O(n) in URL length. */
|
|
31
|
+
function isExternalBrowserUrl({ raw }) {
|
|
32
|
+
let protocol;
|
|
33
|
+
try {
|
|
34
|
+
protocol = new URL(raw).protocol;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return protocol === "http:" || protocol === "https:";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Pin checks to the window creation origin, never its current location. Server-side 30x
|
|
43
|
+
* redirects do not emit will-navigate, so will-redirect closes that bypass too. Only main
|
|
44
|
+
* frames inherit the window preload; a cross-origin subframe is outside this boundary.
|
|
45
|
+
*/
|
|
46
|
+
/** Register popup, navigation and main-frame redirect boundaries against the initial app origin. @complexity O(1) registration; O(n) per URL. */
|
|
47
|
+
function installAppWindowNavigationPolicy({ contents, ...options }) {
|
|
48
|
+
installNavigationBoundary(contents, (url) => isSameOrigin({ candidate: url, reference: options.appOrigin }), options.openExternal);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A renderer page CSP belongs to that document; replacing it with another local or remote
|
|
52
|
+
* page does not carry the CSP along, but can retain the privileged preload. file: origins
|
|
53
|
+
* are opaque, so this boundary compares the complete renderer URL rather than its origin.
|
|
54
|
+
*/
|
|
55
|
+
/** Allow only the renderer file itself, ignoring query and fragment. Foreign web URLs open externally. @complexity O(1) registration; O(n) per URL. */
|
|
56
|
+
function installRendererNavigationPolicy({ contents, ...options }) {
|
|
57
|
+
const renderer = withoutQueryOrHash(options.rendererFileUrl);
|
|
58
|
+
installNavigationBoundary(contents, (url) => renderer !== null && withoutQueryOrHash(url) === renderer, options.openExternal);
|
|
59
|
+
}
|
|
60
|
+
function installNavigationBoundary(contents, isInApp, openExternal) {
|
|
61
|
+
const handOff = (url) => {
|
|
62
|
+
if (isExternalBrowserUrl({ raw: url }))
|
|
63
|
+
openExternal({ url });
|
|
64
|
+
};
|
|
65
|
+
registerWindowOpen(contents, ({ url }) => {
|
|
66
|
+
if (isInApp(url))
|
|
67
|
+
return { action: "allow" };
|
|
68
|
+
handOff(url);
|
|
69
|
+
return { action: "deny" };
|
|
70
|
+
});
|
|
71
|
+
const onNavigate = (event, url) => {
|
|
72
|
+
if (isInApp(url))
|
|
73
|
+
return;
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
handOff(url);
|
|
76
|
+
};
|
|
77
|
+
const onRedirect = (details) => {
|
|
78
|
+
if (!details.isMainFrame || isInApp(details.url))
|
|
79
|
+
return;
|
|
80
|
+
details.preventDefault();
|
|
81
|
+
handOff(details.url);
|
|
82
|
+
};
|
|
83
|
+
if (isNativeContents(contents)) {
|
|
84
|
+
contents.on("will-navigate", onNavigate);
|
|
85
|
+
contents.on("will-redirect", onRedirect);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
contents.on({ event: "will-navigate", listener: ({ event, url }) => onNavigate(event, url) });
|
|
89
|
+
contents.on({ event: "will-redirect", listener: onRedirect });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* There is no second guest in which to open a popup. Forwarding only supervised URLs
|
|
94
|
+
* previously swallowed external sign-in links, so other HTTP(S) links also go to the OS.
|
|
95
|
+
* A thrown handoff can blank the guest window; failure must still return a denial.
|
|
96
|
+
*/
|
|
97
|
+
/** Deny every in-guest popup; forward permitted browser links through the supplied host port. Failed handoffs still deny. @complexity O(1) registration. */
|
|
98
|
+
function installGuestWindowOpenPolicy({ contents, ...options }) {
|
|
99
|
+
registerWindowOpen(contents, ({ url }) => {
|
|
100
|
+
if (options.isSupervisedGuestUrl({ url }) || isExternalBrowserUrl({ raw: url })) {
|
|
101
|
+
try {
|
|
102
|
+
options.openExternal({ url });
|
|
103
|
+
// A browser handoff failure must not escape the guest callback and blank its window.
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { action: "deny" };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function withoutQueryOrHash(raw) {
|
|
112
|
+
let url;
|
|
113
|
+
try {
|
|
114
|
+
url = new URL(raw);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
url.search = "";
|
|
120
|
+
url.hash = "";
|
|
121
|
+
return url.href;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* This is the sender boundary for privileged host IPC. Exact renderer matching keeps
|
|
125
|
+
* opaque file origins from trusting unrelated local pages; attach URLs use parsed origins.
|
|
126
|
+
* Malformed URL comparisons return false instead of throwing from the sender check.
|
|
127
|
+
*/
|
|
128
|
+
/** Trust supervised pages, the optional attach origin or the exact renderer file for host IPC. @complexity O(n) in URL length. */
|
|
129
|
+
function isShellPageUrl({ raw, pages }, { attachUrl } = {}) {
|
|
130
|
+
if (pages.isSupervisedSite({ url: raw }))
|
|
131
|
+
return true;
|
|
132
|
+
if (attachUrl && isSameOrigin({ candidate: raw, reference: attachUrl }))
|
|
133
|
+
return true;
|
|
134
|
+
const page = withoutQueryOrHash(raw);
|
|
135
|
+
return page !== null && page === withoutQueryOrHash(pages.rendererFileUrl);
|
|
136
|
+
}
|
|
137
|
+
export { isSameOrigin, isExternalBrowserUrl, installAppWindowNavigationPolicy, installGuestWindowOpenPolicy, installRendererNavigationPolicy, isShellPageUrl, };
|
|
138
|
+
//# sourceMappingURL=window-navigation-policy.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/** Fake Electron surfaces for tests — never a real `electron` import (see `electron-surfaces.ts`). */
|
|
2
2
|
import type { ElectronAppLike, ElectronBrowserWindowFactory, ElectronBrowserWindowLike, ElectronDialogLike, ElectronOpenDialogResult, ElectronProtocolLike, ElectronShellLike } from './electron-surfaces.js';
|
|
3
|
-
export declare function createFakeElectronApp(options?: {
|
|
3
|
+
export declare function createFakeElectronApp(_requiredArgs: Record<string, never>, options?: {
|
|
4
4
|
lockGranted?: boolean;
|
|
5
5
|
recentDocuments?: string[];
|
|
6
6
|
}): ElectronAppLike & {
|
|
7
7
|
quitCalled: boolean;
|
|
8
8
|
emitSecondInstance(): void;
|
|
9
9
|
};
|
|
10
|
-
export declare function createFakeElectronDialog(script?: {
|
|
10
|
+
export declare function createFakeElectronDialog(_requiredArgs: Record<string, never>, script?: {
|
|
11
11
|
openDialogResult?: ElectronOpenDialogResult;
|
|
12
12
|
}): ElectronDialogLike & {
|
|
13
13
|
lastShowOpenDialogOptions: unknown;
|
|
@@ -21,14 +21,16 @@ export interface FakeWindowScript {
|
|
|
21
21
|
pdfResult?: Buffer;
|
|
22
22
|
pngResult?: Buffer;
|
|
23
23
|
}
|
|
24
|
-
export declare function createFakeBrowserWindowFactory(script?: FakeWindowScript): {
|
|
24
|
+
export declare function createFakeBrowserWindowFactory(_requiredArgs: Record<string, never>, script?: FakeWindowScript): {
|
|
25
25
|
factory: ElectronBrowserWindowFactory;
|
|
26
26
|
windows: ElectronBrowserWindowLike[];
|
|
27
27
|
};
|
|
28
|
-
export declare function createFakeElectronProtocol(): ElectronProtocolLike & {
|
|
29
|
-
handlers: Map<string, (
|
|
28
|
+
export declare function createFakeElectronProtocol(_requiredArgs: Record<string, never>): ElectronProtocolLike & {
|
|
29
|
+
handlers: Map<string, (args: {
|
|
30
|
+
request: Request;
|
|
31
|
+
}) => Promise<Response>>;
|
|
30
32
|
};
|
|
31
|
-
export declare function createFakeElectronShell(options?: {
|
|
33
|
+
export declare function createFakeElectronShell(_requiredArgs: Record<string, never>, options?: {
|
|
32
34
|
openPathError?: string;
|
|
33
35
|
}): ElectronShellLike & {
|
|
34
36
|
openedExternalUrls: string[];
|
package/dist/electron/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function createFakeElectronApp(options = {}) {
|
|
1
|
+
export function createFakeElectronApp(_requiredArgs, options = {}) {
|
|
2
2
|
let secondInstanceListener = null;
|
|
3
3
|
const recentDocuments = options.recentDocuments ?? [];
|
|
4
4
|
const app = {
|
|
@@ -7,7 +7,7 @@ export function createFakeElectronApp(options = {}) {
|
|
|
7
7
|
quit() {
|
|
8
8
|
app.quitCalled = true;
|
|
9
9
|
},
|
|
10
|
-
on(
|
|
10
|
+
on({ listener }) {
|
|
11
11
|
secondInstanceListener = listener;
|
|
12
12
|
},
|
|
13
13
|
emitSecondInstance() {
|
|
@@ -16,25 +16,25 @@ export function createFakeElectronApp(options = {}) {
|
|
|
16
16
|
getRecentDocuments() {
|
|
17
17
|
return recentDocuments;
|
|
18
18
|
},
|
|
19
|
-
addRecentDocument(path) {
|
|
19
|
+
addRecentDocument({ path }) {
|
|
20
20
|
recentDocuments.unshift(path);
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
return app;
|
|
24
24
|
}
|
|
25
|
-
export function createFakeElectronDialog(script = {}) {
|
|
25
|
+
export function createFakeElectronDialog(_requiredArgs, script = {}) {
|
|
26
26
|
const fake = {
|
|
27
27
|
lastShowOpenDialogOptions: undefined,
|
|
28
|
-
async showOpenDialog(options) {
|
|
28
|
+
async showOpenDialog(_requiredArgs, options = {}) {
|
|
29
29
|
fake.lastShowOpenDialogOptions = options;
|
|
30
30
|
return script.openDialogResult ?? { canceled: true, filePaths: [] };
|
|
31
31
|
},
|
|
32
32
|
};
|
|
33
33
|
return fake;
|
|
34
34
|
}
|
|
35
|
-
export function createFakeBrowserWindowFactory(script = {}) {
|
|
35
|
+
export function createFakeBrowserWindowFactory(_requiredArgs, script = {}) {
|
|
36
36
|
const windows = [];
|
|
37
|
-
const factory = (_options) => {
|
|
37
|
+
const factory = (_requiredArgs, _options = {}) => {
|
|
38
38
|
let destroyed = false;
|
|
39
39
|
let didFinishLoad = null;
|
|
40
40
|
let didFailLoad = null;
|
|
@@ -44,19 +44,19 @@ export function createFakeBrowserWindowFactory(script = {}) {
|
|
|
44
44
|
const webContents = {
|
|
45
45
|
session: {
|
|
46
46
|
webRequest: {
|
|
47
|
-
onBeforeRequest(listener) {
|
|
47
|
+
onBeforeRequest({ listener }) {
|
|
48
48
|
beforeRequest = listener;
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
52
|
async loadURL() { },
|
|
53
|
-
once(event, listener) {
|
|
53
|
+
once({ event, listener }) {
|
|
54
54
|
if (event === 'did-finish-load')
|
|
55
55
|
didFinishLoad = listener;
|
|
56
56
|
if (event === 'did-fail-load')
|
|
57
57
|
didFailLoad = listener;
|
|
58
58
|
},
|
|
59
|
-
on(event, listener) {
|
|
59
|
+
on({ event, listener }) {
|
|
60
60
|
if (event === 'will-navigate')
|
|
61
61
|
willNavigate = listener;
|
|
62
62
|
},
|
|
@@ -70,12 +70,12 @@ export function createFakeBrowserWindowFactory(script = {}) {
|
|
|
70
70
|
};
|
|
71
71
|
const win = {
|
|
72
72
|
webContents,
|
|
73
|
-
async loadURL(
|
|
73
|
+
async loadURL(_args) {
|
|
74
74
|
if (script.hang === true)
|
|
75
75
|
return;
|
|
76
76
|
queueMicrotask(() => {
|
|
77
77
|
if (script.failLoad != null)
|
|
78
|
-
didFailLoad?.(null, script.failLoad.errorCode, script.failLoad.errorDescription);
|
|
78
|
+
didFailLoad?.({ event: null, errorCode: script.failLoad.errorCode, errorDescription: script.failLoad.errorDescription });
|
|
79
79
|
else
|
|
80
80
|
didFinishLoad?.();
|
|
81
81
|
});
|
|
@@ -94,20 +94,20 @@ export function createFakeBrowserWindowFactory(script = {}) {
|
|
|
94
94
|
isDestroyed() {
|
|
95
95
|
return destroyed;
|
|
96
96
|
},
|
|
97
|
-
on(event, listener) {
|
|
97
|
+
on({ event, listener }) {
|
|
98
98
|
if (event === 'closed')
|
|
99
99
|
closedListeners.push(listener);
|
|
100
100
|
},
|
|
101
101
|
triggerBeforeRequest(url) {
|
|
102
102
|
let result = { cancel: false };
|
|
103
|
-
beforeRequest?.({ url }, (response) => {
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
beforeRequest?.({ details: { url }, callback: (response) => {
|
|
104
|
+
result = response;
|
|
105
|
+
} });
|
|
106
106
|
return result;
|
|
107
107
|
},
|
|
108
108
|
triggerWillNavigate(url) {
|
|
109
109
|
let prevented = false;
|
|
110
|
-
willNavigate?.({ preventDefault: () => (prevented = true) }, url);
|
|
110
|
+
willNavigate?.({ event: { preventDefault: () => (prevented = true) }, url });
|
|
111
111
|
return prevented;
|
|
112
112
|
},
|
|
113
113
|
};
|
|
@@ -116,26 +116,26 @@ export function createFakeBrowserWindowFactory(script = {}) {
|
|
|
116
116
|
};
|
|
117
117
|
return { factory, windows };
|
|
118
118
|
}
|
|
119
|
-
export function createFakeElectronProtocol() {
|
|
119
|
+
export function createFakeElectronProtocol(_requiredArgs) {
|
|
120
120
|
const handlers = new Map();
|
|
121
121
|
return {
|
|
122
122
|
handlers,
|
|
123
123
|
registerSchemesAsPrivileged() { },
|
|
124
|
-
handle(scheme, handler) {
|
|
124
|
+
handle({ scheme, handler }) {
|
|
125
125
|
handlers.set(scheme, handler);
|
|
126
126
|
},
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
export function createFakeElectronShell(options = {}) {
|
|
129
|
+
export function createFakeElectronShell(_requiredArgs, options = {}) {
|
|
130
130
|
const openedExternalUrls = [];
|
|
131
131
|
const openedPaths = [];
|
|
132
132
|
return {
|
|
133
133
|
openedExternalUrls,
|
|
134
134
|
openedPaths,
|
|
135
|
-
async openExternal(url) {
|
|
135
|
+
async openExternal({ url }) {
|
|
136
136
|
openedExternalUrls.push(url);
|
|
137
137
|
},
|
|
138
|
-
async openPath(path) {
|
|
138
|
+
async openPath({ path }) {
|
|
139
139
|
openedPaths.push(path);
|
|
140
140
|
return options.openPathError ?? '';
|
|
141
141
|
},
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Clock } from '@jini-ai/core/primitives';
|
|
2
|
+
import type { InstancePresencePort } from './instance-presence.js';
|
|
3
|
+
/** Native structural AppUpdater surface; framework methods keep their positional ABI.
|
|
4
|
+
* Listener payloads retain their event-specific native types.
|
|
5
|
+
*/
|
|
6
|
+
export interface ElectronUpdater {
|
|
7
|
+
autoDownload: boolean;
|
|
8
|
+
autoInstallOnAppQuit: boolean;
|
|
9
|
+
autoRunAppAfterInstall: boolean;
|
|
10
|
+
checkForUpdates(): Promise<{
|
|
11
|
+
downloadPromise?: Promise<unknown> | null;
|
|
12
|
+
} | null>;
|
|
13
|
+
quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
|
|
14
|
+
on(event: 'update-downloaded', listener: (info: {
|
|
15
|
+
version: string;
|
|
16
|
+
}) => void): unknown;
|
|
17
|
+
on(event: 'error', listener: (error: Error) => void): unknown;
|
|
18
|
+
}
|
|
19
|
+
/** Existing object-shaped updater ABI retained until hosts delete their compatibility glue. */
|
|
20
|
+
export interface LegacyUpdaterLike {
|
|
21
|
+
autoDownload: boolean;
|
|
22
|
+
autoInstallOnAppQuit: boolean;
|
|
23
|
+
autoRunAppAfterInstall: boolean;
|
|
24
|
+
checkForUpdates(): Promise<{
|
|
25
|
+
downloadPromise?: Promise<unknown> | null;
|
|
26
|
+
} | null>;
|
|
27
|
+
quitAndInstall(requiredArgs: Record<string, never>, optionalArgs?: {
|
|
28
|
+
isSilent?: boolean;
|
|
29
|
+
isForceRunAfter?: boolean;
|
|
30
|
+
}): void;
|
|
31
|
+
on(required: {
|
|
32
|
+
event: 'update-downloaded';
|
|
33
|
+
listener: (args: {
|
|
34
|
+
payload: {
|
|
35
|
+
version: string;
|
|
36
|
+
};
|
|
37
|
+
}) => void;
|
|
38
|
+
}): unknown;
|
|
39
|
+
on(required: {
|
|
40
|
+
event: 'error';
|
|
41
|
+
listener: (args: {
|
|
42
|
+
payload: unknown;
|
|
43
|
+
}) => void;
|
|
44
|
+
}): unknown;
|
|
45
|
+
}
|
|
46
|
+
export type UpdaterLike = ElectronUpdater | LegacyUpdaterLike;
|
|
47
|
+
export interface UpdateTimer {
|
|
48
|
+
unref?: () => void;
|
|
49
|
+
}
|
|
50
|
+
export interface UpdateTimersPort {
|
|
51
|
+
setTimeout({ callback, ms }: {
|
|
52
|
+
callback: () => void;
|
|
53
|
+
ms: number;
|
|
54
|
+
}): UpdateTimer;
|
|
55
|
+
setInterval({ callback, ms }: {
|
|
56
|
+
callback: () => void;
|
|
57
|
+
ms: number;
|
|
58
|
+
}): UpdateTimer;
|
|
59
|
+
clear({ timer }: {
|
|
60
|
+
timer: UpdateTimer;
|
|
61
|
+
}): void;
|
|
62
|
+
}
|
|
63
|
+
export interface UpdateTiming {
|
|
64
|
+
firstCheckDelayMs: number;
|
|
65
|
+
tickMs: number;
|
|
66
|
+
checkIntervalMs: number;
|
|
67
|
+
staleMs: number;
|
|
68
|
+
stageTimeoutMs: number;
|
|
69
|
+
}
|
|
70
|
+
/** Host-replaceable copy formatters let the host own its wording and branding. */
|
|
71
|
+
export interface UpdateMessages {
|
|
72
|
+
downloaded: (args: {
|
|
73
|
+
version: string;
|
|
74
|
+
}) => string;
|
|
75
|
+
error: (args: {
|
|
76
|
+
message: string;
|
|
77
|
+
}) => string;
|
|
78
|
+
promptFailed: (args: {
|
|
79
|
+
message: string;
|
|
80
|
+
}) => string;
|
|
81
|
+
checkFailed: (args: {
|
|
82
|
+
message: string;
|
|
83
|
+
}) => string;
|
|
84
|
+
presenceWriteFailed: (args: {
|
|
85
|
+
message: string;
|
|
86
|
+
}) => string;
|
|
87
|
+
}
|
|
88
|
+
export interface AutoUpdateControllerEffects {
|
|
89
|
+
updater: UpdaterLike;
|
|
90
|
+
platform: NodeJS.Platform;
|
|
91
|
+
pid: number;
|
|
92
|
+
presence: InstancePresencePort;
|
|
93
|
+
/** Compatibility placement; new hosts supply these overrides in parameter two. */
|
|
94
|
+
timers?: UpdateTimersPort;
|
|
95
|
+
timing?: UpdateTiming;
|
|
96
|
+
messages?: UpdateMessages;
|
|
97
|
+
promptUpdateReady: (args: {
|
|
98
|
+
version: string;
|
|
99
|
+
}) => Promise<boolean>;
|
|
100
|
+
explainOthersOpen: (args: {
|
|
101
|
+
count: number;
|
|
102
|
+
}) => void;
|
|
103
|
+
quit: () => void;
|
|
104
|
+
log: (args: {
|
|
105
|
+
message: string;
|
|
106
|
+
}) => void;
|
|
107
|
+
}
|
|
108
|
+
/** New hosts share a core Clock. The old callback is accepted until compatibility glue is removed. */
|
|
109
|
+
export type AutoUpdateControllerDeps = AutoUpdateControllerEffects & ({
|
|
110
|
+
clock: Clock;
|
|
111
|
+
now?: never;
|
|
112
|
+
} | {
|
|
113
|
+
now: () => number;
|
|
114
|
+
clock?: never;
|
|
115
|
+
});
|
|
116
|
+
export interface AutoUpdateControllerOptions {
|
|
117
|
+
timers?: UpdateTimersPort;
|
|
118
|
+
timing?: Partial<UpdateTiming>;
|
|
119
|
+
messages?: UpdateMessages;
|
|
120
|
+
}
|
|
121
|
+
/** Default update copy is replaceable as a whole by the host. */
|
|
122
|
+
export declare const defaultUpdateMessages: UpdateMessages;
|
|
123
|
+
/** Reference timings preserve boot/network contention and missed-heartbeat tolerance. */
|
|
124
|
+
export declare const defaultUpdateTiming: Readonly<UpdateTiming>;
|
|
125
|
+
/** Node scheduling adapter owns its native handles; clear never casts a host-supplied timer. */
|
|
126
|
+
export declare function createNodeUpdateTimers(): UpdateTimersPort;
|
|
127
|
+
/** Forward native methods and mutable configuration without importing electron-updater.
|
|
128
|
+
* Both native event listener overloads retain their payload types and the updater receiver.
|
|
129
|
+
*/
|
|
130
|
+
export declare function createElectronUpdaterAdapter({ updater }: {
|
|
131
|
+
updater: ElectronUpdater;
|
|
132
|
+
}): ElectronUpdater;
|
|
133
|
+
export interface AutoUpdateController {
|
|
134
|
+
start(): void;
|
|
135
|
+
tick(): void;
|
|
136
|
+
requestRestart(): void;
|
|
137
|
+
/** True holds the final quit while an installation takes over. Call after the shutdown drain. */
|
|
138
|
+
beforeFinalQuit(): boolean;
|
|
139
|
+
willQuit(): void;
|
|
140
|
+
}
|
|
141
|
+
/** Coordinates quiet downloads and last-instance installs through injected effects.
|
|
142
|
+
* No single-instance lock is acquired. Construction registers updater listeners but starts no timers.
|
|
143
|
+
* @complexity O(1) construction; O(n) live records per tick or final quit.
|
|
144
|
+
*/
|
|
145
|
+
export declare function createAutoUpdateController(deps: AutoUpdateControllerDeps, options?: AutoUpdateControllerOptions): AutoUpdateController;
|
|
146
|
+
//# sourceMappingURL=auto-update-controller.d.ts.map
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { decideFinalQuit, decideRestartClick, electUpdaterOwner, shouldCheckNow, FIRST_CHECK_DELAY_MS, UPDATER_TICK_MS, UPDATE_CHECK_INTERVAL_MS, PRESENCE_STALE_MS } from './update-policy.js';
|
|
2
|
+
/** Default update copy is replaceable as a whole by the host. */
|
|
3
|
+
export const defaultUpdateMessages = {
|
|
4
|
+
downloaded: ({ version }) => `auto-update: ${version} downloaded`,
|
|
5
|
+
error: ({ message }) => `auto-update: ${message}`,
|
|
6
|
+
promptFailed: ({ message }) => `auto-update: prompt failed: ${message}`,
|
|
7
|
+
checkFailed: ({ message }) => `auto-update: check failed: ${message}`,
|
|
8
|
+
presenceWriteFailed: ({ message }) => `auto-update: presence write failed: ${message}`,
|
|
9
|
+
};
|
|
10
|
+
/** Reference timings preserve boot/network contention and missed-heartbeat tolerance. */
|
|
11
|
+
export const defaultUpdateTiming = {
|
|
12
|
+
firstCheckDelayMs: FIRST_CHECK_DELAY_MS,
|
|
13
|
+
tickMs: UPDATER_TICK_MS,
|
|
14
|
+
checkIntervalMs: UPDATE_CHECK_INTERVAL_MS,
|
|
15
|
+
staleMs: PRESENCE_STALE_MS,
|
|
16
|
+
// Bound the macOS wait for Squirrel's handoff; quit without the update after two minutes.
|
|
17
|
+
stageTimeoutMs: 2 * 60 * 1000,
|
|
18
|
+
};
|
|
19
|
+
/** Node scheduling adapter owns its native handles; clear never casts a host-supplied timer. */
|
|
20
|
+
export function createNodeUpdateTimers() {
|
|
21
|
+
const handles = new Map();
|
|
22
|
+
const remember = (handle) => {
|
|
23
|
+
handles.set(handle, handle);
|
|
24
|
+
return handle;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
setTimeout: ({ callback, ms }) => remember(setTimeout(callback, ms)),
|
|
28
|
+
setInterval: ({ callback, ms }) => remember(setInterval(callback, ms)),
|
|
29
|
+
clear({ timer }) {
|
|
30
|
+
const handle = handles.get(timer);
|
|
31
|
+
if (handle === undefined)
|
|
32
|
+
return;
|
|
33
|
+
clearTimeout(handle);
|
|
34
|
+
handles.delete(timer);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Forward native methods and mutable configuration without importing electron-updater.
|
|
39
|
+
* Both native event listener overloads retain their payload types and the updater receiver.
|
|
40
|
+
*/
|
|
41
|
+
export function createElectronUpdaterAdapter({ updater }) {
|
|
42
|
+
return {
|
|
43
|
+
get autoDownload() { return updater.autoDownload; },
|
|
44
|
+
set autoDownload(value) { updater.autoDownload = value; },
|
|
45
|
+
get autoInstallOnAppQuit() { return updater.autoInstallOnAppQuit; },
|
|
46
|
+
set autoInstallOnAppQuit(value) { updater.autoInstallOnAppQuit = value; },
|
|
47
|
+
get autoRunAppAfterInstall() { return updater.autoRunAppAfterInstall; },
|
|
48
|
+
set autoRunAppAfterInstall(value) { updater.autoRunAppAfterInstall = value; },
|
|
49
|
+
checkForUpdates: () => updater.checkForUpdates(),
|
|
50
|
+
quitAndInstall: (isSilent, isForceRunAfter) => updater.quitAndInstall(isSilent, isForceRunAfter),
|
|
51
|
+
on(...args) {
|
|
52
|
+
if (args[0] === 'update-downloaded')
|
|
53
|
+
return updater.on(args[0], args[1]);
|
|
54
|
+
return updater.on(args[0], args[1]);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// EventEmitter.on has two parameters (or a rest tuple); the legacy object registration has one.
|
|
59
|
+
// This compatibility distinction can disappear after hosts remove the one-object ABI.
|
|
60
|
+
function isNativeUpdater(updater) {
|
|
61
|
+
return updater.on.length !== 1;
|
|
62
|
+
}
|
|
63
|
+
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
64
|
+
/** Coordinates quiet downloads and last-instance installs through injected effects.
|
|
65
|
+
* No single-instance lock is acquired. Construction registers updater listeners but starts no timers.
|
|
66
|
+
* @complexity O(1) construction; O(n) live records per tick or final quit.
|
|
67
|
+
*/
|
|
68
|
+
export function createAutoUpdateController(deps, options = {}) {
|
|
69
|
+
const { updater, platform, pid, presence, log } = deps;
|
|
70
|
+
const clock = deps.clock !== undefined ? deps.clock : { nowMs: deps.now };
|
|
71
|
+
const now = () => clock.nowMs();
|
|
72
|
+
const timers = options.timers ?? deps.timers ?? createNodeUpdateTimers();
|
|
73
|
+
const timing = { ...defaultUpdateTiming, ...deps.timing, ...options.timing };
|
|
74
|
+
const messages = options.messages ?? deps.messages ?? defaultUpdateMessages;
|
|
75
|
+
const startedAt = now();
|
|
76
|
+
const handles = [];
|
|
77
|
+
let started = false;
|
|
78
|
+
let stopped = false;
|
|
79
|
+
let lastCheckAt = null;
|
|
80
|
+
let checking = false;
|
|
81
|
+
let readyVersion = null;
|
|
82
|
+
let promptedVersion = null;
|
|
83
|
+
let restartRequested = false;
|
|
84
|
+
let installStarted = false;
|
|
85
|
+
updater.autoDownload = true;
|
|
86
|
+
// Windows registers its quit handler only if this is true at download time; final-quit policy
|
|
87
|
+
// later decides whether to allow installation. macOS must withhold Squirrel until the final quit.
|
|
88
|
+
updater.autoInstallOnAppQuit = platform === 'win32';
|
|
89
|
+
const onDownloaded = (info) => {
|
|
90
|
+
if (stopped)
|
|
91
|
+
return;
|
|
92
|
+
readyVersion = info.version;
|
|
93
|
+
log({ message: messages.downloaded({ version: info.version }) });
|
|
94
|
+
if (promptedVersion === info.version)
|
|
95
|
+
return;
|
|
96
|
+
promptedVersion = info.version;
|
|
97
|
+
// Promise wrapping catches a prompt that throws synchronously as well as a rejection.
|
|
98
|
+
Promise.resolve().then(() => deps.promptUpdateReady({ version: info.version })).then(restart => { if (restart && !stopped)
|
|
99
|
+
requestRestart(); }, error => log({ message: messages.promptFailed({ message: messageOf(error) }) }));
|
|
100
|
+
};
|
|
101
|
+
const onError = (error) => {
|
|
102
|
+
if (stopped)
|
|
103
|
+
return;
|
|
104
|
+
log({ message: messages.error({ message: messageOf(error) }) });
|
|
105
|
+
// A failed Squirrel handoff must release the held quit rather than leave the app hanging.
|
|
106
|
+
if (installStarted)
|
|
107
|
+
deps.quit();
|
|
108
|
+
};
|
|
109
|
+
if (isNativeUpdater(updater)) {
|
|
110
|
+
updater.on('update-downloaded', onDownloaded);
|
|
111
|
+
updater.on('error', onError);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
updater.on({ event: 'update-downloaded', listener: ({ payload }) => onDownloaded(payload) });
|
|
115
|
+
updater.on({ event: 'error', listener: ({ payload }) => onError(payload) });
|
|
116
|
+
}
|
|
117
|
+
function otherInstances() { return presence.readLive().filter(record => record.pid !== pid).length; }
|
|
118
|
+
function heartbeat() {
|
|
119
|
+
try {
|
|
120
|
+
presence.write({ record: { pid, startedAt, heartbeatAt: now() } });
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
log({ message: messages.presenceWriteFailed({ message: messageOf(error) }) });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function check() {
|
|
127
|
+
lastCheckAt = now();
|
|
128
|
+
checking = true;
|
|
129
|
+
let result;
|
|
130
|
+
try {
|
|
131
|
+
result = updater.checkForUpdates();
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
checking = false;
|
|
135
|
+
log({ message: messages.checkFailed({ message: messageOf(error) }) });
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
result.then(value => value?.downloadPromise ?? null)
|
|
139
|
+
.catch(error => log({ message: messages.checkFailed({ message: messageOf(error) }) }))
|
|
140
|
+
.finally(() => { checking = false; });
|
|
141
|
+
}
|
|
142
|
+
function tick() {
|
|
143
|
+
if (stopped)
|
|
144
|
+
return;
|
|
145
|
+
heartbeat();
|
|
146
|
+
const time = now();
|
|
147
|
+
const isOwner = electUpdaterOwner({ instances: presence.readLive(), now: time, staleMs: timing.staleMs }) === pid;
|
|
148
|
+
if (shouldCheckNow({ isOwner, lastCheckAt, now: time, busy: checking || readyVersion !== null, intervalMs: timing.checkIntervalMs }))
|
|
149
|
+
check();
|
|
150
|
+
}
|
|
151
|
+
function requestRestart() {
|
|
152
|
+
if (stopped)
|
|
153
|
+
return;
|
|
154
|
+
const count = otherInstances();
|
|
155
|
+
const action = decideRestartClick({ updateReady: readyVersion !== null, otherInstances: count });
|
|
156
|
+
if (action === 'others-open')
|
|
157
|
+
deps.explainOthersOpen({ count });
|
|
158
|
+
if (action !== 'restart')
|
|
159
|
+
return;
|
|
160
|
+
restartRequested = true;
|
|
161
|
+
deps.quit();
|
|
162
|
+
}
|
|
163
|
+
function startInstall(silent, relaunch) {
|
|
164
|
+
installStarted = true;
|
|
165
|
+
updater.autoRunAppAfterInstall = relaunch;
|
|
166
|
+
// Arm before the handoff so a synchronous failure cannot leave the held quit hanging.
|
|
167
|
+
const fallback = timers.setTimeout({ callback: () => { if (!stopped)
|
|
168
|
+
deps.quit(); }, ms: timing.stageTimeoutMs });
|
|
169
|
+
fallback.unref?.();
|
|
170
|
+
handles.push(fallback);
|
|
171
|
+
try {
|
|
172
|
+
if (isNativeUpdater(updater))
|
|
173
|
+
updater.quitAndInstall(silent, relaunch);
|
|
174
|
+
else
|
|
175
|
+
updater.quitAndInstall({}, { isSilent: silent, isForceRunAfter: relaunch });
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
log({ message: messages.error({ message: messageOf(error) }) });
|
|
179
|
+
deps.quit();
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
start() {
|
|
185
|
+
if (started || stopped)
|
|
186
|
+
return;
|
|
187
|
+
// Advertise presence immediately so siblings see us, while delaying the first update check.
|
|
188
|
+
started = true;
|
|
189
|
+
heartbeat();
|
|
190
|
+
const first = timers.setTimeout({ callback: tick, ms: timing.firstCheckDelayMs });
|
|
191
|
+
const every = timers.setInterval({ callback: tick, ms: timing.tickMs });
|
|
192
|
+
first.unref?.();
|
|
193
|
+
every.unref?.();
|
|
194
|
+
handles.push(first, every);
|
|
195
|
+
},
|
|
196
|
+
tick,
|
|
197
|
+
requestRestart,
|
|
198
|
+
beforeFinalQuit() {
|
|
199
|
+
if (stopped)
|
|
200
|
+
return false;
|
|
201
|
+
const action = decideFinalQuit({ platform, updateReady: readyVersion !== null,
|
|
202
|
+
otherInstances: readyVersion !== null && !installStarted ? otherInstances() : 0,
|
|
203
|
+
restartRequested, installStarted });
|
|
204
|
+
if (platform === 'win32' && !installStarted)
|
|
205
|
+
updater.autoInstallOnAppQuit = action === 'install-on-quit';
|
|
206
|
+
if (action === 'stage-then-quit')
|
|
207
|
+
return startInstall(false, false);
|
|
208
|
+
if (action === 'install-and-relaunch')
|
|
209
|
+
return startInstall(true, true);
|
|
210
|
+
return false;
|
|
211
|
+
},
|
|
212
|
+
willQuit() {
|
|
213
|
+
if (stopped)
|
|
214
|
+
return;
|
|
215
|
+
stopped = true;
|
|
216
|
+
for (const handle of handles)
|
|
217
|
+
timers.clear({ timer: handle });
|
|
218
|
+
presence.remove({ pid });
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=auto-update-controller.js.map
|