feat: simple cargo

This commit is contained in:
river 2024-09-24 21:19:45 +08:00
parent 2758ea5ddd
commit cb6576ec04
5 changed files with 698 additions and 1416 deletions

1955
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,12 +2,12 @@
name = "nextchat"
version = "0.1.0"
description = "A cross platform app for LLM ChatBot."
authors = ["Yidadaa"]
authors = ["GPTsMotion Tech LLC"]
license = "mit"
repository = ""
default-run = "nextchat"
edition = "2021"
rust-version = "1.60"
rust-version = "1.71"
[lib]
name = "nextchat"
@ -19,17 +19,13 @@ crate-type = ["staticlib", "cdylib", "rlib"]
tauri-build = { version = "2.0.0-rc", features = [] }
[dependencies]
tauri = { version = "2.0.0-rc", features = [] }
tauri-plugin-shell = "2.0.0-rc"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-devtools = "2.0.0-rc"
specta = "=2.0.0-rc.20"
tauri-plugin-updater = "2.0.0-rc"
tauri-plugin-dialog = "2.0.0-rc"
tauri-specta = { version = "=2.0.0-rc.15", features = ["derive", "javascript", "typescript"] }
specta-typescript = "0.0.7"
log = "0.4.22"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
log = "0.4"
tauri = { version = "2.0.0-rc.15", features = [] }
tauri-plugin-log = "2.0.0-rc"
tauri-plugin-http = "2.0.0-rc"
# Optimize for smaller binary size
[profile.release]
@ -46,3 +42,4 @@ strip = true # Remove debug symbols
custom-protocol = ["tauri/custom-protocol"]

View File

@ -4,13 +4,24 @@
"local": true,
"windows": ["main"],
"permissions": [
"dialog:default",
"dialog:allow-ask",
"dialog:allow-message",
"updater:default",
"updater:allow-check",
"updater:allow-download-and-install",
"core:event:allow-listen",
"core:event:default"
"core:default",
"core:window:allow-start-dragging",
"core:window:allow-maximize",
"http:default",
"http:allow-fetch",
"http:allow-fetch-cancel",
"http:allow-fetch-read-body",
"http:allow-fetch-send",
{
"identifier": "http:allow-fetch",
"allow": [
{
"url": "https://*"
},
{
"url": "http://*"
}
]
}
]
}

View File

@ -1,33 +1,15 @@
use tauri_specta::Event;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
#[cfg(debug_assertions)]
let devtools = tauri_plugin_devtools::init();
let mut builder = tauri::Builder::default();
let specta_builder = tauri_specta::Builder::<tauri::Wry>::new();
#[cfg(debug_assertions)]
{
builder = builder.plugin(devtools);
}
#[cfg(all(debug_assertions, not(mobile)))]
specta_builder
.export(
specta_typescript::Typescript::default()
.formatter(specta_typescript::formatter::prettier),
"../src/bindings.ts",
)
.expect("failed to export typescript bindings");
builder
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_dialog::init())
.invoke_handler(specta_builder.invoke_handler())
.setup(move |app| {
specta_builder.mount_events(app);
tauri::Builder::default()
.plugin(tauri_plugin_http::init())
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
tauri_plugin_log::Builder::default()
.level(log::LevelFilter::Info)
.build(),
)?;
}
Ok(())
})
.run(tauri::generate_context!())

71
src/bindings.ts Normal file
View File

@ -0,0 +1,71 @@
// 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 = {};
/** 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: 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 };
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);
}
},
});
},
},
);
}