@jini-ai/desktop-host 0.7.3-next.2 → 0.7.4
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 +7 -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/dist/tauri/tauri-sidecar.js +0 -2
- package/package.json +153 -6
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Attach a private header to requests made in ONE session, for an exact list of URLs only.
|
|
3
|
+
* No renderer ever receives the value; other ports and origins cannot receive it through this
|
|
4
|
+
* listener because the match is exact-URL, not prefix or origin. The host validates the value and
|
|
5
|
+
* the origin, and builds the URLs, before arming.
|
|
6
|
+
*/
|
|
7
|
+
import type { HeaderArmingSession } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Register the listener on `required.session`; requests to any other URL pass through unchanged.
|
|
10
|
+
* @complexity O(u) per intercepted request in the number of armed URLs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function armExactUrlHeader(required: {
|
|
13
|
+
session: HeaderArmingSession;
|
|
14
|
+
urls: string[];
|
|
15
|
+
header: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}, _optional?: Record<string, never>): void;
|
|
18
|
+
//# sourceMappingURL=header-arming.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register the listener on `required.session`; requests to any other URL pass through unchanged.
|
|
3
|
+
* @complexity O(u) per intercepted request in the number of armed URLs.
|
|
4
|
+
*/
|
|
5
|
+
export function armExactUrlHeader(required, _optional = {}) {
|
|
6
|
+
const { urls, header, value } = required;
|
|
7
|
+
required.session.webRequest.onBeforeSendHeaders({ urls }, (details, callback) => {
|
|
8
|
+
callback({ requestHeaders: urls.includes(details.url)
|
|
9
|
+
? { ...details.requestHeaders, [header]: value }
|
|
10
|
+
: details.requestHeaders });
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=header-arming.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Electron main-process session bootstrap mechanics: the cookie exchange into a partition's
|
|
3
|
+
* jar, the server-asked validity probe, per-key partition naming and exact-URL header arming.
|
|
4
|
+
* Endpoints, cookie and partition names, header names, URL guards and copy are the host's.
|
|
5
|
+
*/
|
|
6
|
+
export { exchangeSessionJson, exchangeSessionRequest } from './exchange.js';
|
|
7
|
+
export { hasSessionCookie, probeSession } from './probe.js';
|
|
8
|
+
export { persistentPartitionName } from './partition.js';
|
|
9
|
+
export { armExactUrlHeader } from './header-arming.js';
|
|
10
|
+
export type { CookieJarSession, HeaderArmingSession, SessionBodyRequest, SessionNet, SessionOutcome, SessionRequest, SessionRequestOptions, SessionResponse, } from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Electron main-process session bootstrap mechanics: the cookie exchange into a partition's
|
|
3
|
+
* jar, the server-asked validity probe, per-key partition naming and exact-URL header arming.
|
|
4
|
+
* Endpoints, cookie and partition names, header names, URL guards and copy are the host's.
|
|
5
|
+
*/
|
|
6
|
+
export { exchangeSessionJson, exchangeSessionRequest } from './exchange.js';
|
|
7
|
+
export { hasSessionCookie, probeSession } from './probe.js';
|
|
8
|
+
export { persistentPartitionName } from './partition.js';
|
|
9
|
+
export { armExactUrlHeader } from './header-arming.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stable, filesystem-safe `persist:` partition name for `required.key`.
|
|
3
|
+
*
|
|
4
|
+
* Hashed rather than derived from the key so the name cannot collide with Electron's partition
|
|
5
|
+
* syntax (`persist:` prefix, `/` separators) and does not leak e.g. the operator's directory
|
|
6
|
+
* layout into a partition directory name under `userData`. The host normalises the key first
|
|
7
|
+
* (e.g. `path.resolve` of a site dir) so equivalent spellings share one jar.
|
|
8
|
+
*
|
|
9
|
+
* @param required.prefix the host's partition namespace, placed between `persist:` and the digest.
|
|
10
|
+
* @returns `persist:<prefix><32 hex chars>`.
|
|
11
|
+
* @complexity O(n) in the key length.
|
|
12
|
+
*/
|
|
13
|
+
export declare function persistentPartitionName(required: {
|
|
14
|
+
prefix: string;
|
|
15
|
+
key: string;
|
|
16
|
+
}, _optional?: Record<string, never>): string;
|
|
17
|
+
//# sourceMappingURL=partition.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file One Electron session partition (one cookie jar) per key. Cookies ignore port, so two
|
|
3
|
+
* loopback servers on different ports share a jar by default — one's session cookie would be sent
|
|
4
|
+
* to the other, and the second redeem would overwrite the first. A partition per site is a
|
|
5
|
+
* correctness requirement of serving several sites, not a hardening nicety.
|
|
6
|
+
*/
|
|
7
|
+
import crypto from 'node:crypto';
|
|
8
|
+
/**
|
|
9
|
+
* A stable, filesystem-safe `persist:` partition name for `required.key`.
|
|
10
|
+
*
|
|
11
|
+
* Hashed rather than derived from the key so the name cannot collide with Electron's partition
|
|
12
|
+
* syntax (`persist:` prefix, `/` separators) and does not leak e.g. the operator's directory
|
|
13
|
+
* layout into a partition directory name under `userData`. The host normalises the key first
|
|
14
|
+
* (e.g. `path.resolve` of a site dir) so equivalent spellings share one jar.
|
|
15
|
+
*
|
|
16
|
+
* @param required.prefix the host's partition namespace, placed between `persist:` and the digest.
|
|
17
|
+
* @returns `persist:<prefix><32 hex chars>`.
|
|
18
|
+
* @complexity O(n) in the key length.
|
|
19
|
+
*/
|
|
20
|
+
export function persistentPartitionName(required, _optional = {}) {
|
|
21
|
+
const digest = crypto.createHash('sha256').update(required.key).digest('hex').slice(0, 32);
|
|
22
|
+
return `persist:${required.prefix}${digest}`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=partition.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Whether a partition's cookie jar carries a session the SERVER still honours — asked of the
|
|
3
|
+
* server, not inferred from the jar.
|
|
4
|
+
*
|
|
5
|
+
* A cookie present in the jar is not proof the session is valid server-side: its row may be gone
|
|
6
|
+
* (a rollback, a stale-session cleanup, any revoke this shell did not perform itself). Treating
|
|
7
|
+
* presence as validity skips the redeem and strands the operator at a login form. So presence is
|
|
8
|
+
* only the CHEAP NEGATIVE: a brand-new partition has no cookie, and a request that could only ever
|
|
9
|
+
* answer 401 is a round trip on the critical path of every first open.
|
|
10
|
+
*
|
|
11
|
+
* The cookie is matched by NAME only, never by URL/port: Chromium keys a cookie by host, not port,
|
|
12
|
+
* and a host that allocates a fresh port per launch would never match a port-scoped lookup.
|
|
13
|
+
*
|
|
14
|
+
* `useSessionCookies: true` is load-bearing exactly as in the exchange — without it the probe asks
|
|
15
|
+
* as an anonymous caller and reports 401 for a healthy session, which would redeem a fresh session
|
|
16
|
+
* on every open. Fails to `false`, never rejects, for any transport outcome: "cannot confirm" and
|
|
17
|
+
* "not authenticated" both mean "redeem and try".
|
|
18
|
+
*/
|
|
19
|
+
import type { CookieJarSession, SessionNet } from './types.js';
|
|
20
|
+
/**
|
|
21
|
+
* Whether `required.session`'s jar holds at least one cookie named `required.cookieName`.
|
|
22
|
+
* @complexity O(1) — one cookie-store lookup.
|
|
23
|
+
*/
|
|
24
|
+
export declare function hasSessionCookie(required: {
|
|
25
|
+
session: CookieJarSession;
|
|
26
|
+
cookieName: string;
|
|
27
|
+
}, _optional?: Record<string, never>): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Cookie check first, then a `GET` of the host's own "who am I" route, which must answer `200`
|
|
30
|
+
* for a live session and non-`200` (401) otherwise.
|
|
31
|
+
* @param required.url the probe route; the host guards it before calling.
|
|
32
|
+
* @complexity O(1) — one cookie lookup plus at most one request.
|
|
33
|
+
*/
|
|
34
|
+
export declare function probeSession<TSession>(required: {
|
|
35
|
+
net: SessionNet<TSession>;
|
|
36
|
+
session: TSession & CookieJarSession;
|
|
37
|
+
url: string;
|
|
38
|
+
cookieName: string;
|
|
39
|
+
}, _optional?: Record<string, never>): Promise<boolean>;
|
|
40
|
+
//# sourceMappingURL=probe.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether `required.session`'s jar holds at least one cookie named `required.cookieName`.
|
|
3
|
+
* @complexity O(1) — one cookie-store lookup.
|
|
4
|
+
*/
|
|
5
|
+
export async function hasSessionCookie(required, _optional = {}) {
|
|
6
|
+
const cookies = await required.session.cookies.get({ name: required.cookieName });
|
|
7
|
+
return cookies.length > 0;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Cookie check first, then a `GET` of the host's own "who am I" route, which must answer `200`
|
|
11
|
+
* for a live session and non-`200` (401) otherwise.
|
|
12
|
+
* @param required.url the probe route; the host guards it before calling.
|
|
13
|
+
* @complexity O(1) — one cookie lookup plus at most one request.
|
|
14
|
+
*/
|
|
15
|
+
export async function probeSession(required, _optional = {}) {
|
|
16
|
+
if (!(await hasSessionCookie({ session: required.session, cookieName: required.cookieName })))
|
|
17
|
+
return false;
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
const request = required.net.request({ method: 'GET', url: required.url, session: required.session, useSessionCookies: true });
|
|
20
|
+
request.on('response', (response) => {
|
|
21
|
+
// Drained rather than parsed. Only the STATUS is the answer; the principal is not ours.
|
|
22
|
+
response.on('data', () => { });
|
|
23
|
+
response.on('end', () => resolve(response.statusCode === 200));
|
|
24
|
+
});
|
|
25
|
+
request.on('error', () => resolve(false));
|
|
26
|
+
request.end();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=probe.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Structural slices of Electron's `net`, `ClientRequest`, `IncomingMessage` and `Session`
|
|
3
|
+
* that the session bootstrap reads. Declared here rather than imported from `electron` so the
|
|
4
|
+
* mechanics are testable against fakes and this entry never loads the Electron runtime.
|
|
5
|
+
*/
|
|
6
|
+
/** What an exchange resolves with: `ok` only for a `200`; a transport error carries no status. */
|
|
7
|
+
export interface SessionOutcome {
|
|
8
|
+
ok: boolean;
|
|
9
|
+
status?: number;
|
|
10
|
+
reason?: string;
|
|
11
|
+
}
|
|
12
|
+
/** The slice of a `Session` read here: its cookie jar's lookup. */
|
|
13
|
+
export interface CookieJarSession {
|
|
14
|
+
cookies: {
|
|
15
|
+
get(filter: {
|
|
16
|
+
name: string;
|
|
17
|
+
}): Promise<unknown[]>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** What `net.request` is given, a subset of Electron's `ClientRequestConstructorOptions`. The
|
|
21
|
+
* session is only handed through to the request, so its type is whatever the caller's is. */
|
|
22
|
+
export interface SessionRequestOptions<TSession> {
|
|
23
|
+
method: 'GET' | 'POST';
|
|
24
|
+
url: string;
|
|
25
|
+
session: TSession;
|
|
26
|
+
useSessionCookies: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The slice of an `IncomingMessage` read here. */
|
|
29
|
+
export interface SessionResponse {
|
|
30
|
+
statusCode: number;
|
|
31
|
+
on(event: 'data', listener: () => void): unknown;
|
|
32
|
+
on(event: 'end', listener: () => void): unknown;
|
|
33
|
+
}
|
|
34
|
+
/** The slice of a `ClientRequest` every request here uses. */
|
|
35
|
+
export interface SessionRequest {
|
|
36
|
+
on(event: 'response', listener: (response: SessionResponse) => void): unknown;
|
|
37
|
+
on(event: 'error', listener: (error: Error) => void): unknown;
|
|
38
|
+
end(): void;
|
|
39
|
+
}
|
|
40
|
+
/** A request that also sends a JSON body. */
|
|
41
|
+
export interface SessionBodyRequest extends SessionRequest {
|
|
42
|
+
setHeader(name: string, value: string): void;
|
|
43
|
+
write(chunk: string): void;
|
|
44
|
+
}
|
|
45
|
+
/** The slice of Electron's `net` module used here, answering with `TRequest`. */
|
|
46
|
+
export interface SessionNet<TSession, TRequest extends SessionRequest = SessionRequest> {
|
|
47
|
+
request(options: SessionRequestOptions<TSession>): TRequest;
|
|
48
|
+
}
|
|
49
|
+
/** The slice of a `Session`'s `webRequest` that header arming registers on. */
|
|
50
|
+
export interface HeaderArmingSession {
|
|
51
|
+
webRequest: {
|
|
52
|
+
onBeforeSendHeaders(filter: {
|
|
53
|
+
urls: string[];
|
|
54
|
+
}, listener: (details: {
|
|
55
|
+
url: string;
|
|
56
|
+
requestHeaders: Record<string, string>;
|
|
57
|
+
}, callback: (response: {
|
|
58
|
+
requestHeaders: Record<string, string>;
|
|
59
|
+
}) => void) => void): void;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Structural slices of Electron's `net`, `ClientRequest`, `IncomingMessage` and `Session`
|
|
3
|
+
* that the session bootstrap reads. Declared here rather than imported from `electron` so the
|
|
4
|
+
* mechanics are testable against fakes and this entry never loads the Electron runtime.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The desktop auto-updater lifecycle around one `AutoUpdateController`: start it when this launch may
|
|
3
|
+
* run one, stop it when the host's automatic-updates preference turns it off, say whether the final
|
|
4
|
+
* quit installs an update, and hand a manual "Check for updates" the same native updater. The
|
|
5
|
+
* controller's own rules live in `auto-update-controller.ts`; this module owns only the lifecycle
|
|
6
|
+
* state. The host injects eligibility, the preference read/write, the lazy native-updater load, the
|
|
7
|
+
* controller factory, the "Update ready" prompt and a reporter (no copy or logging lives here); see
|
|
8
|
+
* the electron/updates README section for wiring.
|
|
9
|
+
*/
|
|
10
|
+
import type { AutoUpdateController } from './auto-update-controller.js';
|
|
11
|
+
/** The slice of electron-updater's `autoUpdater` the lifecycle itself toggles. */
|
|
12
|
+
export interface DesktopNativeUpdater {
|
|
13
|
+
autoDownload: boolean;
|
|
14
|
+
autoInstallOnAppQuit: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** The lifecycle's state: what an entry module would otherwise keep in four module variables. */
|
|
17
|
+
export interface DesktopUpdaterState<U extends DesktopNativeUpdater = DesktopNativeUpdater> {
|
|
18
|
+
/** The auto-updater, or `null` when this launch does not run one (ineligible, or the preference is
|
|
19
|
+
* off). `before-quit` asks it whether the final quit installs an update. */
|
|
20
|
+
controller: AutoUpdateController | null;
|
|
21
|
+
native: U | null;
|
|
22
|
+
starting: boolean;
|
|
23
|
+
/** The version `controller` downloaded and prompted for; a manual check shows that prompt again. */
|
|
24
|
+
readyVersion: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** Lifecycle events the host turns into its own log lines. */
|
|
27
|
+
export interface DesktopUpdaterReporter {
|
|
28
|
+
/** This launch runs no updater; `reason` is the host's `skipReason()`. */
|
|
29
|
+
skipped: (args: {
|
|
30
|
+
reason: string;
|
|
31
|
+
}) => void;
|
|
32
|
+
/** A background start failed; it never fails the boot. */
|
|
33
|
+
startFailed: (args: {
|
|
34
|
+
error: unknown;
|
|
35
|
+
}) => void;
|
|
36
|
+
}
|
|
37
|
+
export interface DesktopUpdaterPorts<U extends DesktopNativeUpdater = DesktopNativeUpdater> {
|
|
38
|
+
/** The persisted automatic-updates choice, read fresh each time. */
|
|
39
|
+
automaticUpdates: () => boolean;
|
|
40
|
+
saveAutomaticUpdates: (args: {
|
|
41
|
+
enabled: boolean;
|
|
42
|
+
}) => void;
|
|
43
|
+
/** The host's reason this launch runs no updater, or null. */
|
|
44
|
+
skipReason: () => string | null;
|
|
45
|
+
/** Resolves the native updater. Called only once the skip gate has passed, so an ineligible launch
|
|
46
|
+
* never reads it. */
|
|
47
|
+
loadNativeUpdater: () => Promise<U>;
|
|
48
|
+
/** No quit drain has begun. */
|
|
49
|
+
quitIdle: () => boolean;
|
|
50
|
+
/** Builds a controller bound to `updater`. Called once per start, so host inputs it reads (a data
|
|
51
|
+
* directory that may still move, for one) are read when a controller is created. */
|
|
52
|
+
createController: (args: {
|
|
53
|
+
updater: U;
|
|
54
|
+
promptUpdateReady: (args: {
|
|
55
|
+
version: string;
|
|
56
|
+
}) => Promise<boolean>;
|
|
57
|
+
}) => AutoUpdateController;
|
|
58
|
+
/** The host's "Update ready" prompt; resolves true for Restart. */
|
|
59
|
+
promptUpdateReady: (args: {
|
|
60
|
+
version: string;
|
|
61
|
+
}) => Promise<boolean>;
|
|
62
|
+
reporter: DesktopUpdaterReporter;
|
|
63
|
+
}
|
|
64
|
+
export interface DesktopUpdater<U extends DesktopNativeUpdater = DesktopNativeUpdater> {
|
|
65
|
+
state: DesktopUpdaterState<U>;
|
|
66
|
+
start(): Promise<void>;
|
|
67
|
+
startInBackground(): void;
|
|
68
|
+
setAutomaticUpdates(args: {
|
|
69
|
+
enabled: boolean;
|
|
70
|
+
}): void;
|
|
71
|
+
finalQuitHeldForUpdate(): boolean;
|
|
72
|
+
willQuit(): void;
|
|
73
|
+
readyVersion(): string | null;
|
|
74
|
+
loadUpdaterForCheck(): Promise<U>;
|
|
75
|
+
showReadyPrompt(args: {
|
|
76
|
+
version: string;
|
|
77
|
+
}): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
/** Nothing started yet. */
|
|
80
|
+
export declare function createDesktopUpdaterState<U extends DesktopNativeUpdater = DesktopNativeUpdater>(_requiredArgs?: {}, _optionalArgs?: {}): DesktopUpdaterState<U>;
|
|
81
|
+
/**
|
|
82
|
+
* Binds the updater lifecycle to injected preference, native-updater and controller ports.
|
|
83
|
+
* @complexity O(1) per call beyond the injected ports.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createDesktopUpdater<U extends DesktopNativeUpdater>({ ports }: {
|
|
86
|
+
ports: DesktopUpdaterPorts<U>;
|
|
87
|
+
}, { state, }?: {
|
|
88
|
+
state?: DesktopUpdaterState<U>;
|
|
89
|
+
}): DesktopUpdater<U>;
|
|
90
|
+
//# sourceMappingURL=desktop-updater.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/** Nothing started yet. */
|
|
2
|
+
export function createDesktopUpdaterState(_requiredArgs = {}, _optionalArgs = {}) {
|
|
3
|
+
return { controller: null, native: null, starting: false, readyVersion: null };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Binds the updater lifecycle to injected preference, native-updater and controller ports.
|
|
7
|
+
* @complexity O(1) per call beyond the injected ports.
|
|
8
|
+
*/
|
|
9
|
+
export function createDesktopUpdater({ ports }, { state = createDesktopUpdaterState(), } = {}) {
|
|
10
|
+
let startup = null;
|
|
11
|
+
const loadController = createUpdaterControllerLoader({ ports, bind: createUpdaterControllerBinder({ state, ports }) });
|
|
12
|
+
/** Starts the auto-updater unless this launch must not run one (the host's `skipReason`). */
|
|
13
|
+
function start() {
|
|
14
|
+
if (startup)
|
|
15
|
+
return startup;
|
|
16
|
+
if (state.controller || !ports.automaticUpdates())
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
state.starting = true;
|
|
19
|
+
// A manual check must await the same lazy import and listener binding as background start.
|
|
20
|
+
startup = loadController().finally(() => {
|
|
21
|
+
state.starting = false;
|
|
22
|
+
startup = null;
|
|
23
|
+
});
|
|
24
|
+
return startup;
|
|
25
|
+
}
|
|
26
|
+
// Not awaited: the updater's first check waits on its own timer, and a failure to load it must
|
|
27
|
+
// never block or fail the boot.
|
|
28
|
+
function startInBackground() {
|
|
29
|
+
start().catch((error) => ports.reporter.startFailed({ error }));
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
state,
|
|
33
|
+
start,
|
|
34
|
+
startInBackground,
|
|
35
|
+
/** Persist first: a failed write must leave the actual updater and the checkbox unchanged. */
|
|
36
|
+
setAutomaticUpdates: createAutomaticUpdatesSetter({ ports, startInBackground, stop: createUpdaterStopper({ state }) }),
|
|
37
|
+
finalQuitHeldForUpdate: createFinalQuitUpdateCheck({ ports, state }),
|
|
38
|
+
// `will-quit`: removes this instance's presence record.
|
|
39
|
+
willQuit: () => state.controller?.willQuit(),
|
|
40
|
+
readyVersion: () => (state.controller ? state.readyVersion : null),
|
|
41
|
+
loadUpdaterForCheck: createManualUpdaterLoader({ ports, start, state }),
|
|
42
|
+
async showReadyPrompt({ version }) {
|
|
43
|
+
if (await ports.promptUpdateReady({ version }))
|
|
44
|
+
state.controller?.requestRestart();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** A manual "Check for updates": the same native updater the controller listens to. */
|
|
49
|
+
function createManualUpdaterLoader({ ports, start, state }) {
|
|
50
|
+
return async function loadUpdaterForCheck() {
|
|
51
|
+
// With updates on, the controller must be listening before a download can start.
|
|
52
|
+
if (ports.automaticUpdates())
|
|
53
|
+
await start();
|
|
54
|
+
const updater = await ports.loadNativeUpdater();
|
|
55
|
+
state.native ??= updater;
|
|
56
|
+
return updater;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The quit that actually ends the app, once nothing is left to drain. A downloaded update installs
|
|
61
|
+
* here, and only when no other instance of the app is running (`update-policy.ts`'s
|
|
62
|
+
* `decideFinalQuit`). When the install takes over (macOS staging, or Restart to update) it quits the
|
|
63
|
+
* app itself, so this quit is held.
|
|
64
|
+
*/
|
|
65
|
+
function createFinalQuitUpdateCheck({ ports, state }) {
|
|
66
|
+
return function finalQuitHeldForUpdate() {
|
|
67
|
+
if (!ports.automaticUpdates()) {
|
|
68
|
+
if (state.native)
|
|
69
|
+
state.native.autoInstallOnAppQuit = false;
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return state.controller?.beforeFinalQuit() ?? false;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function createAutomaticUpdatesSetter({ ports, startInBackground, stop }) {
|
|
76
|
+
return function setAutomaticUpdates({ enabled }) {
|
|
77
|
+
ports.saveAutomaticUpdates({ enabled });
|
|
78
|
+
if (enabled)
|
|
79
|
+
startInBackground();
|
|
80
|
+
else
|
|
81
|
+
stop();
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function createUpdaterStopper({ state }) {
|
|
85
|
+
return function stop() {
|
|
86
|
+
state.controller?.willQuit();
|
|
87
|
+
state.controller = null;
|
|
88
|
+
// A download already in flight may finish, but its stopped controller cannot prompt/install.
|
|
89
|
+
// Electron-updater's Windows quit listener also reads this flag before installing.
|
|
90
|
+
if (state.native) {
|
|
91
|
+
state.native.autoDownload = false;
|
|
92
|
+
state.native.autoInstallOnAppQuit = false;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function createUpdaterControllerLoader({ ports, bind }) {
|
|
97
|
+
return async function loadController() {
|
|
98
|
+
const skip = ports.skipReason();
|
|
99
|
+
if (skip !== null) {
|
|
100
|
+
ports.reporter.skipped({ reason: skip });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const updater = await ports.loadNativeUpdater();
|
|
104
|
+
// The operator may turn updates off while the lazy import is resolving.
|
|
105
|
+
if (!ports.automaticUpdates() || !ports.quitIdle())
|
|
106
|
+
return;
|
|
107
|
+
bind(updater);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function createUpdaterControllerBinder({ state, ports }) {
|
|
111
|
+
return function bind(updater) {
|
|
112
|
+
state.native = updater;
|
|
113
|
+
state.readyVersion = null;
|
|
114
|
+
state.controller = ports.createController({
|
|
115
|
+
updater,
|
|
116
|
+
promptUpdateReady: ({ version }) => {
|
|
117
|
+
state.readyVersion = version;
|
|
118
|
+
return ports.promptUpdateReady({ version });
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
state.controller.start();
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=desktop-updater.js.map
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './update-policy.js';
|
|
2
2
|
export * from './instance-presence.js';
|
|
3
|
+
export * from './instance-presence-strict.js';
|
|
3
4
|
export * from './auto-update-controller.js';
|
|
5
|
+
export * from './update-check-now.js';
|
|
6
|
+
export * from './desktop-updater.js';
|
|
7
|
+
export * from './native-notices.js';
|
|
4
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './update-policy.js';
|
|
2
2
|
export * from './instance-presence.js';
|
|
3
|
+
export * from './instance-presence-strict.js';
|
|
3
4
|
export * from './auto-update-controller.js';
|
|
5
|
+
export * from './update-check-now.js';
|
|
6
|
+
export * from './desktop-updater.js';
|
|
7
|
+
export * from './native-notices.js';
|
|
4
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PresenceFilesystemPort } from './instance-presence.js';
|
|
2
|
+
import type { InstanceRecord } from './update-policy.js';
|
|
3
|
+
/**
|
|
4
|
+
* Destructive callers need a reader that can say "I do not know". The tolerant `readLive` skips
|
|
5
|
+
* unreadable records and returns no instances on a directory error, which is right for update
|
|
6
|
+
* timing but would read an unreadable sibling as "no sibling" and authorize mutation. This reader
|
|
7
|
+
* never removes files and turns every doubt into `unknown`.
|
|
8
|
+
*/
|
|
9
|
+
export type StrictPresenceRead = {
|
|
10
|
+
state: 'ok';
|
|
11
|
+
value: InstanceRecord[];
|
|
12
|
+
} | {
|
|
13
|
+
state: 'unknown';
|
|
14
|
+
reason: string;
|
|
15
|
+
};
|
|
16
|
+
export interface ReadPresenceStrictInput {
|
|
17
|
+
directory: string;
|
|
18
|
+
fs: Pick<PresenceFilesystemPort, 'readdirSync' | 'readFileSync'>;
|
|
19
|
+
liveness: (args: {
|
|
20
|
+
pid: number;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Live presence records, or `unknown` on any unreadable/malformed record or non-ENOENT directory error.
|
|
24
|
+
* @complexity O(n) records and liveness probes.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readPresenceStrict({ directory, fs, liveness }: ReadPresenceStrictInput, _optional?: Record<string, never>): StrictPresenceRead;
|
|
27
|
+
//# sourceMappingURL=instance-presence-strict.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
function isRecord(value, name) {
|
|
3
|
+
const record = value;
|
|
4
|
+
if (!record || typeof record !== 'object')
|
|
5
|
+
return false;
|
|
6
|
+
const numeric = [record.pid, record.startedAt, record.heartbeatAt].every(v => typeof v === 'number' && Number.isFinite(v));
|
|
7
|
+
return numeric && name === `${record.pid}.json`;
|
|
8
|
+
}
|
|
9
|
+
function readRecord(name, { directory, fs }) {
|
|
10
|
+
let parsed;
|
|
11
|
+
try {
|
|
12
|
+
parsed = JSON.parse(fs.readFileSync({ path: path.join(directory, name), encoding: 'utf8' }));
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
// Only the owner (on quit) or a dead-PID sweep deletes a record, so a vanished file is proof of exit.
|
|
16
|
+
if (error?.code === 'ENOENT')
|
|
17
|
+
return { state: 'gone' };
|
|
18
|
+
return { state: 'bad', reason: `presence record ${name} unreadable` };
|
|
19
|
+
}
|
|
20
|
+
return isRecord(parsed, name) ? { state: 'record', record: parsed } : { state: 'bad', reason: `presence record ${name} malformed` };
|
|
21
|
+
}
|
|
22
|
+
/** Live presence records, or `unknown` on any unreadable/malformed record or non-ENOENT directory error.
|
|
23
|
+
* @complexity O(n) records and liveness probes.
|
|
24
|
+
*/
|
|
25
|
+
export function readPresenceStrict({ directory, fs, liveness }, _optional = {}) {
|
|
26
|
+
let names;
|
|
27
|
+
try {
|
|
28
|
+
names = fs.readdirSync({ path: directory });
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
const errorCode = error?.code;
|
|
32
|
+
if (errorCode === 'ENOENT')
|
|
33
|
+
return { state: 'ok', value: [] };
|
|
34
|
+
return { state: 'unknown', reason: `presence directory unreadable (${errorCode ?? 'error'})` };
|
|
35
|
+
}
|
|
36
|
+
const live = [];
|
|
37
|
+
for (const name of names.filter(entry => /^\d+\.json$/.test(entry))) {
|
|
38
|
+
const read = readRecord(name, { directory, fs });
|
|
39
|
+
if (read.state === 'bad')
|
|
40
|
+
return { state: 'unknown', reason: read.reason };
|
|
41
|
+
if (read.state === 'record' && liveness({ pid: read.record.pid }))
|
|
42
|
+
live.push(read.record);
|
|
43
|
+
}
|
|
44
|
+
return { state: 'ok', value: live };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=instance-presence-strict.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native message boxes the updater and the desktop shell show: a plain notice, the "Update ready"
|
|
3
|
+
* prompt and the "close the other copies" explanation. Electron's `dialog` and `BrowserWindow`
|
|
4
|
+
* arrive as ports, so every rule here runs under plain node with fakes. Every word (labels, titles,
|
|
5
|
+
* details) is host copy passed in; this module owns only parenting, button order and answers.
|
|
6
|
+
*/
|
|
7
|
+
import type { UpdateNotice } from './update-check-now.js';
|
|
8
|
+
/** The slice of Electron's `MessageBoxOptions` these boxes set; Electron's own type accepts it. */
|
|
9
|
+
export interface NativeMessageBoxOptions {
|
|
10
|
+
type?: 'none' | 'info' | 'error' | 'question' | 'warning';
|
|
11
|
+
message: string;
|
|
12
|
+
detail?: string;
|
|
13
|
+
buttons?: string[];
|
|
14
|
+
defaultId?: number;
|
|
15
|
+
cancelId?: number;
|
|
16
|
+
}
|
|
17
|
+
/** The slice of Electron's `dialog` these boxes use; Electron's own `dialog` satisfies it. */
|
|
18
|
+
export interface NativeDialogPort<W> {
|
|
19
|
+
showMessageBox(window: W, options: NativeMessageBoxOptions): Promise<{
|
|
20
|
+
response: number;
|
|
21
|
+
}>;
|
|
22
|
+
showMessageBox(options: NativeMessageBoxOptions): Promise<{
|
|
23
|
+
response: number;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
/** The slice of Electron's `BrowserWindow` statics these boxes use. */
|
|
27
|
+
export interface WindowListPort<W> {
|
|
28
|
+
getFocusedWindow(): W | null;
|
|
29
|
+
getAllWindows(): W[];
|
|
30
|
+
}
|
|
31
|
+
/** Host wording for the "Update ready" prompt. */
|
|
32
|
+
export interface UpdateReadyPromptCopy {
|
|
33
|
+
message: string;
|
|
34
|
+
detail: (args: {
|
|
35
|
+
version: string;
|
|
36
|
+
}) => string;
|
|
37
|
+
restartLabel: string;
|
|
38
|
+
laterLabel: string;
|
|
39
|
+
}
|
|
40
|
+
/** Host wording for "close the other copies first" (the host owns pluralization). */
|
|
41
|
+
export interface OthersOpenCopy {
|
|
42
|
+
message: string;
|
|
43
|
+
detail: (args: {
|
|
44
|
+
count: number;
|
|
45
|
+
}) => string;
|
|
46
|
+
}
|
|
47
|
+
/** "Update ready": Restart is button 0, Escape/close lands on Later. */
|
|
48
|
+
export declare function updateReadyPromptOptions({ copy, version }: {
|
|
49
|
+
copy: UpdateReadyPromptCopy;
|
|
50
|
+
version: string;
|
|
51
|
+
}, _optionalArgs?: {}): NativeMessageBoxOptions;
|
|
52
|
+
/** Restart to update was chosen while other copies of the app are open. */
|
|
53
|
+
export declare function othersOpenOptions({ copy, count }: {
|
|
54
|
+
copy: OthersOpenCopy;
|
|
55
|
+
count: number;
|
|
56
|
+
}, _optionalArgs?: {}): NativeMessageBoxOptions;
|
|
57
|
+
/**
|
|
58
|
+
* A box as a sheet on the focused window, else the first window, else app-modal when none is open.
|
|
59
|
+
* @returns The native box's answer. @complexity O(n) open windows.
|
|
60
|
+
*/
|
|
61
|
+
export declare function showOnFocusedWindow<W>({ dialog, windows, options }: {
|
|
62
|
+
dialog: NativeDialogPort<W>;
|
|
63
|
+
windows: WindowListPort<W>;
|
|
64
|
+
options: NativeMessageBoxOptions;
|
|
65
|
+
}, _optionalArgs?: {}): Promise<{
|
|
66
|
+
response: number;
|
|
67
|
+
}>;
|
|
68
|
+
/** One native message box with a single acknowledge button (`okLabel`), not awaited. */
|
|
69
|
+
export declare function showNativeNotice<W>({ dialog, windows, notice, okLabel }: {
|
|
70
|
+
dialog: NativeDialogPort<W>;
|
|
71
|
+
windows: WindowListPort<W>;
|
|
72
|
+
notice: UpdateNotice;
|
|
73
|
+
okLabel: string;
|
|
74
|
+
}, _optionalArgs?: {}): void;
|
|
75
|
+
/** The "Update ready" prompt, as a sheet on the focused window. Resolves `true` for Restart. */
|
|
76
|
+
export declare function promptUpdateReady<W>({ dialog, windows, automaticUpdates, version, copy }: {
|
|
77
|
+
dialog: NativeDialogPort<W>;
|
|
78
|
+
windows: WindowListPort<W>;
|
|
79
|
+
automaticUpdates: () => boolean;
|
|
80
|
+
version: string;
|
|
81
|
+
copy: UpdateReadyPromptCopy;
|
|
82
|
+
}, _optionalArgs?: {}): Promise<boolean>;
|
|
83
|
+
/** Restart to update was chosen while other copies of the app are open. Never parented. */
|
|
84
|
+
export declare function explainOthersOpen<W>({ dialog, count, copy }: {
|
|
85
|
+
dialog: NativeDialogPort<W>;
|
|
86
|
+
count: number;
|
|
87
|
+
copy: OthersOpenCopy;
|
|
88
|
+
}, _optionalArgs?: {}): void;
|
|
89
|
+
//# sourceMappingURL=native-notices.d.ts.map
|