This commit is contained in:
lencx
2023-01-05 17:18:47 +08:00
10 changed files with 83 additions and 70 deletions

View File

@@ -5,7 +5,7 @@ use crate::{
};
use log::info;
use std::{collections::HashMap, fs, path::PathBuf};
use tauri::{api, command, AppHandle, Manager};
use tauri::{api, command, AppHandle, Manager, Theme};
use walkdir::WalkDir;
#[command]
@@ -45,6 +45,11 @@ pub fn get_chat_conf() -> ChatConfJson {
ChatConfJson::get_chat_conf()
}
#[command]
pub fn get_theme() -> String {
ChatConfJson::theme().unwrap_or(Theme::Light).to_string()
}
#[command]
pub fn reset_chat_conf() -> ChatConfJson {
ChatConfJson::reset_chat_conf()

View File

@@ -103,14 +103,13 @@ pub fn init() -> Menu {
update_silent.selected()
} else {
update_silent
})
// .add_item(if chat_conf.auto_update == "Disable" {
// update_disable.selected()
// } else {
// update_disable
// })
,
).into(),
}), // .add_item(if chat_conf.auto_update == "Disable" {
// update_disable.selected()
// } else {
// update_disable
// })
)
.into(),
stay_on_top_menu.into(),
#[cfg(target_os = "macos")]
titlebar_menu.into(),
@@ -273,22 +272,31 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
ChatConfJson::amend(&serde_json::json!({ "theme": theme }), Some(app)).unwrap();
}
"update_prompt" | "update_silent" | "update_disable" => {
for id in ["update_prompt" , "update_silent" , "update_disable"] {
for id in ["update_prompt", "update_silent", "update_disable"] {
menu_handle.get_item(id).set_selected(false).unwrap();
}
let auto_update = match menu_id {
"update_silent" => {
menu_handle.get_item("update_silent").set_selected(true).unwrap();
menu_handle
.get_item("update_silent")
.set_selected(true)
.unwrap();
"Silent"
},
}
"update_disable" => {
menu_handle.get_item("update_disable").set_selected(true).unwrap();
menu_handle
.get_item("update_disable")
.set_selected(true)
.unwrap();
"Disable"
},
}
_ => {
menu_handle.get_item("update_prompt").set_selected(true).unwrap();
menu_handle
.get_item("update_prompt")
.set_selected(true)
.unwrap();
"Prompt"
},
}
};
ChatConfJson::amend(&serde_json::json!({ "auto_update": auto_update }), None).unwrap();
}

View File

@@ -52,6 +52,7 @@ async fn main() {
cmd::download,
cmd::open_link,
cmd::get_chat_conf,
cmd::get_theme,
cmd::reset_chat_conf,
cmd::run_check_update,
cmd::form_cancel,