@jini-ai/desktop-host 0.1.2 → 0.4.1
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 +113 -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 +98 -0
- package/dist/speech/macos/mac-on-device-transcriber.js +127 -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
package/dist/protocol.js
CHANGED
|
@@ -24,7 +24,7 @@ function buildProxyErrorResponse(error, target) {
|
|
|
24
24
|
headers: { 'content-type': 'application/json' },
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
export function buildProtocolProxyTargetUrl(targetBaseUrl, requestUrl) {
|
|
27
|
+
export function buildProtocolProxyTargetUrl({ targetBaseUrl, requestUrl }) {
|
|
28
28
|
const incoming = new URL(requestUrl);
|
|
29
29
|
const target = new URL(targetBaseUrl);
|
|
30
30
|
target.pathname = incoming.pathname;
|
|
@@ -32,16 +32,16 @@ export function buildProtocolProxyTargetUrl(targetBaseUrl, requestUrl) {
|
|
|
32
32
|
target.hash = incoming.hash;
|
|
33
33
|
return target.toString();
|
|
34
34
|
}
|
|
35
|
-
export async function handleProtocolProxyRequest(request, targetBaseUrl, fetchImpl = fetch) {
|
|
36
|
-
const target = buildProtocolProxyTargetUrl(targetBaseUrl, request.url);
|
|
35
|
+
export async function handleProtocolProxyRequest({ request, targetBaseUrl }, { fetchImpl = ({ request }) => fetch(request) } = {}) {
|
|
36
|
+
const target = buildProtocolProxyTargetUrl({ targetBaseUrl, requestUrl: request.url });
|
|
37
37
|
try {
|
|
38
|
-
return await fetchImpl(new Request(target, request));
|
|
38
|
+
return await fetchImpl({ request: new Request(target, request) });
|
|
39
39
|
}
|
|
40
40
|
catch (error) {
|
|
41
41
|
return buildProxyErrorResponse(error, target);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
export function schemeEntryUrl(scheme) {
|
|
44
|
+
export function schemeEntryUrl({ scheme }) {
|
|
45
45
|
return `${scheme}://app/`;
|
|
46
46
|
}
|
|
47
47
|
//# sourceMappingURL=protocol.js.map
|
package/dist/render-service.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface RenderResourcePolicy {
|
|
|
25
25
|
javascript?: boolean;
|
|
26
26
|
allowNavigation?: boolean;
|
|
27
27
|
allowedOrigins?: string[];
|
|
28
|
+
/** Explicit opt-out from the default remote-network block, used only when no allowlist is supplied. */
|
|
29
|
+
allowUnrestrictedNetwork?: boolean;
|
|
28
30
|
}
|
|
29
31
|
export interface RenderOptions {
|
|
30
32
|
viewport?: RenderViewport;
|
|
@@ -60,20 +62,42 @@ export interface ExportArtifactOptions extends RenderOptions {
|
|
|
60
62
|
export type RenderServiceErrorCode = 'timeout' | 'aborted' | 'load-failed' | 'navigation-blocked' | 'not-implemented';
|
|
61
63
|
export declare class RenderServiceError extends Error {
|
|
62
64
|
readonly code: RenderServiceErrorCode;
|
|
63
|
-
constructor(message
|
|
65
|
+
constructor({ message, code }: {
|
|
66
|
+
message: string;
|
|
67
|
+
code: RenderServiceErrorCode;
|
|
68
|
+
});
|
|
64
69
|
}
|
|
65
70
|
export interface RenderService {
|
|
66
|
-
renderToPdf(html
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
renderToPdf({ html }: {
|
|
72
|
+
html: string;
|
|
73
|
+
}, options?: RenderToPdfOptions): Promise<Uint8Array>;
|
|
74
|
+
capture({ html }: {
|
|
75
|
+
html: string;
|
|
76
|
+
}, options?: CaptureOptions): Promise<Uint8Array>;
|
|
77
|
+
exportArtifact(requiredArgs: {
|
|
78
|
+
html: string;
|
|
79
|
+
format: string;
|
|
80
|
+
}, options?: Omit<ExportArtifactOptions, 'format'>): Promise<unknown>;
|
|
69
81
|
}
|
|
70
82
|
/** Data-URL-encodes HTML for loading into an offscreen renderer, base64 (not `encodeURIComponent`) to avoid per-platform URL-length/charset surprises with large documents. */
|
|
71
|
-
export declare function htmlToDataUrl(html
|
|
72
|
-
|
|
83
|
+
export declare function htmlToDataUrl({ html }: {
|
|
84
|
+
html: string;
|
|
85
|
+
}): string;
|
|
86
|
+
export declare function isOriginAllowed({ url }: {
|
|
87
|
+
url: string;
|
|
88
|
+
}, { allowedOrigins, allowUnrestrictedNetwork }?: {
|
|
89
|
+
allowedOrigins?: string[] | undefined;
|
|
90
|
+
allowUnrestrictedNetwork?: boolean | undefined;
|
|
91
|
+
}): boolean;
|
|
73
92
|
/**
|
|
74
93
|
* Races a promise against a timeout and an optional `AbortSignal`,
|
|
75
94
|
* normalizing both into `RenderServiceError`. Shared by every adapter so
|
|
76
95
|
* the timeout/abort contract behaves identically regardless of backend.
|
|
77
96
|
*/
|
|
78
|
-
export declare function withRenderTimeout<T>(promise
|
|
97
|
+
export declare function withRenderTimeout<T>({ promise }: {
|
|
98
|
+
promise: Promise<T>;
|
|
99
|
+
}, { timeoutMs, signal }?: {
|
|
100
|
+
timeoutMs?: number | undefined;
|
|
101
|
+
signal?: AbortSignal | undefined;
|
|
102
|
+
}): Promise<T>;
|
|
79
103
|
//# sourceMappingURL=render-service.d.ts.map
|
package/dist/render-service.js
CHANGED
|
@@ -12,23 +12,23 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export class RenderServiceError extends Error {
|
|
14
14
|
code;
|
|
15
|
-
constructor(message, code) {
|
|
15
|
+
constructor({ message, code }) {
|
|
16
16
|
super(message);
|
|
17
17
|
this.name = 'RenderServiceError';
|
|
18
18
|
this.code = code;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
/** Data-URL-encodes HTML for loading into an offscreen renderer, base64 (not `encodeURIComponent`) to avoid per-platform URL-length/charset surprises with large documents. */
|
|
22
|
-
export function htmlToDataUrl(html) {
|
|
22
|
+
export function htmlToDataUrl({ html }) {
|
|
23
23
|
return `data:text/html;base64,${Buffer.from(html, 'utf8').toString('base64')}`;
|
|
24
24
|
}
|
|
25
|
-
export function isOriginAllowed(url, allowedOrigins) {
|
|
26
|
-
if (allowedOrigins == null)
|
|
27
|
-
return true;
|
|
25
|
+
export function isOriginAllowed({ url }, { allowedOrigins, allowUnrestrictedNetwork } = {}) {
|
|
28
26
|
if (url.startsWith('data:') || url.startsWith('about:'))
|
|
29
27
|
return true;
|
|
28
|
+
if (allowedOrigins == null && allowUnrestrictedNetwork === true)
|
|
29
|
+
return true;
|
|
30
30
|
try {
|
|
31
|
-
return allowedOrigins.includes(new URL(url).origin);
|
|
31
|
+
return (allowedOrigins ?? []).includes(new URL(url).origin);
|
|
32
32
|
}
|
|
33
33
|
catch {
|
|
34
34
|
return false;
|
|
@@ -39,9 +39,9 @@ export function isOriginAllowed(url, allowedOrigins) {
|
|
|
39
39
|
* normalizing both into `RenderServiceError`. Shared by every adapter so
|
|
40
40
|
* the timeout/abort contract behaves identically regardless of backend.
|
|
41
41
|
*/
|
|
42
|
-
export async function withRenderTimeout(promise, timeoutMs, signal) {
|
|
42
|
+
export async function withRenderTimeout({ promise }, { timeoutMs, signal } = {}) {
|
|
43
43
|
if (signal?.aborted)
|
|
44
|
-
throw new RenderServiceError('render aborted before starting', 'aborted');
|
|
44
|
+
throw new RenderServiceError({ message: 'render aborted before starting', code: 'aborted' });
|
|
45
45
|
if (timeoutMs == null && signal == null)
|
|
46
46
|
return promise;
|
|
47
47
|
return await new Promise((resolve, reject) => {
|
|
@@ -56,7 +56,7 @@ export async function withRenderTimeout(promise, timeoutMs, signal) {
|
|
|
56
56
|
? null
|
|
57
57
|
: setTimeout(() => {
|
|
58
58
|
settled = true;
|
|
59
|
-
reject(new RenderServiceError(`render timed out after ${timeoutMs}ms`, 'timeout'));
|
|
59
|
+
reject(new RenderServiceError({ message: `render timed out after ${timeoutMs}ms`, code: 'timeout' }));
|
|
60
60
|
}, timeoutMs);
|
|
61
61
|
const onAbort = () => {
|
|
62
62
|
if (settled)
|
|
@@ -64,7 +64,7 @@ export async function withRenderTimeout(promise, timeoutMs, signal) {
|
|
|
64
64
|
settled = true;
|
|
65
65
|
if (timer != null)
|
|
66
66
|
clearTimeout(timer);
|
|
67
|
-
reject(new RenderServiceError('render aborted', 'aborted'));
|
|
67
|
+
reject(new RenderServiceError({ message: 'render aborted', code: 'aborted' }));
|
|
68
68
|
};
|
|
69
69
|
signal?.addEventListener('abort', onAbort, { once: true });
|
|
70
70
|
promise.then((value) => {
|
package/dist/shell.d.ts
CHANGED
|
@@ -12,29 +12,37 @@
|
|
|
12
12
|
* `/api/recent-dirs`, and `/api/dialog/open-folder` as HTTP routes, but
|
|
13
13
|
* those are host-process bridge capabilities (a directory picker, a
|
|
14
14
|
* recent-locations list, a filesystem existence check against the local
|
|
15
|
-
* machine the desktop shell is running on) — `@jini-ai/http` has no
|
|
15
|
+
* machine the desktop shell is running on) — `@jini-ai/http-kit` has no
|
|
16
16
|
* desktop/Electron-bridge concept and never will, so this is where the
|
|
17
17
|
* capability actually belongs: the same `ShellPort` a chat UI's
|
|
18
18
|
* `window.__jini__` bridge already reaches for `openExternal`/`openPath`.
|
|
19
|
-
* See `packages/desktop-host/
|
|
19
|
+
* See `packages/desktop-host/archived provenance ledger`'s dated entry for the full
|
|
20
20
|
* per-adapter provenance, including the one deliberate gap:
|
|
21
21
|
* `recentDirs` has no Tauri equivalent and throws `NotImplementedError`
|
|
22
22
|
* there rather than being silently stubbed to an empty array.
|
|
23
23
|
*/
|
|
24
24
|
export declare class ShellError extends Error {
|
|
25
|
-
constructor(message:
|
|
25
|
+
constructor({ message }: {
|
|
26
|
+
message: string;
|
|
27
|
+
});
|
|
26
28
|
}
|
|
27
29
|
export interface OpenFolderDialogOptions {
|
|
28
30
|
readonly defaultPath?: string;
|
|
29
31
|
}
|
|
30
32
|
export interface ShellPort {
|
|
31
|
-
openExternal(url
|
|
32
|
-
|
|
33
|
+
openExternal({ url }: {
|
|
34
|
+
url: string;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
openPath({ path }: {
|
|
37
|
+
path: string;
|
|
38
|
+
}): Promise<void>;
|
|
33
39
|
/** True if `path` exists on the local filesystem and is a directory; `false` for a missing path, a non-directory (a file), or any other stat failure. Never throws. */
|
|
34
|
-
dirExists(path
|
|
40
|
+
dirExists({ path }: {
|
|
41
|
+
path: string;
|
|
42
|
+
}): Promise<boolean>;
|
|
35
43
|
/** Host-tracked recently-opened locations, most-recent first. Electron backs this with `app.getRecentDocuments()`; Tauri has no equivalent (see module doc) and rejects with `NotImplementedError`. */
|
|
36
44
|
recentDirs(): Promise<string[]>;
|
|
37
45
|
/** Opens a native "choose a folder" dialog. Resolves to the chosen absolute path, or `null` if the user canceled. */
|
|
38
|
-
openFolderDialog(options?: OpenFolderDialogOptions): Promise<string | null>;
|
|
46
|
+
openFolderDialog(requiredArgs: Record<string, never>, options?: OpenFolderDialogOptions): Promise<string | null>;
|
|
39
47
|
}
|
|
40
48
|
//# sourceMappingURL=shell.d.ts.map
|
package/dist/shell.js
CHANGED
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
* `/api/recent-dirs`, and `/api/dialog/open-folder` as HTTP routes, but
|
|
13
13
|
* those are host-process bridge capabilities (a directory picker, a
|
|
14
14
|
* recent-locations list, a filesystem existence check against the local
|
|
15
|
-
* machine the desktop shell is running on) — `@jini-ai/http` has no
|
|
15
|
+
* machine the desktop shell is running on) — `@jini-ai/http-kit` has no
|
|
16
16
|
* desktop/Electron-bridge concept and never will, so this is where the
|
|
17
17
|
* capability actually belongs: the same `ShellPort` a chat UI's
|
|
18
18
|
* `window.__jini__` bridge already reaches for `openExternal`/`openPath`.
|
|
19
|
-
* See `packages/desktop-host/
|
|
19
|
+
* See `packages/desktop-host/archived provenance ledger`'s dated entry for the full
|
|
20
20
|
* per-adapter provenance, including the one deliberate gap:
|
|
21
21
|
* `recentDirs` has no Tauri equivalent and throws `NotImplementedError`
|
|
22
22
|
* there rather than being silently stubbed to an empty array.
|
|
23
23
|
*/
|
|
24
24
|
export class ShellError extends Error {
|
|
25
|
-
constructor(message) {
|
|
25
|
+
constructor({ message }) {
|
|
26
26
|
super(message);
|
|
27
27
|
this.name = 'ShellError';
|
|
28
28
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Tracks unfinished work and gates graceful shutdown without depending on a desktop backend. */
|
|
2
|
+
/**
|
|
3
|
+
* A repeated quit during the drain must be prevented and dropped. Letting a second attempt
|
|
4
|
+
* through before asynchronous shutdown finishes can orphan detached child processes.
|
|
5
|
+
* Hold even if nothingToDrain has become true: resource registries can empty as children exit
|
|
6
|
+
* while other teardown work is still pending. The drain's own final quit proceeds only after
|
|
7
|
+
* the phase becomes drained; the host supplies a force-exit deadline for a hung drain.
|
|
8
|
+
*/
|
|
9
|
+
type QuitPhase = "idle" | "draining" | "drained";
|
|
10
|
+
type BeforeQuitAction = "proceed" | "drain" | "hold";
|
|
11
|
+
interface BeforeQuitInput {
|
|
12
|
+
phase: QuitPhase;
|
|
13
|
+
nothingToDrain: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Decide whether to proceed, drain or hold; an in-progress drain always holds repeated quit attempts. Throws for an unknown phase. @complexity O(1). */
|
|
16
|
+
declare function decideBeforeQuit(input: BeforeQuitInput): BeforeQuitAction;
|
|
17
|
+
export { decideBeforeQuit };
|
|
18
|
+
export type { BeforeQuitAction, BeforeQuitInput, QuitPhase };
|
|
19
|
+
//# sourceMappingURL=quit-drain-gate.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Decide whether to proceed, drain or hold; an in-progress drain always holds repeated quit attempts. Throws for an unknown phase. @complexity O(1). */
|
|
2
|
+
function decideBeforeQuit(input) {
|
|
3
|
+
switch (input.phase) {
|
|
4
|
+
case "idle":
|
|
5
|
+
return input.nothingToDrain ? "proceed" : "drain";
|
|
6
|
+
case "draining":
|
|
7
|
+
return "hold";
|
|
8
|
+
case "drained":
|
|
9
|
+
return "proceed";
|
|
10
|
+
default:
|
|
11
|
+
throw new TypeError(`decideBeforeQuit: unknown quit phase ${JSON.stringify(input.phase)}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { decideBeforeQuit };
|
|
15
|
+
//# sourceMappingURL=quit-drain-gate.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Tracks unfinished work and gates graceful shutdown without depending on a desktop backend. */
|
|
2
|
+
/**
|
|
3
|
+
* Chromium's POSIX quit handler is one-shot: it resets the signal to its default disposition,
|
|
4
|
+
* so a second copy can kill the process during the first copy's graceful drain. Launchers can
|
|
5
|
+
* deliver duplicates through process-group signaling and forwarding by wrapper processes.
|
|
6
|
+
* Persistent listeners absorb those copies; request quit only once to avoid re-entering shutdown.
|
|
7
|
+
* Register after app readiness because Chromium installs its handler after module loading and
|
|
8
|
+
* can replace listeners installed earlier. Absorbing repeats also removes their accidental escape
|
|
9
|
+
* hatch for a hung drain, so the first signal must arm a bounded force-exit deadline.
|
|
10
|
+
*/
|
|
11
|
+
declare const QUIT_SIGNALS: readonly NodeJS.Signals[];
|
|
12
|
+
type QuitTimer = (args: {
|
|
13
|
+
fn: () => void;
|
|
14
|
+
ms: number;
|
|
15
|
+
}) => {
|
|
16
|
+
unref?: () => void;
|
|
17
|
+
};
|
|
18
|
+
interface QuitSignalInput {
|
|
19
|
+
processLike: {
|
|
20
|
+
on(args: {
|
|
21
|
+
signal: NodeJS.Signals;
|
|
22
|
+
listener: () => void;
|
|
23
|
+
}): unknown;
|
|
24
|
+
};
|
|
25
|
+
quit: () => void;
|
|
26
|
+
forceExit: () => void;
|
|
27
|
+
deadlineMs: number;
|
|
28
|
+
}
|
|
29
|
+
interface QuitSignalOptions {
|
|
30
|
+
setTimer?: QuitTimer;
|
|
31
|
+
}
|
|
32
|
+
/** Register persistent signal listeners. The first signal arms an unreferenced force-exit deadline and requests graceful quit exactly once. Register after the host is ready. @complexity O(1). */
|
|
33
|
+
declare function routeQuitSignals(input: QuitSignalInput, options?: QuitSignalOptions): void;
|
|
34
|
+
export { routeQuitSignals, QUIT_SIGNALS };
|
|
35
|
+
export type { QuitSignalInput, QuitSignalOptions, QuitTimer };
|
|
36
|
+
//# sourceMappingURL=quit-signals.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Tracks unfinished work and gates graceful shutdown without depending on a desktop backend. */
|
|
2
|
+
/**
|
|
3
|
+
* Chromium's POSIX quit handler is one-shot: it resets the signal to its default disposition,
|
|
4
|
+
* so a second copy can kill the process during the first copy's graceful drain. Launchers can
|
|
5
|
+
* deliver duplicates through process-group signaling and forwarding by wrapper processes.
|
|
6
|
+
* Persistent listeners absorb those copies; request quit only once to avoid re-entering shutdown.
|
|
7
|
+
* Register after app readiness because Chromium installs its handler after module loading and
|
|
8
|
+
* can replace listeners installed earlier. Absorbing repeats also removes their accidental escape
|
|
9
|
+
* hatch for a hung drain, so the first signal must arm a bounded force-exit deadline.
|
|
10
|
+
*/
|
|
11
|
+
const QUIT_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
12
|
+
/** Register persistent signal listeners. The first signal arms an unreferenced force-exit deadline and requests graceful quit exactly once. Register after the host is ready. @complexity O(1). */
|
|
13
|
+
function routeQuitSignals(input, options = {}) {
|
|
14
|
+
const setTimer = options.setTimer ?? (({ fn, ms }) => setTimeout(fn, ms));
|
|
15
|
+
let requested = false;
|
|
16
|
+
const onSignal = () => {
|
|
17
|
+
if (requested)
|
|
18
|
+
return;
|
|
19
|
+
requested = true;
|
|
20
|
+
setTimer({ fn: input.forceExit, ms: input.deadlineMs }).unref?.();
|
|
21
|
+
input.quit();
|
|
22
|
+
};
|
|
23
|
+
for (const signal of QUIT_SIGNALS)
|
|
24
|
+
input.processLike.on({ signal, listener: onSignal });
|
|
25
|
+
}
|
|
26
|
+
export { routeQuitSignals, QUIT_SIGNALS };
|
|
27
|
+
//# sourceMappingURL=quit-signals.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Tracks unfinished work and gates graceful shutdown without depending on a desktop backend. */
|
|
2
|
+
/**
|
|
3
|
+
* Removing a closed window/resource from the live registry does not mean its async teardown
|
|
4
|
+
* has finished. Quitting from an empty registry can abandon that work and leave detached child
|
|
5
|
+
* processes alive, especially when their crash-recovery entry has already been removed.
|
|
6
|
+
* Track promises separately from live resources so shutdown can still see that in-flight work.
|
|
7
|
+
*/
|
|
8
|
+
interface ShutdownTracker {
|
|
9
|
+
track({ promise }: {
|
|
10
|
+
promise: PromiseLike<unknown>;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
readonly size: number;
|
|
13
|
+
drain(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/** Create an isolated tracker. Rejected teardowns settle normally; drain also awaits work added during draining. @complexity O(1) construction; O(n) pending work per drain snapshot. */
|
|
16
|
+
declare function createShutdownTracker(_required: Record<string, never>): ShutdownTracker;
|
|
17
|
+
export { createShutdownTracker };
|
|
18
|
+
export type { ShutdownTracker };
|
|
19
|
+
//# sourceMappingURL=shutdown-tracker.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Create an isolated tracker. Rejected teardowns settle normally; drain also awaits work added during draining. @complexity O(1) construction; O(n) pending work per drain snapshot. */
|
|
2
|
+
function createShutdownTracker(_required) {
|
|
3
|
+
const pending = new Set();
|
|
4
|
+
return {
|
|
5
|
+
track({ promise }) {
|
|
6
|
+
// A failed logout/stop must still be waited for, but must not make graceful quit reject
|
|
7
|
+
// and hang: that would be worse than the unfinished-resource leak this tracker prevents.
|
|
8
|
+
const settled = Promise.resolve(promise).then(() => { }, () => { });
|
|
9
|
+
pending.add(settled);
|
|
10
|
+
void settled.then(() => pending.delete(settled));
|
|
11
|
+
return settled;
|
|
12
|
+
},
|
|
13
|
+
get size() {
|
|
14
|
+
return pending.size;
|
|
15
|
+
},
|
|
16
|
+
async drain() {
|
|
17
|
+
// Waiting for one teardown can let another closed-handler enqueue work. A single snapshot
|
|
18
|
+
// would miss it; every iteration awaits real pending promises rather than spinning.
|
|
19
|
+
while (pending.size > 0) {
|
|
20
|
+
await Promise.all([...pending]);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { createShutdownTracker };
|
|
26
|
+
//# sourceMappingURL=shutdown-tracker.js.map
|
package/dist/sidecar.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export interface SidecarProcessHandle {
|
|
2
2
|
readonly pid: number | undefined;
|
|
3
|
-
onExit(listener
|
|
4
|
-
|
|
3
|
+
onExit({ listener }: {
|
|
4
|
+
listener: (args: {
|
|
5
|
+
code: number | null;
|
|
6
|
+
signal: NodeJS.Signals | null;
|
|
7
|
+
}) => void;
|
|
8
|
+
}): void;
|
|
9
|
+
kill(requiredArgs: Record<string, never>, optionalArgs?: {
|
|
10
|
+
signal?: NodeJS.Signals;
|
|
11
|
+
}): boolean;
|
|
5
12
|
}
|
|
6
13
|
export interface SidecarLaunchOptions {
|
|
7
14
|
command: string;
|
|
@@ -12,7 +19,9 @@ export interface SidecarLaunchOptions {
|
|
|
12
19
|
}
|
|
13
20
|
export interface SidecarReadyOptions<T> {
|
|
14
21
|
probe: () => Promise<T>;
|
|
15
|
-
isReady: (
|
|
22
|
+
isReady: (args: {
|
|
23
|
+
status: T;
|
|
24
|
+
}) => boolean;
|
|
16
25
|
timeoutMs?: number;
|
|
17
26
|
pollIntervalMs?: number;
|
|
18
27
|
}
|
|
@@ -23,12 +32,15 @@ export interface SidecarShutdownOptions {
|
|
|
23
32
|
export interface SidecarHandle {
|
|
24
33
|
readonly process: SidecarProcessHandle;
|
|
25
34
|
readonly logPath: string | null;
|
|
26
|
-
waitUntilReady<T>(
|
|
27
|
-
shutdown(options?: SidecarShutdownOptions): Promise<void>;
|
|
35
|
+
waitUntilReady<T>(requiredArgs: Pick<SidecarReadyOptions<T>, 'probe' | 'isReady'>, optionalArgs?: Omit<SidecarReadyOptions<T>, 'probe' | 'isReady'>): Promise<T>;
|
|
36
|
+
shutdown(requiredArgs: Record<string, never>, options?: SidecarShutdownOptions): Promise<void>;
|
|
28
37
|
}
|
|
29
38
|
export interface SidecarLauncherPort {
|
|
30
|
-
launch(
|
|
39
|
+
launch(requiredArgs: Pick<SidecarLaunchOptions, 'command'>, optionalArgs?: Omit<SidecarLaunchOptions, 'command'>): Promise<SidecarHandle>;
|
|
31
40
|
}
|
|
32
|
-
export declare function createNodeSidecarLauncher(): SidecarLauncherPort;
|
|
33
|
-
export declare function appendSidecarLifecycleLog(logPath
|
|
41
|
+
export declare function createNodeSidecarLauncher(_requiredArgs: Record<string, never>): SidecarLauncherPort;
|
|
42
|
+
export declare function appendSidecarLifecycleLog({ logPath, message }: {
|
|
43
|
+
logPath: string;
|
|
44
|
+
message: string;
|
|
45
|
+
}): Promise<void>;
|
|
34
46
|
//# sourceMappingURL=sidecar.d.ts.map
|
package/dist/sidecar.js
CHANGED
|
@@ -40,31 +40,47 @@ async function waitForProcessExit(child, timeoutMs) {
|
|
|
40
40
|
async function waitUntilReady(child, logPath, options) {
|
|
41
41
|
const timeoutMs = options.timeoutMs ?? DEFAULT_READY_TIMEOUT_MS;
|
|
42
42
|
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
43
|
-
const startedAt = Date.now();
|
|
44
43
|
let lastError;
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
const exitError = (code, signal) => new Error(`sidecar exited before reporting ready (code=${code}, signal=${signal ?? 'none'})${logPath == null ? '' : `; see ${logPath} for details`}`);
|
|
45
|
+
const timeoutError = () => new Error(`timed out waiting for sidecar to become ready${lastError instanceof Error ? ` (${lastError.message})` : ''}`);
|
|
46
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
47
|
+
throw exitError(child.exitCode, child.signalCode);
|
|
48
|
+
if (timeoutMs <= 0)
|
|
49
|
+
throw timeoutError();
|
|
50
|
+
let onExit;
|
|
51
|
+
const exited = new Promise((_resolve, reject) => {
|
|
52
|
+
onExit = (code, signal) => reject(exitError(code, signal));
|
|
53
|
+
child.once('exit', onExit);
|
|
54
|
+
});
|
|
55
|
+
let timer;
|
|
56
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
57
|
+
timer = setTimeout(() => reject(timeoutError()), timeoutMs);
|
|
58
|
+
});
|
|
59
|
+
let stopped = false;
|
|
60
|
+
const controller = new AbortController();
|
|
61
|
+
const poll = async () => {
|
|
62
|
+
while (!stopped) {
|
|
55
63
|
try {
|
|
56
64
|
const status = await options.probe();
|
|
57
|
-
if (options.isReady(status))
|
|
65
|
+
if (!stopped && options.isReady({ status }))
|
|
58
66
|
return status;
|
|
59
67
|
}
|
|
60
68
|
catch (error) {
|
|
61
69
|
lastError = error;
|
|
62
70
|
}
|
|
63
|
-
|
|
71
|
+
if (!stopped)
|
|
72
|
+
await sleep(pollIntervalMs, undefined, { signal: controller.signal });
|
|
64
73
|
}
|
|
65
|
-
throw
|
|
74
|
+
throw timeoutError();
|
|
75
|
+
};
|
|
76
|
+
try {
|
|
77
|
+
// Race the whole polling task, including a probe or sleep that has not settled yet.
|
|
78
|
+
return await Promise.race([exited, deadline, poll()]);
|
|
66
79
|
}
|
|
67
80
|
finally {
|
|
81
|
+
stopped = true;
|
|
82
|
+
controller.abort();
|
|
83
|
+
clearTimeout(timer);
|
|
68
84
|
child.off('exit', onExit);
|
|
69
85
|
}
|
|
70
86
|
}
|
|
@@ -89,9 +105,10 @@ async function openLogHandle(logPath) {
|
|
|
89
105
|
await mkdir(dirname(logPath), { recursive: true });
|
|
90
106
|
return await open(logPath, 'a');
|
|
91
107
|
}
|
|
92
|
-
export function createNodeSidecarLauncher() {
|
|
108
|
+
export function createNodeSidecarLauncher(_requiredArgs) {
|
|
93
109
|
return {
|
|
94
|
-
async launch(
|
|
110
|
+
async launch(requiredArgs, optionalArgs = {}) {
|
|
111
|
+
const options = { ...optionalArgs, ...requiredArgs };
|
|
95
112
|
const logHandle = await openLogHandle(options.logPath);
|
|
96
113
|
const child = spawn(options.command, options.args ?? [], {
|
|
97
114
|
cwd: options.cwd,
|
|
@@ -104,18 +121,18 @@ export function createNodeSidecarLauncher() {
|
|
|
104
121
|
});
|
|
105
122
|
const processHandle = {
|
|
106
123
|
pid: child.pid,
|
|
107
|
-
onExit(listener) {
|
|
108
|
-
child.on('exit', listener);
|
|
124
|
+
onExit({ listener }) {
|
|
125
|
+
child.on('exit', (code, signal) => listener({ code, signal }));
|
|
109
126
|
},
|
|
110
|
-
kill(signal) {
|
|
127
|
+
kill(_requiredArgs, { signal } = {}) {
|
|
111
128
|
return child.kill(signal);
|
|
112
129
|
},
|
|
113
130
|
};
|
|
114
131
|
return {
|
|
115
132
|
process: processHandle,
|
|
116
133
|
logPath: options.logPath ?? null,
|
|
117
|
-
waitUntilReady: (
|
|
118
|
-
async shutdown(shutdownOptions) {
|
|
134
|
+
waitUntilReady: (requiredArgs, optionalArgs = {}) => waitUntilReady(child, options.logPath ?? null, { ...optionalArgs, ...requiredArgs }),
|
|
135
|
+
async shutdown(_requiredArgs, shutdownOptions) {
|
|
119
136
|
try {
|
|
120
137
|
await shutdownChild(child, shutdownOptions);
|
|
121
138
|
}
|
|
@@ -127,7 +144,7 @@ export function createNodeSidecarLauncher() {
|
|
|
127
144
|
},
|
|
128
145
|
};
|
|
129
146
|
}
|
|
130
|
-
export async function appendSidecarLifecycleLog(logPath, message) {
|
|
147
|
+
export async function appendSidecarLifecycleLog({ logPath, message }) {
|
|
131
148
|
await mkdir(dirname(logPath), { recursive: true });
|
|
132
149
|
await appendFile(logPath, `${message}\n`, 'utf8').catch(() => undefined);
|
|
133
150
|
}
|
|
@@ -7,12 +7,21 @@
|
|
|
7
7
|
export interface SingleInstanceApp {
|
|
8
8
|
requestSingleInstanceLock(): boolean;
|
|
9
9
|
quit(): void;
|
|
10
|
-
onSecondInstance(listener
|
|
10
|
+
onSecondInstance({ listener }: {
|
|
11
|
+
listener: () => void;
|
|
12
|
+
}): void;
|
|
11
13
|
}
|
|
12
14
|
/** Bound to one host app instance, matching how `WindowLifecyclePort`/`ProtocolHandlerPort` are bound at construction rather than taking the host handle per call. */
|
|
13
15
|
export interface SingleInstanceLockPort {
|
|
14
|
-
claim(onSecondInstance
|
|
16
|
+
claim({ onSecondInstance }: {
|
|
17
|
+
onSecondInstance: () => void;
|
|
18
|
+
}): boolean;
|
|
15
19
|
}
|
|
16
|
-
export declare function claimSingleInstanceLock(app
|
|
17
|
-
|
|
20
|
+
export declare function claimSingleInstanceLock({ app, onSecondInstance }: {
|
|
21
|
+
app: SingleInstanceApp;
|
|
22
|
+
onSecondInstance: () => void;
|
|
23
|
+
}): boolean;
|
|
24
|
+
export declare function createSingleInstanceLockPort({ app }: {
|
|
25
|
+
app: SingleInstanceApp;
|
|
26
|
+
}): SingleInstanceLockPort;
|
|
18
27
|
//# sourceMappingURL=single-instance.d.ts.map
|
package/dist/single-instance.js
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* original was its name and the namespace-scoped paths threaded alongside it
|
|
5
5
|
* elsewhere in that file. The lock mechanism itself was already generic.
|
|
6
6
|
*/
|
|
7
|
-
export function claimSingleInstanceLock(app, onSecondInstance) {
|
|
7
|
+
export function claimSingleInstanceLock({ app, onSecondInstance }) {
|
|
8
8
|
if (!app.requestSingleInstanceLock()) {
|
|
9
9
|
app.quit();
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
-
app.onSecondInstance(onSecondInstance);
|
|
12
|
+
app.onSecondInstance({ listener: onSecondInstance });
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
|
-
export function createSingleInstanceLockPort(app) {
|
|
16
|
-
return { claim: (onSecondInstance) => claimSingleInstanceLock(app, onSecondInstance) };
|
|
15
|
+
export function createSingleInstanceLockPort({ app }) {
|
|
16
|
+
return { claim: ({ onSecondInstance }) => claimSingleInstanceLock({ app, onSecondInstance }) };
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=single-instance.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Get both IPC channel names from a required, caller-owned namespace. */
|
|
2
|
+
export declare function speechChannels({ channelNamespace }: {
|
|
3
|
+
channelNamespace: string;
|
|
4
|
+
}): {
|
|
5
|
+
isAvailable: string;
|
|
6
|
+
transcribe: string;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=channels.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Get both IPC channel names from a required, caller-owned namespace. */
|
|
2
|
+
export function speechChannels({ channelNamespace }) {
|
|
3
|
+
return { isAvailable: `${channelNamespace}:isAvailable`, transcribe: `${channelNamespace}:transcribe` };
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=channels.js.map
|