-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from oscartbeaumont/channel
ipc::Channel support
- Loading branch information
Showing
9 changed files
with
609 additions
and
669 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,57 @@ | ||
import { invoke as TAURI_INVOKE } from "@tauri-apps/api/core"; | ||
import { | ||
invoke as TAURI_INVOKE, | ||
Channel as TAURI_CHANNEL, | ||
} from "@tauri-apps/api/core"; | ||
import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow"; | ||
|
||
type __EventObj__<T> = { | ||
listen: ( | ||
cb: TAURI_API_EVENT.EventCallback<T> | ||
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>; | ||
once: ( | ||
cb: TAURI_API_EVENT.EventCallback<T> | ||
) => ReturnType<typeof TAURI_API_EVENT.once<T>>; | ||
emit: T extends null | ||
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
listen: ( | ||
cb: TAURI_API_EVENT.EventCallback<T>, | ||
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>; | ||
once: ( | ||
cb: TAURI_API_EVENT.EventCallback<T>, | ||
) => ReturnType<typeof TAURI_API_EVENT.once<T>>; | ||
emit: T extends null | ||
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
}; | ||
|
||
export type Result<T, E> = | ||
| { status: "ok"; data: T } | ||
| { status: "error"; error: E }; | ||
| { status: "ok"; data: T } | ||
| { status: "error"; error: E }; | ||
|
||
function __makeEvents__<T extends Record<string, any>>( | ||
mappings: Record<keyof T, string> | ||
mappings: Record<keyof T, string>, | ||
) { | ||
return new Proxy( | ||
{} as unknown as { | ||
[K in keyof T]: __EventObj__<T[K]> & { | ||
(handle: __WebviewWindow__): __EventObj__<T[K]>; | ||
}; | ||
}, | ||
{ | ||
get: (_, event) => { | ||
const name = mappings[event as keyof T]; | ||
return new Proxy( | ||
{} as unknown as { | ||
[K in keyof T]: __EventObj__<T[K]> & { | ||
(handle: __WebviewWindow__): __EventObj__<T[K]>; | ||
}; | ||
}, | ||
{ | ||
get: (_, event) => { | ||
const name = mappings[event as keyof T]; | ||
|
||
return new Proxy((() => {}) as any, { | ||
apply: (_, __, [window]: [__WebviewWindow__]) => ({ | ||
listen: (arg: any) => window.listen(name, arg), | ||
once: (arg: any) => window.once(name, arg), | ||
emit: (arg: any) => window.emit(name, arg), | ||
}), | ||
get: (_, command: keyof __EventObj__<any>) => { | ||
switch (command) { | ||
case "listen": | ||
return (arg: any) => TAURI_API_EVENT.listen(name, arg); | ||
case "once": | ||
return (arg: any) => TAURI_API_EVENT.once(name, arg); | ||
case "emit": | ||
return (arg: any) => TAURI_API_EVENT.emit(name, arg); | ||
} | ||
}, | ||
}); | ||
}, | ||
} | ||
); | ||
return new Proxy((() => {}) as any, { | ||
apply: (_, __, [window]: [__WebviewWindow__]) => ({ | ||
listen: (arg: any) => window.listen(name, arg), | ||
once: (arg: any) => window.once(name, arg), | ||
emit: (arg: any) => window.emit(name, arg), | ||
}), | ||
get: (_, command: keyof __EventObj__<any>) => { | ||
switch (command) { | ||
case "listen": | ||
return (arg: any) => TAURI_API_EVENT.listen(name, arg); | ||
case "once": | ||
return (arg: any) => TAURI_API_EVENT.once(name, arg); | ||
case "emit": | ||
return (arg: any) => TAURI_API_EVENT.emit(name, arg); | ||
} | ||
}, | ||
}); | ||
}, | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters