mirror of
https://github.com/lanyeeee/bilibili-video-downloader.git
synced 2026-09-08 17:16:52 +08:00
feat: 引入tauri-specta来保证类型安全
This commit is contained in:
Generated
+89
@@ -2,6 +2,12 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "Inflector"
|
||||||
|
version = "0.11.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "addr2line"
|
||||||
version = "0.24.2"
|
version = "0.24.2"
|
||||||
@@ -263,9 +269,12 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"specta",
|
||||||
|
"specta-typescript",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"tauri-plugin-opener",
|
"tauri-plugin-opener",
|
||||||
|
"tauri-specta",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2449,6 +2458,12 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pathdiff"
|
name = "pathdiff"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
@@ -3374,6 +3389,51 @@ dependencies = [
|
|||||||
"system-deps",
|
"system-deps",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "specta"
|
||||||
|
version = "2.0.0-rc.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ccbb212565d2dc177bc15ecb7b039d66c4490da892436a4eee5b394d620c9bc"
|
||||||
|
dependencies = [
|
||||||
|
"paste",
|
||||||
|
"serde_json",
|
||||||
|
"specta-macros",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "specta-macros"
|
||||||
|
version = "2.0.0-rc.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68999d29816965eb9e5201f60aec02a76512139811661a7e8e653abc810b8f72"
|
||||||
|
dependencies = [
|
||||||
|
"Inflector",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.104",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "specta-serde"
|
||||||
|
version = "0.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "12260cbb21abb2e83a0375b1521867910e3aed8a7afa782206150ce552cd2e5a"
|
||||||
|
dependencies = [
|
||||||
|
"specta",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "specta-typescript"
|
||||||
|
version = "0.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1e4472229365ceb6395487e3a60d921ad8e21f9ad06eaecc396f098902c9adc"
|
||||||
|
dependencies = [
|
||||||
|
"specta",
|
||||||
|
"specta-serde",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stable_deref_trait"
|
name = "stable_deref_trait"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -3572,6 +3632,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_repr",
|
"serde_repr",
|
||||||
"serialize-to-javascript",
|
"serialize-to-javascript",
|
||||||
|
"specta",
|
||||||
"swift-rs",
|
"swift-rs",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"tauri-macros",
|
"tauri-macros",
|
||||||
@@ -3740,6 +3801,34 @@ dependencies = [
|
|||||||
"wry",
|
"wry",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-specta"
|
||||||
|
version = "2.0.0-rc.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d06336a2fa3ead0c8d08719e78cbc1fb73650845789605bd2ab908cbde72815"
|
||||||
|
dependencies = [
|
||||||
|
"heck 0.5.0",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"specta",
|
||||||
|
"specta-typescript",
|
||||||
|
"tauri",
|
||||||
|
"tauri-specta-macros",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-specta-macros"
|
||||||
|
version = "2.0.0-rc.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a4aa93823e07859546aa796b8a5d608190cd8037a3a5dce3eb63d491c34bda8"
|
||||||
|
dependencies = [
|
||||||
|
"heck 0.5.0",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.104",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-utils"
|
name = "tauri-utils"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
|
|||||||
@@ -23,3 +23,6 @@ tauri-plugin-opener = "2"
|
|||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
||||||
|
specta = { version = "=2.0.0-rc.20", features = ["serde_json"] }
|
||||||
|
tauri-specta = { version = "=2.0.0-rc.20", features = ["derive", "typescript"] }
|
||||||
|
specta-typescript = { version = "=0.0.7" }
|
||||||
|
|||||||
+19
-1
@@ -1,14 +1,32 @@
|
|||||||
|
use tauri::Wry;
|
||||||
|
|
||||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
#[specta::specta]
|
||||||
fn greet(name: &str) -> String {
|
fn greet(name: &str) -> String {
|
||||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
|
let builder = tauri_specta::Builder::<Wry>::new()
|
||||||
|
.commands(tauri_specta::collect_commands![greet])
|
||||||
|
.events(tauri_specta::collect_events![]);
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
builder
|
||||||
|
.export(
|
||||||
|
specta_typescript::Typescript::default()
|
||||||
|
.bigint(specta_typescript::BigIntExportBehavior::Number)
|
||||||
|
.formatter(specta_typescript::formatter::prettier)
|
||||||
|
.header("// @ts-nocheck"), // disable typescript checks
|
||||||
|
"../src/bindings.ts",
|
||||||
|
)
|
||||||
|
.expect("Failed to export typescript bindings");
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
.invoke_handler(tauri::generate_handler![greet])
|
.invoke_handler(builder.invoke_handler())
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,13 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { invoke } from '@tauri-apps/api/core'
|
import {commands} from "./bindings.ts";
|
||||||
|
|
||||||
const greetMsg = ref('')
|
const greetMsg = ref('')
|
||||||
const name = ref('')
|
const name = ref('')
|
||||||
|
|
||||||
async function greet() {
|
async function greet() {
|
||||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||||
greetMsg.value = await invoke('greet', { name: name.value })
|
greetMsg.value = await commands.greet(name.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
// 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 greet(name: string) : Promise<string> {
|
||||||
|
return await TAURI_INVOKE("greet", { name });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user