diff --git a/README-ZH_CN.md b/README-ZH_CN.md index d29f192..6f0f581 100644 --- a/README-ZH_CN.md +++ b/README-ZH_CN.md @@ -22,9 +22,9 @@ **最新版:** -- `Mac`: [ChatGPT_0.4.1_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.4.1/ChatGPT_0.4.1_x64.dmg) -- `Linux`: [chat-gpt_0.4.1_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.4.1/chat-gpt_0.4.1_amd64.deb) -- `Windows`: [ChatGPT_0.4.1_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.4.1/ChatGPT_0.4.1_x64_en-US.msi) +- `Mac`: [ChatGPT_0.4.2_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.4.2/ChatGPT_0.4.2_x64.dmg) +- `Linux`: [chat-gpt_0.4.2_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.4.2/chat-gpt_0.4.2_amd64.deb) +- `Windows`: [ChatGPT_0.4.2_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.4.2/ChatGPT_0.4.2_x64_en-US.msi) [其他版本...](https://github.com/lencx/ChatGPT/releases) diff --git a/README.md b/README.md index 7b7476c..723b5f9 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ **Latest:** -- `Mac`: [ChatGPT_0.4.1_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.4.1/ChatGPT_0.4.1_x64.dmg) -- `Linux`: [chat-gpt_0.4.1_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.4.1/chat-gpt_0.4.1_amd64.deb) -- `Windows`: [ChatGPT_0.4.1_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.4.1/ChatGPT_0.4.1_x64_en-US.msi) +- `Mac`: [ChatGPT_0.4.2_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.4.2/ChatGPT_0.4.2_x64.dmg) +- `Linux`: [chat-gpt_0.4.2_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.4.2/chat-gpt_0.4.2_amd64.deb) +- `Windows`: [ChatGPT_0.4.2_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.4.2/ChatGPT_0.4.2_x64_en-US.msi) [Other version...](https://github.com/lencx/ChatGPT/releases) diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index 38d0ab8..4c124fb 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -1,5 +1,9 @@ # UPDATE LOG +## v0.4.2 + +add chatgpt log (path: `~/.chatgpt/chatgpt.log`) + ## v0.4.1 fix: diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 1e861a8..c9aa894 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -19,6 +19,12 @@ serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } tauri = { version = "1.2.2", features = ["api-all", "devtools", "system-tray", "updater"] } tauri-plugin-positioner = { version = "1.0.4", features = ["system-tray"] } +log = "0.4.17" + +[dependencies.tauri-plugin-log] +git = "https://github.com/tauri-apps/tauri-plugin-log" +branch = "dev" +features = ["colored"] [features] # by default Tauri runs in production mode diff --git a/src-tauri/src/app/cmd.rs b/src-tauri/src/app/cmd.rs index b770a81..17968c3 100644 --- a/src-tauri/src/app/cmd.rs +++ b/src-tauri/src/app/cmd.rs @@ -70,4 +70,4 @@ pub fn get_chat_model() -> serde_json::Value { let path = utils::chat_root().join("chat.model.json"); let content = fs::read_to_string(path).unwrap_or_else(|_| r#"{"data":[]}"#.to_string()); serde_json::from_str(&content).unwrap() -} \ No newline at end of file +} diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 453df65..6d548c4 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -4,7 +4,7 @@ use crate::{ }; use tauri::{ AboutMetadata, AppHandle, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray, - SystemTrayEvent, SystemTrayMenu, WindowMenuEvent, SystemTrayMenuItem, + SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, WindowMenuEvent, }; use tauri_plugin_positioner::{on_tray_event, Position, WindowExt}; @@ -138,6 +138,10 @@ pub fn init() -> Menu { let help_menu = Submenu::new( "Help", Menu::new() + .add_item(CustomMenuItem::new( + "chatgpt_log".to_string(), + "ChatGPT Log", + )) .add_item(CustomMenuItem::new("update_log".to_string(), "Update Log")) .add_item(CustomMenuItem::new("report_bug".to_string(), "Report Bug")) .add_item( @@ -226,6 +230,7 @@ pub fn menu_handler(event: WindowMenuEvent) { ) .unwrap(), // Help + "chatgpt_log" => utils::open_file(utils::chat_root().join("chatgpt.log")), "update_log" => open(&app, conf::UPDATE_LOG_URL.to_string()), "report_bug" => open(&app, conf::ISSUES_URL.to_string()), "dev_tools" => { @@ -240,11 +245,20 @@ pub fn menu_handler(event: WindowMenuEvent) { pub fn tray_menu() -> SystemTray { SystemTray::new().with_menu( SystemTrayMenu::new() - .add_item(CustomMenuItem::new("control_center".to_string(), "Control Center")) - .add_item(CustomMenuItem::new("show_dock_icon".to_string(), "Show Dock Icon")) - .add_item(CustomMenuItem::new("hide_dock_icon".to_string(), "Hide Dock Icon")) + .add_item(CustomMenuItem::new( + "control_center".to_string(), + "Control Center", + )) + .add_item(CustomMenuItem::new( + "show_dock_icon".to_string(), + "Show Dock Icon", + )) + .add_item(CustomMenuItem::new( + "hide_dock_icon".to_string(), + "Hide Dock Icon", + )) .add_native_item(SystemTrayMenuItem::Separator) - .add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")) + .add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")), ) } @@ -276,25 +290,19 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) { "control_center" => app.get_window("main").unwrap().show().unwrap(), "restart" => tauri::api::process::restart(&handle.env()), "show_dock_icon" => { - ChatConfJson::amend( - &serde_json::json!({ "hide_dock_icon": false }), - Some(app), - ) - .unwrap(); - }, + ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": false }), Some(app)) + .unwrap(); + } "hide_dock_icon" => { let chat_conf = conf::ChatConfJson::get_chat_conf(); if !chat_conf.hide_dock_icon { - ChatConfJson::amend( - &serde_json::json!({ "hide_dock_icon": true }), - Some(app), - ) - .unwrap(); + ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": true }), Some(app)) + .unwrap(); } - }, + } "quit" => std::process::exit(0), _ => (), - } + }, _ => (), } } diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs index d12cdab..7d342a4 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -34,7 +34,8 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box .initialization_script(include_str!("../assets/export.js")) .initialization_script(include_str!("../assets/cmd.js")) .user_agent(&chat_conf.ua_window) - .build().unwrap(); + .build() + .unwrap(); #[cfg(not(target_os = "macos"))] WindowBuilder::new(&app, "core", WindowUrl::App(url.into())) @@ -51,7 +52,8 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box .initialization_script(include_str!("../assets/export.js")) .initialization_script(include_str!("../assets/cmd.js")) .user_agent(&chat_conf.ua_window) - .build().unwrap(); + .build() + .unwrap(); }); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index cd53040..a4f2d21 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,13 +9,29 @@ mod utils; use app::{cmd, menu, setup}; use conf::{ChatConfJson, ChatState}; +use tauri::api::path; +use tauri_plugin_log::{fern::colors::ColoredLevelConfig, LogTarget, LoggerBuilder}; fn main() { ChatConfJson::init(); let chat_conf = ChatConfJson::get_chat_conf(); let context = tauri::generate_context!(); + let colors = ColoredLevelConfig::default(); tauri::Builder::default() + // https://github.com/tauri-apps/tauri/pull/2736 + .plugin( + LoggerBuilder::new() + .with_colors(colors) + .targets([ + // LogTarget::LogDir, + // LOG PATH: ~/.chatgpt/ChatGPT.log + LogTarget::Folder(path::home_dir().unwrap().join(".chatgpt")), + LogTarget::Stdout, + LogTarget::Webview, + ]) + .build(), + ) .manage(ChatState::default(chat_conf)) .invoke_handler(tauri::generate_handler![ cmd::drag_window, diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index 841ab62..6191596 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use log::info; use std::{ fs::{self, File}, path::{Path, PathBuf}, @@ -48,6 +49,7 @@ pub fn user_script() -> String { } pub fn open_file(path: PathBuf) { + info!("open_file: {}", path.to_string_lossy()); #[cfg(target_os = "macos")] Command::new("open").arg("-R").arg(path).spawn().unwrap(); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 4717277..ec1c936 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -7,7 +7,7 @@ }, "package": { "productName": "ChatGPT", - "version": "0.4.1" + "version": "0.4.2" }, "tauri": { "allowlist": {