@inflatable-cookie/longhorn-tauri 0.7.0 → 0.7.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/dist/bridge-events.d.ts +43 -0
- package/dist/bridge-events.js +160 -0
- package/dist/bridge.d.ts +31 -0
- package/dist/bridge.js +59 -0
- package/dist/history-tree.d.ts +14 -0
- package/dist/history-tree.js +26 -0
- package/dist/history.d.ts +11 -0
- package/dist/history.js +18 -0
- package/dist/licence.d.ts +20 -0
- package/dist/licence.js +31 -0
- package/dist/native-content.d.ts +12 -0
- package/dist/native-content.js +22 -0
- package/dist/notifications.d.ts +10 -0
- package/dist/notifications.js +16 -0
- package/dist/operation.d.ts +11 -0
- package/dist/operation.js +18 -0
- package/dist/transport/events.d.ts +5 -0
- package/dist/transport/events.js +22 -0
- package/dist/transport/index.d.ts +12 -0
- package/dist/transport/index.js +59 -0
- package/dist/update.d.ts +24 -0
- package/dist/update.js +46 -0
- package/package.json +40 -37
- package/src/bridge-events.ts +0 -215
- package/src/bridge.ts +0 -93
- package/src/history-tree.ts +0 -33
- package/src/history.ts +0 -29
- package/src/licence.ts +0 -51
- package/src/native-content.ts +0 -37
- package/src/notifications.ts +0 -29
- package/src/operation.ts +0 -29
- package/src/transport/events.ts +0 -36
- package/src/transport/index.ts +0 -74
- package/src/update.ts +0 -73
package/src/operation.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
-
import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
3
|
-
|
|
4
|
-
import type { OperationPort } from "@inflatable-cookie/longhorn/operation";
|
|
5
|
-
|
|
6
|
-
export const OPERATION_SNAPSHOT_COMMAND = "longhorn_operation_snapshot";
|
|
7
|
-
export const OPERATION_MUTATE_COMMAND = "longhorn_operation_mutate";
|
|
8
|
-
export const OPERATION_CANCEL_COMMAND = "longhorn_operation_cancel";
|
|
9
|
-
export const OPERATION_CHANGED_EVENT = "longhorn://operation/changed";
|
|
10
|
-
|
|
11
|
-
export interface TauriOperationPortOptions {
|
|
12
|
-
readonly transport: InvokeTransport;
|
|
13
|
-
readonly nextRequestId: () => string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function createTauriOperationPort(options: TauriOperationPortOptions): OperationPort {
|
|
17
|
-
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
18
|
-
return {
|
|
19
|
-
snapshot: (query) => options.transport.invoke(OPERATION_SNAPSHOT_COMMAND, { query }),
|
|
20
|
-
mutate: (command) => options.transport.invoke(OPERATION_MUTATE_COMMAND, { command }),
|
|
21
|
-
cancel: (command) => options.transport.invoke(OPERATION_CANCEL_COMMAND, { command }),
|
|
22
|
-
listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
|
|
23
|
-
nextRequestId: options.nextRequestId,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function listenChanged(transport: EventTransport, listener: (event: unknown) => void) {
|
|
28
|
-
return transport.listen(OPERATION_CHANGED_EVENT, listener);
|
|
29
|
-
}
|
package/src/transport/events.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { listen } from "@tauri-apps/api/event";
|
|
2
|
-
import type { Options } from "@tauri-apps/api/event";
|
|
3
|
-
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
EventListenOptions,
|
|
7
|
-
EventTransport,
|
|
8
|
-
Unlisten,
|
|
9
|
-
} from "@inflatable-cookie/longhorn/core";
|
|
10
|
-
|
|
11
|
-
import { TauriTransport } from "./index.ts";
|
|
12
|
-
|
|
13
|
-
/// Optional raw Tauri invoke/listen edge.
|
|
14
|
-
export class TauriEventTransport extends TauriTransport implements EventTransport {
|
|
15
|
-
async listen(
|
|
16
|
-
event: string,
|
|
17
|
-
listener: (payload: unknown) => void,
|
|
18
|
-
options?: EventListenOptions,
|
|
19
|
-
): Promise<Unlisten> {
|
|
20
|
-
if (options?.scope === "renderer-local") {
|
|
21
|
-
const webview = window;
|
|
22
|
-
const receive = (message: Event): void => {
|
|
23
|
-
if ("detail" in message) {
|
|
24
|
-
listener(message.detail);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
webview.addEventListener(event, receive);
|
|
28
|
-
return () => webview.removeEventListener(event, receive);
|
|
29
|
-
}
|
|
30
|
-
const tauriOptions: Options | undefined =
|
|
31
|
-
options?.scope === "current-webview"
|
|
32
|
-
? { target: { kind: "WebviewWindow", label: getCurrentWebviewWindow().label } }
|
|
33
|
-
: undefined;
|
|
34
|
-
return listen(event, ({ payload }) => listener(payload), tauriOptions);
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/transport/index.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Channel, invoke } from "@tauri-apps/api/core";
|
|
2
|
-
|
|
3
|
-
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
4
|
-
|
|
5
|
-
/** An operational error returned by a Tauri host adapter. */
|
|
6
|
-
export class TauriHostError extends Error {
|
|
7
|
-
constructor(
|
|
8
|
-
readonly code: string,
|
|
9
|
-
message: string,
|
|
10
|
-
readonly retryable: boolean,
|
|
11
|
-
) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.name = "TauriHostError";
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class TauriTransport implements InvokeTransport {
|
|
18
|
-
async invoke(command: string, arguments_: Record<string, unknown>): Promise<unknown> {
|
|
19
|
-
try {
|
|
20
|
-
return await invoke(command, arguments_);
|
|
21
|
-
} catch (error) {
|
|
22
|
-
if (isHostErrorEnvelope(error)) {
|
|
23
|
-
throw new TauriHostError(error.code, error.message, error.retryable);
|
|
24
|
-
}
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Invokes a command with a channel for its live progress. */
|
|
30
|
-
async invokeWithProgress(
|
|
31
|
-
command: string,
|
|
32
|
-
arguments_: Record<string, unknown>,
|
|
33
|
-
listener: (event: unknown) => void,
|
|
34
|
-
): Promise<unknown> {
|
|
35
|
-
const onProgress = new Channel(listener);
|
|
36
|
-
try {
|
|
37
|
-
return await this.invoke(command, { ...arguments_, onProgress });
|
|
38
|
-
} finally {
|
|
39
|
-
// A rejected invoke may never create a Rust channel to close the callback.
|
|
40
|
-
const internals: unknown = "__TAURI_INTERNALS__" in window && window.__TAURI_INTERNALS__;
|
|
41
|
-
if (hasCallbackCleanup(internals)) {
|
|
42
|
-
internals.unregisterCallback(onProgress.id);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isHostErrorEnvelope(
|
|
49
|
-
value: unknown,
|
|
50
|
-
): value is Pick<TauriHostError, "code" | "message" | "retryable"> {
|
|
51
|
-
return (
|
|
52
|
-
typeof value === "object" &&
|
|
53
|
-
value !== null &&
|
|
54
|
-
Object.keys(value).length === 3 &&
|
|
55
|
-
Object.hasOwn(value, "code") &&
|
|
56
|
-
Object.hasOwn(value, "message") &&
|
|
57
|
-
Object.hasOwn(value, "retryable") &&
|
|
58
|
-
"code" in value &&
|
|
59
|
-
typeof value.code === "string" &&
|
|
60
|
-
"message" in value &&
|
|
61
|
-
typeof value.message === "string" &&
|
|
62
|
-
"retryable" in value &&
|
|
63
|
-
typeof value.retryable === "boolean"
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function hasCallbackCleanup(value: unknown): value is { unregisterCallback(id: number): void } {
|
|
68
|
-
return (
|
|
69
|
-
typeof value === "object" &&
|
|
70
|
-
value !== null &&
|
|
71
|
-
"unregisterCallback" in value &&
|
|
72
|
-
typeof value.unregisterCallback === "function"
|
|
73
|
-
);
|
|
74
|
-
}
|
package/src/update.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
-
import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
3
|
-
import type {
|
|
4
|
-
UpdateApplyCommand,
|
|
5
|
-
UpdateCancelCommand,
|
|
6
|
-
UpdateCheckCommand,
|
|
7
|
-
UpdateDeferCommand,
|
|
8
|
-
UpdatePort,
|
|
9
|
-
UpdatePrepareCommand,
|
|
10
|
-
UpdateSelectChannelCommand,
|
|
11
|
-
UpdateUnlisten,
|
|
12
|
-
} from "@inflatable-cookie/longhorn/update";
|
|
13
|
-
import type { TauriTransport } from "./transport/index.ts";
|
|
14
|
-
export const UPDATE_SNAPSHOT_COMMAND = "longhorn_update_snapshot";
|
|
15
|
-
export const UPDATE_CHECK_COMMAND = "longhorn_update_check";
|
|
16
|
-
export const UPDATE_SELECT_CHANNEL_COMMAND = "longhorn_update_select_channel";
|
|
17
|
-
export const UPDATE_DEFER_COMMAND = "longhorn_update_defer";
|
|
18
|
-
export const UPDATE_PREPARE_COMMAND = "longhorn_update_prepare";
|
|
19
|
-
export const UPDATE_APPLY_COMMAND = "longhorn_update_apply";
|
|
20
|
-
export const UPDATE_CANCEL_COMMAND = "longhorn_update_cancel";
|
|
21
|
-
export const UPDATE_CHANGED_EVENT = "longhorn://update/changed";
|
|
22
|
-
/**
|
|
23
|
-
* The update seam.
|
|
24
|
-
*
|
|
25
|
-
* Committed changes produce an invalidation hint. Live byte progress arrives
|
|
26
|
-
* on a channel owned by the prepare invocation.
|
|
27
|
-
*
|
|
28
|
-
* Results are `unknown`, as every other raw port's are. What comes back over a
|
|
29
|
-
* transport is untrusted until a validator says otherwise; `UpdateClient` is
|
|
30
|
-
* what narrows them. Commands going *out* are typed, because those this side
|
|
31
|
-
* constructs.
|
|
32
|
-
*/
|
|
33
|
-
export function createTauriUpdatePort(options: {
|
|
34
|
-
readonly transport: InvokeTransport;
|
|
35
|
-
}): UpdatePort {
|
|
36
|
-
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
37
|
-
const transport = options.transport;
|
|
38
|
-
const progress = hasProgress(transport) ? transport : undefined;
|
|
39
|
-
return {
|
|
40
|
-
snapshot: () => transport.invoke(UPDATE_SNAPSHOT_COMMAND, {}),
|
|
41
|
-
check: (command: UpdateCheckCommand) =>
|
|
42
|
-
options.transport.invoke(UPDATE_CHECK_COMMAND, { command }),
|
|
43
|
-
selectChannel: (command: UpdateSelectChannelCommand) =>
|
|
44
|
-
options.transport.invoke(UPDATE_SELECT_CHANNEL_COMMAND, { command }),
|
|
45
|
-
defer: (command: UpdateDeferCommand) =>
|
|
46
|
-
options.transport.invoke(UPDATE_DEFER_COMMAND, { command }),
|
|
47
|
-
prepare: (command: UpdatePrepareCommand) =>
|
|
48
|
-
options.transport.invoke(UPDATE_PREPARE_COMMAND, { command }),
|
|
49
|
-
prepareWithProgress:
|
|
50
|
-
progress === undefined
|
|
51
|
-
? undefined
|
|
52
|
-
: (command, listener) =>
|
|
53
|
-
progress.invokeWithProgress(UPDATE_PREPARE_COMMAND, { command }, listener),
|
|
54
|
-
apply: (command: UpdateApplyCommand) =>
|
|
55
|
-
options.transport.invoke(UPDATE_APPLY_COMMAND, { command }),
|
|
56
|
-
cancel: (command: UpdateCancelCommand) =>
|
|
57
|
-
options.transport.invoke(UPDATE_CANCEL_COMMAND, { command }),
|
|
58
|
-
listen:
|
|
59
|
-
events === undefined
|
|
60
|
-
? undefined
|
|
61
|
-
: (listener) => listen(events, UPDATE_CHANGED_EVENT, listener),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function hasProgress(transport: InvokeTransport): transport is TauriTransport {
|
|
65
|
-
return "invokeWithProgress" in transport && typeof transport.invokeWithProgress === "function";
|
|
66
|
-
}
|
|
67
|
-
function listen(
|
|
68
|
-
events: EventTransport,
|
|
69
|
-
event: string,
|
|
70
|
-
listener: (event: unknown) => void,
|
|
71
|
-
): Promise<UpdateUnlisten> {
|
|
72
|
-
return events.listen(event, listener);
|
|
73
|
-
}
|