@wailsio/runtime 3.0.0-alpha.72 → 3.0.0-alpha.74

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/types/events.d.ts CHANGED
@@ -1,26 +1,48 @@
1
- export { Types } from "./event_types.js";
1
+ import { Types } from "./event_types.js";
2
+ export * from "./event_types.js";
3
+ /**
4
+ * A table of data types for all known events.
5
+ * Will be monkey-patched by the binding generator.
6
+ */
7
+ export interface CustomEvents {
8
+ }
9
+ /**
10
+ * Either a known event name or an arbitrary string.
11
+ */
12
+ export type WailsEventName<E extends keyof CustomEvents = keyof CustomEvents> = E | (string & {});
13
+ /**
14
+ * Union of all known system event names.
15
+ */
16
+ type SystemEventName = {
17
+ [K in keyof (typeof Types)]: (typeof Types)[K][keyof ((typeof Types)[K])];
18
+ } extends (infer M) ? M[keyof M] : never;
19
+ /**
20
+ * The data type associated to a given event.
21
+ */
22
+ export type WailsEventData<E extends WailsEventName = WailsEventName> = E extends keyof CustomEvents ? CustomEvents[E] : (E extends SystemEventName ? void : any);
2
23
  /**
3
24
  * The type of handlers for a given event.
4
25
  */
5
- export type Callback = (ev: WailsEvent) => void;
26
+ export type WailsEventCallback<E extends WailsEventName = WailsEventName> = (ev: WailsEvent<E>) => void;
6
27
  /**
7
28
  * Represents a system event or a custom event emitted through wails-provided facilities.
8
29
  */
