Skip to content
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

feat: conditionally export TypeScript bindings in debug mode #56

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions src/helpers/bindings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.

/** user-defined commands **/


export const commands = {
async login(username: string, password: string) : Promise<Result<null, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("login", { username, password }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getDailyLimit() : Promise<Result<number, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_daily_limit") };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async upload(geojson: string, mileage: number, endTime: number) : Promise<Result<null, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("upload", { geojson, mileage, endTime }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
}
}

/** user-defined events **/



/** user-defined constants **/



/** user-defined types **/



/** tauri-specta globals **/

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);
}
},
});
},
},
);
}
2 changes: 1 addition & 1 deletion tauri-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pretty-der6y",
"version": "1.2.1",
"version": "1.2.2",
"description": "Hachimi hachimi hachimi~",
"type": "module",
"author": "Fay Ash",
Expand Down
2 changes: 1 addition & 1 deletion tauri-app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pretty-der6y"
version = "1.2.1"
version = "1.2.2"
description = "Hachimi hachimi hachimi~"
authors = ["Fay Ash"]
edition = "2021"
Expand Down
1 change: 1 addition & 0 deletions tauri-app/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
chrono::{DateTime, Local},
Account,
};
use specta_typescript::{formatter, BigIntExportBehavior, Typescript};

Check warning on line 23 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (specta)
use tauri::{async_runtime::Mutex, Manager, State};

Check warning on line 24 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (tauri)
use tauri_specta::{collect_commands, Builder};

Check warning on line 25 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (tauri)

Check warning on line 25 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (specta)

#[tauri::command]

Check warning on line 27 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (tauri)
#[specta::specta]

Check warning on line 28 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (specta)

Check warning on line 28 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (specta)
async fn login(
state: State<'_, Mutex<Account>>,
username: &str,
Expand All @@ -38,14 +38,14 @@
.map_err(|e| e.to_string())
}

#[tauri::command]

Check warning on line 41 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (tauri)
#[specta::specta]

Check warning on line 42 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (specta)
async fn get_daily_limit(state: State<'_, Mutex<Account>>) -> Result<f64, String> {
let account = state.lock().await;
Ok(account.daily())
}

#[tauri::command]

Check warning on line 48 in tauri-app/src-tauri/src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

Unknown word (tauri)
#[specta::specta]
async fn upload(
state: State<'_, Mutex<Account>>,
Expand All @@ -69,6 +69,7 @@
let builder =
Builder::<tauri::Wry>::new().commands(collect_commands![login, get_daily_limit, upload,]);

#[cfg(debug_assertions)] // only export typescript bindings in debug mode
builder
.export(
Typescript::default()
Expand Down
2 changes: 1 addition & 1 deletion tauri-app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "Pretty Der6y",
"version": "1.2.1",
"version": "1.2.2",
"identifier": "moe.phieash.pretty-der6y",
"build": {
"beforeDevCommand": "deno run dev",
Expand Down
Loading