diff --git a/src-tauri/src/app/cmd.rs b/src-tauri/src/app/cmd.rs index 4c1b3ed..9b13282 100644 --- a/src-tauri/src/app/cmd.rs +++ b/src-tauri/src/app/cmd.rs @@ -1,5 +1,5 @@ use crate::utils; -use log::info; +use log::error; use std::{fs, path::PathBuf}; use tauri::{api, command, AppHandle, Manager}; @@ -58,7 +58,7 @@ pub async fn get_data(app: AppHandle, url: String, is_msg: Option) -> Opti utils::get_data(&url, None).await }; res.unwrap_or_else(|err| { - info!("chatgpt_client_http_error: {}", err); + error!("chatgpt_client_http: {}", err); None }) } diff --git a/src-tauri/src/app/gpt.rs b/src-tauri/src/app/gpt.rs index ebaa6d3..964410d 100644 --- a/src-tauri/src/app/gpt.rs +++ b/src-tauri/src/app/gpt.rs @@ -3,7 +3,7 @@ use crate::{ conf::GITHUB_PROMPTS_CSV_URL, utils, }; -use log::info; +use log::{error, info}; use regex::Regex; use std::{collections::HashMap, fs, path::PathBuf, vec}; use tauri::{api, command, AppHandle, Manager}; @@ -29,7 +29,7 @@ pub fn parse_prompt(data: String) -> Vec { let mut list = vec![]; for result in rdr.deserialize() { let record: PromptRecord = result.unwrap_or_else(|err| { - info!("parse_prompt_error: {}", err); + error!("parse_prompt: {}", err); PromptRecord { cmd: None, act: "".to_string(), @@ -84,12 +84,12 @@ pub fn get_download_list(pathname: &str) -> (Vec, PathBuf) { info!("get_download_list: {}", pathname); let download_path = utils::app_root().join(PathBuf::from(pathname)); let content = fs::read_to_string(&download_path).unwrap_or_else(|err| { - info!("download_list_error: {}", err); + error!("download_list: {}", err); fs::write(&download_path, "[]").unwrap(); "[]".to_string() }); let list = serde_json::from_str::>(&content).unwrap_or_else(|err| { - info!("download_list_parse_error: {}", err); + error!("download_list_parse: {}", err); vec![] }); @@ -249,13 +249,12 @@ pub async fn sync_prompts(app: AppHandle, time: u64) -> Option> #[command] pub async fn sync_user_prompts(url: String, data_type: String) -> Option> { + info!("sync_user_prompts: url => {}", url); let res = utils::get_data(&url, None).await.unwrap_or_else(|err| { - info!("chatgpt_http_error: {}", err); + error!("chatgpt_http: {}", err); None }); - info!("chatgpt_http_url: {}", url); - if let Some(v) = res { let data; if data_type == "csv" { @@ -264,11 +263,11 @@ pub async fn sync_user_prompts(url: String, data_type: String) -> Option Menu { 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 _update_disable = CustomMenuItem::new("update_disable".to_string(), "Disable"); let popup_search = CustomMenuItem::new("popup_search".to_string(), "Pop-up Search"); let popup_search_menu = if app_conf.popup_search { @@ -74,6 +74,7 @@ pub fn init() -> Menu { system_tray }; + let auto_update = app_conf.get_auto_update(); let preferences_menu = Submenu::new( "Preferences", Menu::with_items([ @@ -114,16 +115,16 @@ pub fn init() -> Menu { Submenu::new( "Auto Update", Menu::new() - .add_item(if app_conf.auto_update == "Prompt" { + .add_item(if auto_update == "prompt" { update_prompt.selected() } else { update_prompt }) - .add_item(if app_conf.auto_update == "Silent" { + .add_item(if auto_update == "silent" { update_silent.selected() } else { update_silent - }), // .add_item(if app_conf.auto_update == "Disable" { + }), // .add_item(if auto_update == "disable" { // update_disable.selected() // } else { // update_disable @@ -321,21 +322,21 @@ pub fn menu_handler(event: WindowMenuEvent) { .get_item("update_silent") .set_selected(true) .unwrap(); - "Silent" + "silent" } "update_disable" => { menu_handle .get_item("update_disable") .set_selected(true) .unwrap(); - "Disable" + "disable" } _ => { menu_handle .get_item("update_prompt") .set_selected(true) .unwrap(); - "Prompt" + "prompt" } }; AppConf::read() diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs index 0f23024..8ed87cf 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -1,5 +1,5 @@ use crate::{app::window, conf::AppConf, utils}; -use log::info; +use log::{error, info}; use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, GlobalShortcutManager, Manager}; use wry::application::accelerator::Accelerator; @@ -33,11 +33,11 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box } }) .unwrap_or_else(|err| { - info!("global_shortcut_register_error: {}", err); + error!("global_shortcut_register_error: {}", err); }); } Err(err) => { - info!("global_shortcut_parse_error: {}", err); + error!("global_shortcut_parse_error: {}", err); } } } else { @@ -93,10 +93,11 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box } // auto_update - if app_conf.auto_update != "Disable" { - info!("stepup::run_check_update"); + let auto_update = app_conf.get_auto_update(); + if auto_update != "disable" { + info!("run_check_update"); let app = app.handle(); - utils::run_check_update(app, app_conf.auto_update == "Silent", None); + utils::run_check_update(app, auto_update == "silent", None); } Ok(()) diff --git a/src-tauri/src/conf.rs b/src-tauri/src/conf.rs index 6f9961e..97bf202 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -31,9 +31,9 @@ macro_rules! pub_struct { pub_struct!(AppConf { titlebar: bool, hide_dock_icon: bool, - // macOS and Windows: Light / Dark / System + // macOS and Windows: light / dark / system theme: String, - // auto update policy: Prompt / Silent / Disable + // auto update policy: prompt / silent / disable auto_update: String, tray: bool, popup_search: bool, @@ -54,8 +54,8 @@ impl AppConf { Self { titlebar: !cfg!(target_os = "macos"), hide_dock_icon: false, - theme: "Light".into(), - auto_update: "Prompt".into(), + theme: "light".into(), + auto_update: "prompt".into(), tray: true, popup_search: false, stay_on_top: false, @@ -88,15 +88,15 @@ impl AppConf { let path = &Self::file_path(); if !exists(path) { create_file(path).unwrap(); - info!("conf_init") + info!("conf_create"); } if let Ok(v) = serde_json::to_string_pretty(&self) { std::fs::write(path, v).unwrap_or_else(|err| { - error!("conf_write_error: {}", err); + error!("conf_write: {}", err); Self::default().write(); }); } else { - error!("conf_ser_error"); + error!("conf_ser"); } self } @@ -114,12 +114,12 @@ impl AppConf { Ok(v) => match serde_json::from_str::(&v) { Ok(v) => v, Err(err) => { - error!("conf_amend_parse_error: {}", err); + error!("conf_amend_parse: {}", err); self } }, Err(err) => { - error!("conf_amend_str_error: {}", err); + error!("conf_amend_str: {}", err); self } } @@ -135,7 +135,7 @@ impl AppConf { } pub fn theme_mode() -> Theme { - match cmd::get_theme().to_lowercase().as_str() { + match Self::get_theme().as_str() { "system" => match dark_light::detect() { // Dark mode dark_light::Mode::Dark => Theme::Dark, @@ -149,6 +149,14 @@ impl AppConf { } } + pub fn get_theme() -> String { + Self::read().theme.to_lowercase() + } + + pub fn get_auto_update(self) -> String { + self.auto_update.to_lowercase() + } + pub fn theme_check(self, mode: &str) -> bool { self.theme.to_lowercase() == mode } @@ -180,7 +188,7 @@ pub mod cmd { #[command] pub fn get_theme() -> String { - AppConf::read().theme + AppConf::get_theme() } #[command] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c41be6c..919d00c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -54,16 +54,6 @@ async fn main() { None, )) .invoke_handler(tauri::generate_handler![ - conf::cmd::get_app_conf, - conf::cmd::reset_app_conf, - conf::cmd::get_theme, - conf::cmd::form_confirm, - conf::cmd::form_cancel, - conf::cmd::form_msg, - window::cmd::wa_window, - window::cmd::control_window, - window::cmd::window_reload, - window::cmd::dalle2_search_window, cmd::drag_window, cmd::fullscreen, cmd::download, @@ -80,6 +70,16 @@ async fn main() { gpt::download_list, gpt::get_download_list, fs_extra::metadata, + conf::cmd::get_app_conf, + conf::cmd::reset_app_conf, + conf::cmd::get_theme, + conf::cmd::form_confirm, + conf::cmd::form_cancel, + conf::cmd::form_msg, + window::cmd::wa_window, + window::cmd::control_window, + window::cmd::window_reload, + window::cmd::dalle2_search_window, ]) .setup(setup::init) .menu(menu::init()); diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index cecf449..bb03d9a 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use log::info; +use log::{error, info}; use regex::Regex; use serde_json::Value; use std::{ @@ -145,7 +145,7 @@ pub async fn get_data( if is_ok { Ok(Some(body)) } else { - info!("chatgpt_http_error: {}", body); + error!("chatgpt_http: {}", body); if let Some(v) = app { tauri::api::dialog::message(v.get_window("core").as_ref(), "ChatGPT HTTP", body); } diff --git a/src/view/settings/General.tsx b/src/view/settings/General.tsx index 6f03a5f..78a853e 100644 --- a/src/view/settings/General.tsx +++ b/src/view/settings/General.tsx @@ -30,16 +30,16 @@ export default function General() { )} - Light - Dark + Light + Dark {['darwin', 'windows'].includes(platformInfo) && System} } name="auto_update"> - Prompt - Silent - {/*Disable*/} + Prompt + Silent + {/*Disable*/} } name="global_shortcut">