@inflatable-cookie/longhorn-tauri 0.5.0 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflatable-cookie/longhorn-tauri",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -74,7 +74,7 @@
74
74
  "LICENSE"
75
75
  ],
76
76
  "peerDependencies": {
77
- "@inflatable-cookie/longhorn": "0.5.0",
77
+ "@inflatable-cookie/longhorn": "0.6.0",
78
78
  "@tauri-apps/api": "^2.10.1"
79
79
  },
80
80
  "sideEffects": false,
@@ -61,9 +61,7 @@ export interface BridgeJobListeners<Progress, Success, Detail> {
61
61
  readonly successCodec: BridgeCodec<Success>;
62
62
  readonly detailCodec: BridgeCodec<Detail>;
63
63
  readonly progress?: (event: BridgeProgressEvent<Progress>) => void;
64
- readonly terminal: (
65
- event: BridgeJobTerminalEvent<Success, Detail>,
66
- ) => void;
64
+ readonly terminal: (event: BridgeJobTerminalEvent<Success, Detail>) => void;
67
65
  /**
68
66
  * Reports a malformed event or a teardown failure, mirroring
69
67
  * `CheckedSnapshotConnection`. A malformed terminal event is the only way
@@ -76,6 +74,11 @@ export interface BridgeJobListeners<Progress, Success, Detail> {
76
74
  /**
77
75
  * Installs request/job-correlated progress and terminal listeners.
78
76
  * Wrong-correlation and post-terminal messages never reach consumers.
77
+ *
78
+ * Contract 010 makes events projections, not durable delivery, and the bridge
79
+ * has no job-status query. A terminal that fires before its listener is
80
+ * registered (the jobId is only known once the job has started) is therefore
81
+ * not recovered here; see docs/knowledge/questions.md.
79
82
  */
80
83
  export async function listenTauriBridgeJob<Progress, Success, Detail>(
81
84
  requestId: BridgeRequestId,
@@ -84,70 +87,109 @@ export async function listenTauriBridgeJob<Progress, Success, Detail>(
84
87
  transport: EventTransport = new TauriEventTransport(),
85
88
  ): Promise<Unlisten> {
86
89
  const tracker = new BridgeJobTracker(requestId, jobId);
87
- let failed = false;
88
- let disposeProgress: Unlisten | undefined;
89
- let disposeTerminal: Unlisten | undefined;
90
+ // Set once the job has failed or been closed. Nothing reaches the consumer
91
+ // after that, and a registration that completes later is released at once.
92
+ let stopped = false;
93
+ let registered = false;
94
+ const unlistens: Array<Unlisten> = [];
90
95
 
91
- const close = async (): Promise<void> => {
92
- const pending = [disposeTerminal, disposeProgress].filter(
93
- (unlisten): unlisten is Unlisten => unlisten !== undefined,
96
+ // Last registered, first released.
97
+ const teardown = async (): Promise<void> => {
98
+ const pending = unlistens.splice(0).reverse();
99
+ const results = await Promise.allSettled(
100
+ pending.map((unlisten) => Promise.resolve().then(() => unlisten())),
94
101
  );
95
- disposeTerminal = undefined;
96
- disposeProgress = undefined;
97
- const results = await Promise.allSettled(pending.map((unlisten) => unlisten()));
98
102
  for (const result of results) {
99
- if (result.status === "rejected") throw result.reason;
103
+ if (result.status === "rejected") {
104
+ throw result.reason;
105
+ }
100
106
  }
101
107
  };
102
108
 
103
- const report = (error: unknown): void => {
104
- if (failed) return;
105
- failed = true;
106
- listeners.onFailure?.({ phase: "event", error });
107
- void close().catch((teardownError) => {
108
- listeners.onFailure?.({ phase: "unlisten", error: teardownError });
109
- });
109
+ const reportUnlistenFailure = (error: unknown): void => {
110
+ try {
111
+ listeners.onFailure?.({ phase: "unlisten", error });
112
+ } catch {
113
+ // A secondary reporter failure cannot replace the original error.
114
+ }
110
115
  };
111
116
 
112
- disposeProgress = await transport.listen(
113
- BRIDGE_PROGRESS_EVENT,
114
- (value) => {
115
- if (failed) return;
116
- try {
117
- const event = parseBridgeProgressEvent(
118
- value,
119
- listeners.progressCodec,
120
- );
121
- if (tracker.classifyProgress(event) === "accept") {
122
- listeners.progress?.(event);
123
- }
124
- } catch (error) {
125
- report(error);
117
+ const notify = (callback: () => void): void => {
118
+ try {
119
+ callback();
120
+ } catch (error) {
121
+ // A transport may deliver inline before returning its unlisten.
122
+ if (registered) {
123
+ throw error;
126
124
  }
127
- },
128
- );
125
+ }
126
+ };
127
+
128
+ const fail = (error: unknown): void => {
129
+ if (stopped) {
130
+ return;
131
+ }
132
+ stopped = true;
133
+ void teardown().catch(reportUnlistenFailure);
134
+ notify(() => listeners.onFailure?.({ phase: "event", error }));
135
+ };
136
+
137
+ const adopt = async (unlisten: Unlisten): Promise<void> => {
138
+ if (!stopped) {
139
+ unlistens.push(unlisten);
140
+ return;
141
+ }
142
+ try {
143
+ await unlisten();
144
+ } catch (error) {
145
+ reportUnlistenFailure(error);
146
+ }
147
+ };
148
+
149
+ const onProgress = (value: unknown): void => {
150
+ if (stopped) {
151
+ return;
152
+ }
153
+ let event: BridgeProgressEvent<Progress>;
154
+ try {
155
+ event = parseBridgeProgressEvent(value, listeners.progressCodec);
156
+ } catch (error) {
157
+ fail(error);
158
+ return;
159
+ }
160
+ if (tracker.classifyProgress(event) === "accept") {
161
+ notify(() => listeners.progress?.(event));
162
+ }
163
+ };
164
+
165
+ const onTerminal = (value: unknown): void => {
166
+ if (stopped) {
167
+ return;
168
+ }
169
+ let event: BridgeJobTerminalEvent<Success, Detail>;
170
+ try {
171
+ event = parseBridgeJobTerminalEvent(value, listeners.successCodec, listeners.detailCodec);
172
+ } catch (error) {
173
+ fail(error);
174
+ return;
175
+ }
176
+ if (tracker.classifyTerminal(event) === "accept") {
177
+ notify(() => listeners.terminal(event));
178
+ }
179
+ };
180
+
181
+ const close = async (): Promise<void> => {
182
+ stopped = true;
183
+ await teardown();
184
+ };
185
+
129
186
  try {
130
- disposeTerminal = await transport.listen(
131
- BRIDGE_TERMINAL_EVENT,
132
- (value) => {
133
- if (failed) return;
134
- try {
135
- const event = parseBridgeJobTerminalEvent(
136
- value,
137
- listeners.successCodec,
138
- listeners.detailCodec,
139
- );
140
- if (tracker.classifyTerminal(event) === "accept") {
141
- listeners.terminal(event);
142
- }
143
- } catch (error) {
144
- report(error);
145
- }
146
- },
147
- );
187
+ await adopt(await transport.listen(BRIDGE_PROGRESS_EVENT, onProgress));
188
+ await adopt(await transport.listen(BRIDGE_TERMINAL_EVENT, onTerminal));
189
+ registered = true;
148
190
  } catch (error) {
149
- await disposeProgress();
150
- disposeProgress = undefined;
191
+ stopped = true;
192
+ await teardown().catch(reportUnlistenFailure);
151
193
  throw error;
152
194
  }
153
195
  return close;
package/src/bridge.ts CHANGED
@@ -9,15 +9,11 @@ import type {
9
9
  import type {
10
10
  BridgeOperationAdapter,
11
11
  BridgeOperationDescriptor,
12
- } from "@inflatable-cookie/longhorn/bridge";
13
- import {
14
- BridgeDomainClient,
15
- } from "@inflatable-cookie/longhorn/bridge";
16
- import type { BridgeNegotiationAdapter } from "@inflatable-cookie/longhorn/bridge";
17
- import {
18
12
  BridgeSession,
19
- BridgeSessionClient,
20
13
  } from "@inflatable-cookie/longhorn/bridge";
14
+ import { BridgeDomainClient } from "@inflatable-cookie/longhorn/bridge";
15
+ import type { BridgeNegotiationAdapter } from "@inflatable-cookie/longhorn/bridge";
16
+ import { BridgeSessionClient } from "@inflatable-cookie/longhorn/bridge";
21
17
 
22
18
  export const BRIDGE_HELLO_COMMAND = "longhorn_bridge_hello";
23
19
  export const BRIDGE_AUTHORITY_COMMAND = "longhorn_bridge_authority";
@@ -32,8 +28,7 @@ export const BRIDGE_RESYNC_COMMAND = "longhorn_bridge_resync";
32
28
  * Domain routes and payload vocabulary arrive only through operation
33
29
  * descriptors owned by adapted domain packages.
34
30
  */
35
- export class TauriBridgeAdapter
36
- implements BridgeNegotiationAdapter, BridgeOperationAdapter {
31
+ export class TauriBridgeAdapter implements BridgeNegotiationAdapter, BridgeOperationAdapter {
37
32
  readonly #transport: InvokeTransport;
38
33
 
39
34
  constructor(transport: InvokeTransport = new TauriTransport()) {
@@ -86,9 +81,7 @@ export async function connectTauriBridge(
86
81
  };
87
82
  }
88
83
 
89
- function commandFor<Request, Reply>(
90
- operation: BridgeOperationDescriptor<Request, Reply>,
91
- ): string {
84
+ function commandFor<Request, Reply>(operation: BridgeOperationDescriptor<Request, Reply>): string {
92
85
  switch (operation.kind) {
93
86
  case "query":
94
87
  return BRIDGE_QUERY_COMMAND;
@@ -1,4 +1,5 @@
1
- import { isEventTransport, type EventTransport, type InvokeTransport } from "@inflatable-cookie/longhorn/core";
1
+ import { isEventTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
3
  import type { ForkHistoryPort } from "@inflatable-cookie/longhorn/history-tree";
3
4
  export const FORK_HISTORY_SNAPSHOT_COMMAND = "longhorn_history_tree_snapshot";
4
5
  export const FORK_HISTORY_PATH_COMMAND = "longhorn_history_tree_path";
@@ -8,18 +9,25 @@ export const FORK_HISTORY_DELETE_COMMAND = "longhorn_history_tree_delete_continu
8
9
  export const FORK_HISTORY_PRUNE_COMMAND = "longhorn_history_tree_prune";
9
10
  export const FORK_HISTORY_NAVIGATE_COMMAND = "longhorn_history_tree_navigate";
10
11
  export const FORK_HISTORY_CHANGED_EVENT = "longhorn://history-tree/changed";
11
- export function createTauriForkHistoryPort(options: { readonly transport: InvokeTransport; readonly nextPlanId: () => string }): ForkHistoryPort {
12
+ export function createTauriForkHistoryPort(options: {
13
+ readonly transport: InvokeTransport;
14
+ readonly nextPlanId: () => string;
15
+ }): ForkHistoryPort {
12
16
  const events = isEventTransport(options.transport) ? options.transport : undefined;
13
17
  return {
14
18
  snapshot: () => options.transport.invoke(FORK_HISTORY_SNAPSHOT_COMMAND, {}),
15
19
  path: (command) => options.transport.invoke(FORK_HISTORY_PATH_COMMAND, { command }),
16
20
  branches: (command) => options.transport.invoke(FORK_HISTORY_BRANCHES_COMMAND, { command }),
17
- continuations: (command) => options.transport.invoke(FORK_HISTORY_CONTINUATIONS_COMMAND, { command }),
18
- deleteContinuation: (command) => options.transport.invoke(FORK_HISTORY_DELETE_COMMAND, { command }),
21
+ continuations: (command) =>
22
+ options.transport.invoke(FORK_HISTORY_CONTINUATIONS_COMMAND, { command }),
23
+ deleteContinuation: (command) =>
24
+ options.transport.invoke(FORK_HISTORY_DELETE_COMMAND, { command }),
19
25
  prune: (command) => options.transport.invoke(FORK_HISTORY_PRUNE_COMMAND, { command }),
20
26
  navigate: (command) => options.transport.invoke(FORK_HISTORY_NAVIGATE_COMMAND, { command }),
21
27
  listen: events === undefined ? undefined : (listener) => listen(events, listener),
22
28
  nextPlanId: options.nextPlanId,
23
29
  };
24
30
  }
25
- function listen(events: EventTransport, listener: (event: unknown) => void) { return events.listen(FORK_HISTORY_CHANGED_EVENT, listener); }
31
+ function listen(events: EventTransport, listener: (event: unknown) => void) {
32
+ return events.listen(FORK_HISTORY_CHANGED_EVENT, listener);
33
+ }
package/src/history.ts CHANGED
@@ -1,8 +1,5 @@
1
- import {
2
- isEventTransport,
3
- type EventTransport,
4
- type InvokeTransport,
5
- } from "@inflatable-cookie/longhorn/core";
1
+ import { isEventTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
6
3
 
7
4
  import type { HistoryPort } from "@inflatable-cookie/longhorn/history";
8
5
 
@@ -16,29 +13,17 @@ export interface TauriHistoryPortOptions {
16
13
  readonly nextPlanId: () => string;
17
14
  }
18
15
 
19
- export function createTauriHistoryPort(
20
- options: TauriHistoryPortOptions,
21
- ): HistoryPort {
22
- const events = isEventTransport(options.transport)
23
- ? options.transport
24
- : undefined;
16
+ export function createTauriHistoryPort(options: TauriHistoryPortOptions): HistoryPort {
17
+ const events = isEventTransport(options.transport) ? options.transport : undefined;
25
18
  return {
26
19
  snapshot: () => options.transport.invoke(HISTORY_SNAPSHOT_COMMAND, {}),
27
- page: (command) =>
28
- options.transport.invoke(HISTORY_PAGE_COMMAND, { command }),
29
- navigate: (command) =>
30
- options.transport.invoke(HISTORY_NAVIGATE_COMMAND, { command }),
31
- listen:
32
- events === undefined
33
- ? undefined
34
- : (listener) => listenChanged(events, listener),
20
+ page: (command) => options.transport.invoke(HISTORY_PAGE_COMMAND, { command }),
21
+ navigate: (command) => options.transport.invoke(HISTORY_NAVIGATE_COMMAND, { command }),
22
+ listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
35
23
  nextPlanId: options.nextPlanId,
36
24
  };
37
25
  }
38
26
 
39
- async function listenChanged(
40
- transport: EventTransport,
41
- listener: (event: unknown) => void,
42
- ) {
27
+ async function listenChanged(transport: EventTransport, listener: (event: unknown) => void) {
43
28
  return transport.listen(HISTORY_CHANGED_EVENT, listener);
44
29
  }
package/src/licence.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { isEventTransport, type EventTransport, type InvokeTransport } from "@inflatable-cookie/longhorn/core";
1
+ import { isEventTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
3
  import type {
3
4
  LicenceActivateCommand,
4
5
  LicenceDeactivateCommand,
@@ -23,16 +24,28 @@ export const LICENCE_CHANGED_EVENT = "longhorn://licence/changed";
23
24
  * Results are `unknown`, as every raw port's are — `LicenceClient` is what
24
25
  * narrows them. Commands going out are typed, because this side builds those.
25
26
  */
26
- export function createTauriLicencePort(options: { readonly transport: InvokeTransport }): LicencePort {
27
+ export function createTauriLicencePort(options: {
28
+ readonly transport: InvokeTransport;
29
+ }): LicencePort {
27
30
  const events = isEventTransport(options.transport) ? options.transport : undefined;
28
31
  return {
29
32
  snapshot: () => options.transport.invoke(LICENCE_SNAPSHOT_COMMAND, {}),
30
- activate: (command: LicenceActivateCommand) => options.transport.invoke(LICENCE_ACTIVATE_COMMAND, { command }),
31
- deactivate: (command: LicenceDeactivateCommand) => options.transport.invoke(LICENCE_DEACTIVATE_COMMAND, { command }),
32
- refresh: (command: LicenceRefreshCommand) => options.transport.invoke(LICENCE_REFRESH_COMMAND, { command }),
33
- releaseSeat: (command: LicenceReleaseSeatCommand) => options.transport.invoke(LICENCE_RELEASE_SEAT_COMMAND, { command }),
34
- renameSeat: (command: LicenceRenameSeatCommand) => options.transport.invoke(LICENCE_RENAME_SEAT_COMMAND, { command }),
33
+ activate: (command: LicenceActivateCommand) =>
34
+ options.transport.invoke(LICENCE_ACTIVATE_COMMAND, { command }),
35
+ deactivate: (command: LicenceDeactivateCommand) =>
36
+ options.transport.invoke(LICENCE_DEACTIVATE_COMMAND, { command }),
37
+ refresh: (command: LicenceRefreshCommand) =>
38
+ options.transport.invoke(LICENCE_REFRESH_COMMAND, { command }),
39
+ releaseSeat: (command: LicenceReleaseSeatCommand) =>
40
+ options.transport.invoke(LICENCE_RELEASE_SEAT_COMMAND, { command }),
41
+ renameSeat: (command: LicenceRenameSeatCommand) =>
42
+ options.transport.invoke(LICENCE_RENAME_SEAT_COMMAND, { command }),
35
43
  listen: events === undefined ? undefined : (listener) => listen(events, listener),
36
44
  };
37
45
  }
38
- function listen(events: EventTransport, listener: (event: unknown) => void): Promise<LicenceUnlisten> { return events.listen(LICENCE_CHANGED_EVENT, listener); }
46
+ function listen(
47
+ events: EventTransport,
48
+ listener: (event: unknown) => void,
49
+ ): Promise<LicenceUnlisten> {
50
+ return events.listen(LICENCE_CHANGED_EVENT, listener);
51
+ }
@@ -1,21 +1,13 @@
1
- import {
2
- isEventTransport,
3
- type EventTransport,
4
- type InvokeTransport,
5
- } from "@inflatable-cookie/longhorn/core";
1
+ import { isEventTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
6
3
 
7
4
  import type { NativeContentPort } from "@inflatable-cookie/longhorn/native-content";
8
5
 
9
- export const NATIVE_CONTENT_CONNECT_COMMAND =
10
- "longhorn_native_content_connect";
11
- export const NATIVE_CONTENT_SNAPSHOT_COMMAND =
12
- "longhorn_native_content_snapshot";
13
- export const NATIVE_CONTENT_UPDATE_DESIRED_COMMAND =
14
- "longhorn_native_content_update_desired";
15
- export const NATIVE_CONTENT_DECIDE_SIZE_COMMAND =
16
- "longhorn_native_content_decide_size";
17
- export const NATIVE_CONTENT_CHANGED_EVENT =
18
- "longhorn://native-content/changed";
6
+ export const NATIVE_CONTENT_CONNECT_COMMAND = "longhorn_native_content_connect";
7
+ export const NATIVE_CONTENT_SNAPSHOT_COMMAND = "longhorn_native_content_snapshot";
8
+ export const NATIVE_CONTENT_UPDATE_DESIRED_COMMAND = "longhorn_native_content_update_desired";
9
+ export const NATIVE_CONTENT_DECIDE_SIZE_COMMAND = "longhorn_native_content_decide_size";
10
+ export const NATIVE_CONTENT_CHANGED_EVENT = "longhorn://native-content/changed";
19
11
 
20
12
  export interface TauriNativeContentPortOptions {
21
13
  readonly transport: InvokeTransport;
@@ -25,31 +17,21 @@ export interface TauriNativeContentPortOptions {
25
17
  export function createTauriNativeContentPort(
26
18
  options: TauriNativeContentPortOptions,
27
19
  ): NativeContentPort {
28
- const events = isEventTransport(options.transport)
29
- ? options.transport
30
- : undefined;
20
+ const events = isEventTransport(options.transport) ? options.transport : undefined;
31
21
  return {
32
- connect: (request) =>
33
- options.transport.invoke(NATIVE_CONTENT_CONNECT_COMMAND, { request }),
34
- snapshot: (request) =>
35
- options.transport.invoke(NATIVE_CONTENT_SNAPSHOT_COMMAND, { request }),
22
+ connect: (request) => options.transport.invoke(NATIVE_CONTENT_CONNECT_COMMAND, { request }),
23
+ snapshot: (request) => options.transport.invoke(NATIVE_CONTENT_SNAPSHOT_COMMAND, { request }),
36
24
  updateDesired: (request) =>
37
25
  options.transport.invoke(NATIVE_CONTENT_UPDATE_DESIRED_COMMAND, {
38
26
  request,
39
27
  }),
40
28
  decideContentSize: (request) =>
41
29
  options.transport.invoke(NATIVE_CONTENT_DECIDE_SIZE_COMMAND, { request }),
42
- listen:
43
- events === undefined
44
- ? undefined
45
- : (listener) => listenChanged(events, listener),
30
+ listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
46
31
  nextRequestId: options.nextRequestId,
47
32
  };
48
33
  }
49
34
 
50
- function listenChanged(
51
- transport: EventTransport,
52
- listener: (event: unknown) => void,
53
- ) {
35
+ function listenChanged(transport: EventTransport, listener: (event: unknown) => void) {
54
36
  return transport.listen(NATIVE_CONTENT_CHANGED_EVENT, listener);
55
37
  }
@@ -1,4 +1,5 @@
1
- import { isEventTransport, type EventTransport, type InvokeTransport } from "@inflatable-cookie/longhorn/core";
1
+ import { isEventTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
3
 
3
4
  import type { NotificationPort } from "@inflatable-cookie/longhorn/notifications";
4
5
 
@@ -11,7 +12,9 @@ export interface TauriNotificationPortOptions {
11
12
  readonly nextRequestId: () => string;
12
13
  }
13
14
 
14
- export function createTauriNotificationPort(options: TauriNotificationPortOptions): NotificationPort {
15
+ export function createTauriNotificationPort(
16
+ options: TauriNotificationPortOptions,
17
+ ): NotificationPort {
15
18
  const events = isEventTransport(options.transport) ? options.transport : undefined;
16
19
  return {
17
20
  snapshot: (query) => options.transport.invoke(NOTIFICATION_SNAPSHOT_COMMAND, { query }),
package/src/operation.ts CHANGED
@@ -1,8 +1,5 @@
1
- import {
2
- isEventTransport,
3
- type EventTransport,
4
- type InvokeTransport,
5
- } from "@inflatable-cookie/longhorn/core";
1
+ import { isEventTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
6
3
 
7
4
  import type { OperationPort } from "@inflatable-cookie/longhorn/operation";
8
5
 
@@ -16,30 +13,17 @@ export interface TauriOperationPortOptions {
16
13
  readonly nextRequestId: () => string;
17
14
  }
18
15
 
19
- export function createTauriOperationPort(
20
- options: TauriOperationPortOptions,
21
- ): OperationPort {
22
- const events = isEventTransport(options.transport)
23
- ? options.transport
24
- : undefined;
16
+ export function createTauriOperationPort(options: TauriOperationPortOptions): OperationPort {
17
+ const events = isEventTransport(options.transport) ? options.transport : undefined;
25
18
  return {
26
- snapshot: (query) =>
27
- options.transport.invoke(OPERATION_SNAPSHOT_COMMAND, { query }),
28
- mutate: (command) =>
29
- options.transport.invoke(OPERATION_MUTATE_COMMAND, { command }),
30
- cancel: (command) =>
31
- options.transport.invoke(OPERATION_CANCEL_COMMAND, { command }),
32
- listen:
33
- events === undefined
34
- ? undefined
35
- : (listener) => listenChanged(events, listener),
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),
36
23
  nextRequestId: options.nextRequestId,
37
24
  };
38
25
  }
39
26
 
40
- function listenChanged(
41
- transport: EventTransport,
42
- listener: (event: unknown) => void,
43
- ) {
27
+ function listenChanged(transport: EventTransport, listener: (event: unknown) => void) {
44
28
  return transport.listen(OPERATION_CHANGED_EVENT, listener);
45
29
  }
@@ -1,17 +1,18 @@
1
1
  import { listen } from "@tauri-apps/api/event";
2
+ import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
2
3
 
3
4
  import type { EventTransport, Unlisten } from "@inflatable-cookie/longhorn/core";
5
+ import { TRANSFER_CLIENT_CHANGED_EVENT } from "@inflatable-cookie/longhorn/transfer";
4
6
 
5
7
  import { TauriTransport } from "./index.ts";
6
8
 
7
9
  /// Optional raw Tauri invoke/listen edge.
8
- export class TauriEventTransport
9
- extends TauriTransport
10
- implements EventTransport {
11
- listen(
12
- event: string,
13
- listener: (payload: unknown) => void,
14
- ): Promise<Unlisten> {
15
- return listen(event, ({ payload }) => listener(payload));
10
+ export class TauriEventTransport extends TauriTransport implements EventTransport {
11
+ listen(event: string, listener: (payload: unknown) => void): Promise<Unlisten> {
12
+ const options =
13
+ event === TRANSFER_CLIENT_CHANGED_EVENT
14
+ ? { target: getCurrentWebviewWindow().label }
15
+ : undefined;
16
+ return listen(event, ({ payload }) => listener(payload), options);
16
17
  }
17
18
  }
@@ -3,10 +3,7 @@ import { invoke } from "@tauri-apps/api/core";
3
3
  import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
4
4
 
5
5
  export class TauriTransport implements InvokeTransport {
6
- invoke(
7
- command: string,
8
- arguments_: Record<string, unknown>,
9
- ): Promise<unknown> {
6
+ invoke(command: string, arguments_: Record<string, unknown>): Promise<unknown> {
10
7
  return invoke(command, arguments_);
11
8
  }
12
9
  }
package/src/update.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { isEventTransport, type EventTransport, type InvokeTransport } from "@inflatable-cookie/longhorn/core";
1
+ import { isEventTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
3
  import type {
3
4
  UpdateApplyCommand,
4
5
  UpdateCancelCommand,
@@ -36,18 +37,38 @@ export const UPDATE_PROGRESS_EVENT = "longhorn://update/progress";
36
37
  * what narrows them. Commands going *out* are typed, because those this side
37
38
  * constructs.
38
39
  */
39
- export function createTauriUpdatePort(options: { readonly transport: InvokeTransport }): UpdatePort {
40
+ export function createTauriUpdatePort(options: {
41
+ readonly transport: InvokeTransport;
42
+ }): UpdatePort {
40
43
  const events = isEventTransport(options.transport) ? options.transport : undefined;
41
44
  return {
42
45
  snapshot: () => options.transport.invoke(UPDATE_SNAPSHOT_COMMAND, {}),
43
- check: (command: UpdateCheckCommand) => options.transport.invoke(UPDATE_CHECK_COMMAND, { command }),
44
- selectChannel: (command: UpdateSelectChannelCommand) => options.transport.invoke(UPDATE_SELECT_CHANNEL_COMMAND, { command }),
45
- defer: (command: UpdateDeferCommand) => options.transport.invoke(UPDATE_DEFER_COMMAND, { command }),
46
- prepare: (command: UpdatePrepareCommand) => options.transport.invoke(UPDATE_PREPARE_COMMAND, { command }),
47
- apply: (command: UpdateApplyCommand) => options.transport.invoke(UPDATE_APPLY_COMMAND, { command }),
48
- cancel: (command: UpdateCancelCommand) => options.transport.invoke(UPDATE_CANCEL_COMMAND, { command }),
49
- listen: events === undefined ? undefined : (listener) => listen(events, UPDATE_CHANGED_EVENT, listener),
50
- listenProgress: events === undefined ? undefined : (listener) => listen(events, UPDATE_PROGRESS_EVENT, listener),
46
+ check: (command: UpdateCheckCommand) =>
47
+ options.transport.invoke(UPDATE_CHECK_COMMAND, { command }),
48
+ selectChannel: (command: UpdateSelectChannelCommand) =>
49
+ options.transport.invoke(UPDATE_SELECT_CHANNEL_COMMAND, { command }),
50
+ defer: (command: UpdateDeferCommand) =>
51
+ options.transport.invoke(UPDATE_DEFER_COMMAND, { command }),
52
+ prepare: (command: UpdatePrepareCommand) =>
53
+ options.transport.invoke(UPDATE_PREPARE_COMMAND, { command }),
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
+ listenProgress:
63
+ events === undefined
64
+ ? undefined
65
+ : (listener) => listen(events, UPDATE_PROGRESS_EVENT, listener),
51
66
  };
52
67
  }
53
- function listen(events: EventTransport, event: string, listener: (event: unknown) => void): Promise<UpdateUnlisten> { return events.listen(event, listener); }
68
+ function listen(
69
+ events: EventTransport,
70
+ event: string,
71
+ listener: (event: unknown) => void,
72
+ ): Promise<UpdateUnlisten> {
73
+ return events.listen(event, listener);
74
+ }