auto update policy

This commit is contained in:
tk103331
2023-01-05 10:39:46 +08:00
parent aa98d7dd2a
commit f646684f4d
8 changed files with 105 additions and 21 deletions

View File

@@ -44,8 +44,8 @@ pub fn reset_chat_conf() -> ChatConfJson {
}
#[command]
pub fn run_check_update(app: AppHandle) {
utils::run_check_update(app).unwrap();
pub fn run_check_update(app: AppHandle, silent: bool) {
utils::run_check_update(app, silent).unwrap();
}
#[command]

View File

@@ -47,6 +47,10 @@ pub fn init() -> Menu {
let is_dark = chat_conf.theme == "Dark";
let is_system = chat_conf.theme == "System";
let update_prompt = CustomMenuItem::new("update_prompt".to_string(), "Prompt");
let update_silent = CustomMenuItem::new("update_silent".to_string(), "Silent");
let _update_disable = CustomMenuItem::new("update_disable".to_string(), "Disable");
let stay_on_top_menu = if chat_conf.stay_on_top {
stay_on_top.selected()
} else {
@@ -87,6 +91,26 @@ pub fn init() -> Menu {
}),
)
.into(),
Submenu::new(
"Auto Update",
Menu::new()
.add_item(if chat_conf.auto_update == "Prompt" {
update_prompt.selected()
} else {
update_prompt
})
.add_item(if chat_conf.auto_update == "Silent" {
update_silent.selected()
} else {
update_silent
})
// .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(),
@@ -204,7 +228,7 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
);
}
"check_update" => {
utils::run_check_update(app).unwrap();
utils::run_check_update(app, false).unwrap();
}
// Preferences
"control_center" => window::control_window(&app),
@@ -248,6 +272,26 @@ 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"] {
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();
"Silent"
},
"update_disable" => {
menu_handle.get_item("update_disable").set_selected(true).unwrap();
"Disable"
},
_ => {
menu_handle.get_item("update_prompt").set_selected(true).unwrap();
"Prompt"
},
};
ChatConfJson::amend(&serde_json::json!({ "auto_update": auto_update }), None).unwrap();
}
"stay_on_top" => {
let mut stay_on_top = state.stay_on_top.lock().unwrap();
*stay_on_top = !*stay_on_top;

View File

@@ -89,10 +89,10 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
.unwrap();
});
}
// auto_check_update
if chat_conf.auto_check_update {
// auto_update
if chat_conf.auto_update != "Disable" {
let app = app.handle();
utils::run_check_update(app).unwrap();
utils::run_check_update(app, chat_conf.auto_update == "Silent").unwrap();
}
Ok(())