From dc21b8cb25cefa2a6d935b4c7c14695671d9edaa Mon Sep 17 00:00:00 2001 From: shikai liu Date: Wed, 16 Oct 2024 08:25:24 +0800 Subject: [PATCH] Update the text of menu item. --- src-tauri/src/main.rs | 8 ++++---- src-tauri/src/sql_lite/connection.rs | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 76bd6cd..fc738da 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -19,12 +19,12 @@ use tauri::tray::TrayIconEvent; use tauri::Manager; fn main() -> Result<(), anyhow::Error> { - let sql_lite = AppState::new()?; + let app_state = AppState::new()?; tauri::Builder::default() .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_fs::init()) - .manage(sql_lite) + .manage(app_state) .on_window_event(|window, event| { if let tauri::WindowEvent::CloseRequested { api, .. } = event.clone() { window.hide().unwrap(); @@ -38,8 +38,8 @@ fn main() -> Result<(), anyhow::Error> { .build(), ) .setup(|app| { - let quit = MenuItem::with_id(app, "quit".to_string(), "退出", true, None::<&str>)?; - let show = MenuItem::with_id(app, "show".to_string(), "显示", true, None::<&str>)?; + let quit = MenuItem::with_id(app, "quit".to_string(), "Quit", true, None::<&str>)?; + let show = MenuItem::with_id(app, "show".to_string(), "Show", true, None::<&str>)?; let menu = Menu::with_items(app, &[&show, &quit])?; let _ = TrayIconBuilder::new() .icon(app.default_window_icon().unwrap().clone()) diff --git a/src-tauri/src/sql_lite/connection.rs b/src-tauri/src/sql_lite/connection.rs index 3d5a2c8..c72cc2b 100644 --- a/src-tauri/src/sql_lite/connection.rs +++ b/src-tauri/src/sql_lite/connection.rs @@ -7,8 +7,13 @@ use std::sync::Arc; pub struct AppState { pub pool: Pool, pub cancel_flag: Arc, + pub language: LanguageEnum, +} +#[derive(Clone)] +pub enum LanguageEnum { + Chinese, + English, } - impl AppState { pub fn new() -> Result { let home_dir = dirs::home_dir().ok_or(anyhow!("failed to get home directory"))?; @@ -17,7 +22,12 @@ impl AppState { .with_init(|c| c.execute_batch("PRAGMA journal_mode=wal;PRAGMA busy_timeout=60000;")); let pool = r2d2::Pool::new(manager)?; let cancel_flag = Arc::new(AtomicBool::new(false)); + let language = LanguageEnum::English; // let connection = Connection::open(db_path)?; - Ok(AppState { pool, cancel_flag }) + Ok(AppState { + pool, + cancel_flag, + language, + }) } }