mirror of
https://github.com/lencx/ChatGPT.git
synced 2024-10-01 01:06:13 -04:00
chore: log
This commit is contained in:
parent
f9f173407e
commit
a38804139a
@ -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<bool>) -> Opti
|
||||
utils::get_data(&url, None).await
|
||||
};
|
||||
res.unwrap_or_else(|err| {
|
||||
info!("chatgpt_client_http_error: {}", err);
|
||||
error!("chatgpt_client_http: {}", err);
|
||||
None
|
||||
})
|
||||
}
|
||||
|
@ -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<PromptRecord> {
|
||||
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<serde_json::Value>, 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::<Vec<serde_json::Value>>(&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<Vec<ModelRecord>>
|
||||
|
||||
#[command]
|
||||
pub async fn sync_user_prompts(url: String, data_type: String) -> Option<Vec<ModelRecord>> {
|
||||
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<Vec<Mod
|
||||
} else if data_type == "json" {
|
||||
info!("chatgpt_http_json_parse");
|
||||
data = serde_json::from_str(&v).unwrap_or_else(|err| {
|
||||
info!("chatgpt_http_json_parse_error: {}", err);
|
||||
error!("chatgpt_http_json_parse: {}", err);
|
||||
vec![]
|
||||
});
|
||||
} else {
|
||||
info!("chatgpt_http_unknown_type");
|
||||
error!("chatgpt_http_unknown_type");
|
||||
data = vec![];
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ pub fn init() -> 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<tauri::Wry>) {
|
||||
.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()
|
||||
|
@ -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<dyn std::error::Error>
|
||||
}
|
||||
})
|
||||
.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<dyn std::error::Error>
|
||||
}
|
||||
|
||||
// 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(())
|
||||
|
@ -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::<AppConf>(&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]
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
10
src/view/settings/General.tsx
vendored
10
src/view/settings/General.tsx
vendored
@ -30,16 +30,16 @@ export default function General() {
|
||||
)}
|
||||
<Form.Item label="Theme" name="theme">
|
||||
<Radio.Group>
|
||||
<Radio value="Light">Light</Radio>
|
||||
<Radio value="Dark">Dark</Radio>
|
||||
<Radio value="light">Light</Radio>
|
||||
<Radio value="dark">Dark</Radio>
|
||||
{['darwin', 'windows'].includes(platformInfo) && <Radio value="System">System</Radio>}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label={<AutoUpdateLabel />} name="auto_update">
|
||||
<Radio.Group>
|
||||
<Radio value="Prompt">Prompt</Radio>
|
||||
<Radio value="Silent">Silent</Radio>
|
||||
{/*<Radio value="Disable">Disable</Radio>*/}
|
||||
<Radio value="prompt">Prompt</Radio>
|
||||
<Radio value="silent">Silent</Radio>
|
||||
{/*<Radio value="disable">Disable</Radio>*/}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label={<GlobalShortcutLabel />} name="global_shortcut">
|
||||
|
Loading…
Reference in New Issue
Block a user