-
-
Notifications
You must be signed in to change notification settings - Fork 52
don't generate unused functions in bindings #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,14 @@ export type RandomNumber = number | |
|
|
||
| import { | ||
| invoke as TAURI_INVOKE, | ||
| Channel as TAURI_CHANNEL, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is reqiured when using channels for them to work. They must be called |
||
| } from "@tauri-apps/api/core"; | ||
|
|
||
|
|
||
| export type Result<T, E> = | ||
| | { status: "ok"; data: T } | ||
| | { status: "error"; error: E }; | ||
|
|
||
|
|
||
| import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
| import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow"; | ||
|
|
||
|
|
@@ -47,14 +53,10 @@ type __EventObj__<T> = { | |
| cb: TAURI_API_EVENT.EventCallback<T>, | ||
| ) => ReturnType<typeof TAURI_API_EVENT.once<T>>; | ||
| emit: T extends null | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this change? It also differs from the JS Doc alternative so they will need to match for this to be merged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be honest i don't know when/how this changed. i will undo the change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason when running tests, it creates this change. Thought I'd broken something somewhere but it just happens when you run tests lol There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay cool. As long as the JS doc part also matches we can resolve this. |
||
| ? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit> | ||
| : (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>; | ||
| ? (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 }; | ||
|
|
||
| function __makeEvents__<T extends Record<string, any>>( | ||
| mappings: Record<keyof T, string>, | ||
| ) { | ||
|
|
@@ -68,7 +70,7 @@ function __makeEvents__<T extends Record<string, any>>( | |
| get: (_, event) => { | ||
| const name = mappings[event as keyof T]; | ||
|
|
||
| return new Proxy((() => {}) as any, { | ||
| return new Proxy((() => { }) as any, { | ||
| apply: (_, __, [window]: [__WebviewWindow__]) => ({ | ||
| listen: (arg: any) => window.listen(name, arg), | ||
| once: (arg: any) => window.once(name, arg), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,65 +1,9 @@ | ||
| import { | ||
| invoke as TAURI_INVOKE, | ||
| Channel as TAURI_CHANNEL, | ||
| } from "@tauri-apps/api/core"; | ||
| import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
|
|
||
| /** @typedef {typeof import("@tauri-apps/api/window").WebviewWindowHandle} __WebviewWindowHandle__ */ | ||
|
|
||
| /** | ||
| * @template T | ||
| * @typedef {{ | ||
| * 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>; | ||
| * }} __EventObj__<T> | ||
| */ | ||
|
|
||
| /** | ||
| * @template T,E | ||
| * @typedef { { status: "ok", data: T } | { status: "error", error: E } } Result | ||
| */ | ||
|
|
||
| /** | ||
| * @template {Record<string, any>} T | ||
| * @param {Record<keyof T, string>} mappings | ||
| * @returns {{ | ||
| * [K in keyof T]: __EventObj__<T[K]> & { | ||
| * (handle: __WebviewWindowHandle__): __EventObj__<T[K]>; | ||
| * }; | ||
| * }} | ||
| */ | ||
| function __makeEvents__(mappings) { | ||
| return new Proxy( | ||
| {}, | ||
| { | ||
| get: (_, event) => { | ||
| const name = mappings[event]; | ||
|
|
||
| new Proxy(() => {}, { | ||
| apply: (_, __, [window]) => ({ | ||
| listen: (arg) => window.listen(name, arg), | ||
| once: (arg) => window.once(name, arg), | ||
| emit: (arg) => window.emit(name, arg), | ||
| }), | ||
| get: (_, command) => { | ||
| switch (command) { | ||
| case "listen": | ||
| return (arg) => TAURI_API_EVENT.listen(name, arg); | ||
| case "once": | ||
| return (arg) => TAURI_API_EVENT.once(name, arg); | ||
| case "emit": | ||
| return (arg) => TAURI_API_EVENT.emit(name, arg); | ||
| } | ||
| }, | ||
| }); | ||
| }, | ||
| }, | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,9 @@ | ||
| 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: null extends T | ||
| ? (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 }; | ||
|
|
||
| function __makeEvents__<T extends Record<string, any>>( | ||
| 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 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); | ||
| } | ||
| }, | ||
| }); | ||
| }, | ||
| }, | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import * as TAURI_API_EVENT from "@tauri-apps/api/event"; | ||
|
|
||
| /** @typedef {typeof import("@tauri-apps/api/window").WebviewWindowHandle} __WebviewWindowHandle__ */ | ||
|
|
||
| /** | ||
| * @template T | ||
| * @typedef {{ | ||
| * 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>; | ||
| * }} __EventObj__<T> | ||
| */ | ||
|
|
||
| /** | ||
| * @template {Record<string, any>} T | ||
| * @param {Record<keyof T, string>} mappings | ||
| * @returns {{ | ||
| * [K in keyof T]: __EventObj__<T[K]> & { | ||
| * (handle: __WebviewWindowHandle__): __EventObj__<T[K]>; | ||
| * }; | ||
| * }} | ||
| */ | ||
| function __makeEvents__(mappings) { | ||
| return new Proxy( | ||
| {}, | ||
| { | ||
| get: (_, event) => { | ||
| const name = mappings[event]; | ||
|
|
||
| new Proxy(() => { }, { | ||
| apply: (_, __, [window]) => ({ | ||
| listen: (arg) => window.listen(name, arg), | ||
| once: (arg) => window.once(name, arg), | ||
| emit: (arg) => window.emit(name, arg), | ||
| }), | ||
| get: (_, command) => { | ||
| switch (command) { | ||
| case "listen": | ||
| return (arg) => TAURI_API_EVENT.listen(name, arg); | ||
| case "once": | ||
| return (arg) => TAURI_API_EVENT.once(name, arg); | ||
| case "emit": | ||
| return (arg) => TAURI_API_EVENT.emit(name, arg); | ||
| } | ||
| }, | ||
| }); | ||
| }, | ||
| }, | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 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>; | ||
| }; | ||
|
|
||
| function __makeEvents__<T extends Record<string, any>>( | ||
| 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 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); | ||
| } | ||
| }, | ||
| }); | ||
| }, | ||
| }, | ||
| ); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.