2026-07-18 20:34:47 +08:00
|
|
|
pub mod database;
|
|
|
|
|
pub mod diagnostics;
|
|
|
|
|
pub mod file_transfer;
|
2026-07-18 22:17:29 +08:00
|
|
|
pub mod logging;
|
2026-07-18 20:34:47 +08:00
|
|
|
pub mod networking;
|
2026-07-18 23:36:19 +08:00
|
|
|
pub mod profiles;
|
2026-07-18 20:34:47 +08:00
|
|
|
pub mod secure_store;
|
|
|
|
|
pub mod windows;
|
|
|
|
|
|
2026-07-18 22:17:29 +08:00
|
|
|
use database::ApplicationDatabase;
|
2026-07-18 20:34:47 +08:00
|
|
|
use serde::Serialize;
|
2026-07-18 22:17:29 +08:00
|
|
|
|
2026-07-18 20:34:47 +08:00
|
|
|
use tauri::{
|
|
|
|
|
Manager, WindowEvent,
|
|
|
|
|
menu::{Menu, MenuItem},
|
|
|
|
|
tray::TrayIconBuilder,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
|
struct BootstrapStatus {
|
|
|
|
|
app_version: &'static str,
|
2026-07-18 22:17:29 +08:00
|
|
|
database_schema_version: u32,
|
2026-07-18 20:34:47 +08:00
|
|
|
platform: &'static str,
|
|
|
|
|
rust_core: &'static str,
|
|
|
|
|
protocol_version: &'static str,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
2026-07-18 22:17:29 +08:00
|
|
|
fn bootstrap_status(
|
|
|
|
|
database: tauri::State<'_, ApplicationDatabase>,
|
|
|
|
|
) -> Result<BootstrapStatus, String> {
|
|
|
|
|
let database_schema_version = database
|
|
|
|
|
.schema_version()
|
|
|
|
|
.map_err(|_| "database status is unavailable".to_owned())?;
|
|
|
|
|
|
|
|
|
|
Ok(BootstrapStatus {
|
2026-07-18 20:34:47 +08:00
|
|
|
app_version: env!("CARGO_PKG_VERSION"),
|
|
|
|
|
platform: "windows",
|
|
|
|
|
rust_core: "ready",
|
|
|
|
|
protocol_version: desktop_protocol::PROTOCOL_VERSION,
|
2026-07-18 22:17:29 +08:00
|
|
|
database_schema_version,
|
|
|
|
|
})
|
2026-07-18 20:34:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn run() {
|
2026-07-18 22:17:29 +08:00
|
|
|
logging::init();
|
2026-07-18 20:34:47 +08:00
|
|
|
|
|
|
|
|
tauri::Builder::default()
|
|
|
|
|
.plugin(tauri_plugin_single_instance::init(|app, _, _| {
|
|
|
|
|
if let Some(window) = app.get_webview_window("main") {
|
|
|
|
|
let _ = window.show();
|
|
|
|
|
let _ = window.set_focus();
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
.setup(|app| {
|
2026-07-18 22:17:29 +08:00
|
|
|
let app_data_dir = app.path().app_data_dir()?;
|
|
|
|
|
std::fs::create_dir_all(&app_data_dir)?;
|
|
|
|
|
app.manage(ApplicationDatabase::open(
|
|
|
|
|
app_data_dir.join("astrbot-desktop.sqlite3"),
|
|
|
|
|
)?);
|
|
|
|
|
|
2026-07-18 20:34:47 +08:00
|
|
|
let show = MenuItem::with_id(app, "show", "Show AstrBot Desktop", true, None::<&str>)?;
|
|
|
|
|
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
|
|
|
|
let menu = Menu::with_items(app, &[&show, &quit])?;
|
|
|
|
|
|
|
|
|
|
TrayIconBuilder::with_id("main")
|
|
|
|
|
.menu(&menu)
|
|
|
|
|
.on_menu_event(|app, event| match event.id.as_ref() {
|
|
|
|
|
"show" => {
|
|
|
|
|
if let Some(window) = app.get_webview_window("main") {
|
|
|
|
|
let _ = window.show();
|
|
|
|
|
let _ = window.set_focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
"quit" => app.exit(0),
|
|
|
|
|
_ => {}
|
|
|
|
|
})
|
|
|
|
|
.build(app)?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
})
|
|
|
|
|
.on_window_event(|window, event| {
|
|
|
|
|
if let WindowEvent::CloseRequested { api, .. } = event {
|
|
|
|
|
api.prevent_close();
|
|
|
|
|
let _ = window.hide();
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-07-18 23:36:19 +08:00
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
bootstrap_status,
|
|
|
|
|
profiles::list_connection_profiles,
|
|
|
|
|
profiles::create_connection_profile,
|
|
|
|
|
profiles::update_connection_profile,
|
|
|
|
|
profiles::delete_connection_profile,
|
|
|
|
|
])
|
2026-07-18 20:34:47 +08:00
|
|
|
.run(tauri::generate_context!())
|
|
|
|
|
.expect("failed to run AstrBot Desktop");
|
|
|
|
|
}
|