support tauri-v2

This commit is contained in:
sr7
2024-09-24 18:38:12 +08:00
parent 23f2b6213c
commit 87c5b72ea2
11 changed files with 15450 additions and 2792 deletions

View File

@@ -1,3 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/gen/

3940
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -9,37 +9,40 @@ default-run = "nextchat"
edition = "2021"
rust-version = "1.60"
[lib]
name = "nextchat"
crate-type = ["staticlib", "cdylib", "rlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.5.1", features = [] }
tauri-build = { version = "2.0.0-rc", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.5.4", features = [ "http-all",
"notification-all",
"fs-all",
"clipboard-all",
"dialog-all",
"shell-open",
"updater",
"window-close",
"window-hide",
"window-maximize",
"window-minimize",
"window-set-icon",
"window-set-ignore-cursor-events",
"window-set-resizable",
"window-show",
"window-start-dragging",
"window-unmaximize",
"window-unminimize",
] }
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
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"
# Optimize for smaller binary size
[profile.release]
panic = "abort" # Strip expensive panic clean-up logic
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
lto = true # Enables link to optimizations
opt-level = "s" # Optimize for binary size
strip = true # Remove debug symbols
[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

View File

@@ -0,0 +1,16 @@
{
"identifier": "main",
"description": "permissions for desktop app",
"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"
]
}

69
src-tauri/src/lib.rs Normal file
View File

@@ -0,0 +1,69 @@
use tauri_specta::Event;
// demo command
#[tauri::command]
#[specta::specta]
fn greet(app: tauri::AppHandle, name: &str) -> String {
DemoEvent("Demo event fired from Rust 🦀".to_string())
.emit(&app)
.ok();
format!("Hello, {}! You've been greeted from Rust!", name)
}
// demo event
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, specta::Type, Event)]
pub struct DemoEvent(String);
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
#[cfg(debug_assertions)]
{
log::info!("App started!");
log::warn!("Example Rust Log: warning!");
log::error!("Example Rust Log: error!");
}
#[cfg(debug_assertions)]
let devtools = tauri_plugin_devtools::init();
let mut builder = tauri::Builder::default();
let specta_builder = tauri_specta::Builder::<tauri::Wry>::new()
.commands(tauri_specta::collect_commands![greet])
.events(tauri_specta::collect_events![crate::DemoEvent]);
#[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_updater::Builder::new().build())
.plugin(tauri_plugin_dialog::init())
.invoke_handler(specta_builder.invoke_handler())
.setup(move |app| {
specta_builder.mount_events(app);
// listen to demo event
DemoEvent::listen(app, |event| {
log::info!("DemoEvent received in Rust:: {:?}", event.payload);
});
// dispatch demo event
DemoEvent("Hello from Rust 🦀".to_string()).emit(app).ok();
// /dispatch demo event
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -1,9 +1,16 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
// #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// fn main() {
// tauri::Builder::default()
// .plugin(tauri_plugin_window_state::Builder::default().build())
// .run(tauri::generate_context!())
// .expect("error while running tauri application");
// }
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_window_state::Builder::default().build())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
nextchat::run()
}

View File

@@ -1,120 +1,40 @@
{
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"productName": "NextChat",
"identifier": "NextChat.template.dev",
"version": "0.1.0",
"build": {
"beforeBuildCommand": "yarn export",
"beforeDevCommand": "yarn export:dev",
"devPath": "http://localhost:3000",
"distDir": "../out",
"withGlobalTauri": true
"devUrl": "http://localhost:3000",
"frontendDist": "../out"
},
"package": {
"productName": "NextChat",
"version": "2.15.2"
},
"tauri": {
"allowlist": {
"all": false,
"shell": {
"all": false,
"open": true
},
"dialog": {
"all": true,
"ask": true,
"confirm": true,
"message": true,
"open": true,
"save": true
},
"clipboard": {
"all": true,
"writeText": true,
"readText": true
},
"window": {
"all": false,
"close": true,
"hide": true,
"maximize": true,
"minimize": true,
"setIcon": true,
"setIgnoreCursorEvents": true,
"setResizable": true,
"show": true,
"startDragging": true,
"unmaximize": true,
"unminimize": true
},
"fs": {
"all": true
},
"notification": {
"all": true
},
"http": {
"all": true,
"request": true,
"scope": ["https://*", "http://*"]
}
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "2023, Zhang Yifei All Rights Reserved.",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.yida.chatgpt.next.web",
"longDescription": "NextChat is a cross-platform ChatGPT client, including Web/Win/Linux/OSX/PWA.",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "NextChat App",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null,
"dangerousUseHttpScheme": true
},
"updater": {
"active": true,
"endpoints": [
"https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/releases/latest/download/latest.json"
],
"dialog": false,
"windows": {
"installMode": "passive"
},
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IERFNDE4MENFM0Y1RTZBOTQKUldTVWFsNC96b0JCM3RqM2NmMnlFTmxIaStRaEJrTHNOU2VqRVlIV1hwVURoWUdVdEc1eDcxVEYK"
},
"plugins": {},
"app": {
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "NextChat",
"width": 960,
"hiddenTitle": true,
"titleBarStyle": "Overlay"
"title": "quantum",
"width": 800,
"height": 600
}
]
}
],
"security": {
"csp": null
},
"withGlobalTauri": false
},
"bundle": {
"macOS": {
"signingIdentity": "-"
},
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}