9
- export declare class WailsEvent {
30
+ export declare class WailsEvent<E extends WailsEventName = WailsEventName> {
10
31
  /**
11
32
  * The name of the event.
12
33
  */
13
- name: string;
34
+ name: E;
14
35
  /**
15
36
  * Optional data associated with the emitted event.
16
37
  */
17
- data: any;
38
+ data: WailsEventData<E>;
18
39
  /**
19
40
  * Name of the originating window. Omitted for application events.
20
41
  * Will be overridden if set manually.
21
42
  */
22
43
  sender?: string;
23
- constructor(name: string, data?: any);
44
+ constructor(name: E, data: WailsEventData<E>);
45
+ constructor(name: WailsEventData<E> extends null | void ? E : never);
24
46
  }
25
47
  /**
26
48
  * Register a callback function to be called multiple times for a specific event.
@@ -30,7 +52,7 @@ export declare class WailsEvent {
30
52
  * @param maxCallbacks - The maximum number of times the callback can be called for the event. Once the maximum number is reached, the callback will no longer be called.
31
53
  * @returns A function that, when called, will unregister the callback from the event.
32
54
  */
33
- export declare function OnMultiple(eventName: string, callback: Callback, maxCallbacks: number): () => void;
55
+ export declare function OnMultiple<E extends WailsEventName = WailsEventName>(eventName: E, callback: WailsEventCallback<E>, maxCallbacks: number): () => void;
34
56
  /**
35
57
  * Registers a callback function to be executed when the specified event occurs.
36
58
  *
@@ -38,7 +60,7 @@ export declare function OnMultiple(eventName: string, callback: Callback, maxCal
38
60
  * @param callback - The callback function to be called when the event is triggered.
39
61
  * @returns A function that, when called, will unregister the callback from the event.
40
62
  */
41
- export declare function On(eventName: string, callback: Callback): () => void;
63
+ export declare function On<E extends WailsEventName = WailsEventName>(eventName: E, callback: WailsEventCallback<E>): () => void;
42
64
  /**
43
65
  * Registers a callback function to be executed only once for the specified event.
44
66
  *
@@ -46,22 +68,23 @@ export declare function On(eventName: string, callback: Callback): () => void;
46
68
  * @param callback - The callback function to be called when the event is triggered.
47
69
  * @returns A function that, when called, will unregister the callback from the event.
48
70
  */
49
- export declare function Once(eventName: string, callback: Callback): () => void;
71
+ export declare function Once<E extends WailsEventName = WailsEventName>(eventName: E, callback: WailsEventCallback<E>): () => void;
50
72
  /**
51
73
  * Removes event listeners for the specified event names.
52
74
  *
53
75
  * @param eventNames - The name of the events to remove listeners for.
54
76
  */
55
- export declare function Off(...eventNames: [string, ...string[]]): void;
77
+ export declare function Off(...eventNames: [WailsEventName, ...WailsEventName[]]): void;
56
78
  /**
57
79
  * Removes all event listeners.
58
80
  */
59
81
  export declare function OffAll(): void;
60
82
  /**
61
- * Emits an event using the name and data.
83
+ * Emits an event.
62
84
  *
63
- * @returns A promise that will be fulfilled once the event has been emitted.
64
- * @param name - the name of the event to emit.
65
- * @param data - the data to be sent with the event.
85
+ * @returns A promise that will be fulfilled once the event has been emitted. Resolves to true if the event was cancelled.
86
+ * @param name - The name of the event to emit
87
+ * @param data - The data that will be sent with the event
66
88
  */
67
- export declare function Emit(name: string, data?: any): Promise<void>;
89
+ export declare function Emit<E extends WailsEventName = WailsEventName>(name: E, data: WailsEventData<E>): Promise<boolean>;
90
+ export declare function Emit<E extends WailsEventName = WailsEventName>(name: WailsEventData<E> extends null | void ? E : never): Promise<boolean>;
package/types/index.d.ts CHANGED
@@ -13,4 +13,11 @@ import * as System from "./system.js";
13
13
  import Window from "./window.js";
14
14
  import * as WML from "./wml.js";
15
15
  export { Application, Browser, Call, Clipboard, Dialogs, Events, Flags, Screens, System, Window, WML };
16
+ /**
17
+ * An internal utility consumed by the binding generator.
18
+ *
19
+ * @ignore
20
+ */
21
+ export { Create };
16
22
  export * from "./cancellable.js";
23
+ export { setTransport, getTransport, type RuntimeTransport, objectNames, clientId, } from "./runtime.js";
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * A plugin that extends the wails runtime with locally generated code
4
+ * to provide support for typed custom events.
5
+ * With the plugin installed, vite will fail to build the project
6
+ * unless wails bindings have been generated first.
7
+ *
8
+ * @param {string} [bindingsRoot] - The root import path for generated bindings
9
+ */
10
+ export default function WailsTypedEvents(bindingsRoot: string): Plugin;
@@ -1,3 +1,5 @@
1
+ import { nanoid } from "./nanoid.js";
2
+ export { nanoid };
1
3
  export declare const objectNames: Readonly<{
2
4
  Call: 0;
3
5
  Clipboard: 1;
@@ -12,6 +14,48 @@ export declare const objectNames: Readonly<{
12
14
  CancelCall: 10;
13
15
  }>;
14
16
  export declare let clientId: string;
17
+ /**
18
+ * RuntimeTransport defines the interface for custom IPC transport implementations.
19
+ * Implement this interface to use WebSockets, custom protocols, or any other
20
+ * transport mechanism instead of the default HTTP fetch.
21
+ */
22
+ export interface RuntimeTransport {
23
+ /**
24
+ * Send a runtime call and return the response.
25
+ *
26
+ * @param objectID - The Wails object ID (0=Call, 1=Clipboard, etc.)
27
+ * @param method - The method ID to call
28
+ * @param windowName - Optional window name
29
+ * @param args - Arguments to pass (will be JSON stringified if present)
30
+ * @returns Promise that resolves with the response data
31
+ */
32
+ call(objectID: number, method: number, windowName: string, args: any): Promise<any>;
33
+ }
34
+ /**
35
+ * Set a custom transport for all Wails runtime calls.
36
+ * This allows you to replace the default HTTP fetch transport with
37
+ * WebSockets, custom protocols, or any other mechanism.
38
+ *
39
+ * @param transport - Your custom transport implementation
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * import { setTransport } from '/wails/runtime.js';
44
+ *
45
+ * const wsTransport = {
46
+ * call: async (objectID, method, windowName, args) => {
47
+ * // Your WebSocket implementation
48
+ * }
49
+ * };
50
+ *
51
+ * setTransport(wsTransport);
52
+ * ```
53
+ */
54
+ export declare function setTransport(transport: RuntimeTransport | null): void;
55
+ /**
56
+ * Get the current transport (useful for extending/wrapping)
57
+ */
58
+ export declare function getTransport(): RuntimeTransport | null;
15
59
  /**
16
60
  * Creates a new runtime caller with specified ID.
17
61
  *