This commit is contained in:
Michael Zhang 2023-06-11 15:08:16 -05:00
parent ace93534ad
commit afd50c1f0e

View file

@ -9,11 +9,15 @@ extern crate serde;
mod kanji; mod kanji;
mod srs; mod srs;
use std::process;
use std::str::FromStr; use std::str::FromStr;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use tauri::SystemTray; use tauri::{
CustomMenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu,
SystemTrayMenuItem, WindowEvent,
};
use tokio::fs; use tokio::fs;
use crate::kanji::KanjiDb; use crate::kanji::KanjiDb;
@ -44,7 +48,11 @@ async fn main() -> Result<()> {
sqlx::migrate!().run(&srs_pool).await?; sqlx::migrate!().run(&srs_pool).await?;
// System tray // System tray
let tray = SystemTray::new(); let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let tray_menu = SystemTrayMenu::new().add_item(quit);
let tray = SystemTray::new()
.with_tooltip("Houhou")
.with_menu(tray_menu);
// Build tauri // Build tauri
tauri::Builder::default() tauri::Builder::default()
@ -56,6 +64,22 @@ async fn main() -> Result<()> {
kanji::get_kanji, kanji::get_kanji,
kanji::get_single_kanji kanji::get_single_kanji
]) ])
.on_window_event(|event| match event.event() {
WindowEvent::CloseRequested { api, .. } => {
event.window().hide().unwrap();
api.prevent_close();
}
_ => {}
})
.on_system_tray_event(|app, event| match event {
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"quit" => {
process::exit(0);
}
_ => {}
},
_ => {}
})
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.context("error while running tauri application")?; .context("error while running tauri application")?;