mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2026-02-11 00:44:27 +08:00
support tauri-v2
This commit is contained in:
69
src-tauri/src/lib.rs
Normal file
69
src-tauri/src/lib.rs
Normal 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");
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user