diff --git a/README-ZH_CN.md b/README-ZH_CN.md index d2338fb..db42252 100644 --- a/README-ZH_CN.md +++ b/README-ZH_CN.md @@ -22,9 +22,9 @@ **最新版:** -- `Mac`: [ChatGPT_0.7.2_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.7.2/ChatGPT_0.7.2_x64.dmg) -- `Linux`: [chat-gpt_0.7.2_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.7.2/chat-gpt_0.7.2_amd64.deb) -- `Windows`: [ChatGPT_0.7.2_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.7.2/ChatGPT_0.7.2_x64_en-US.msi) +- `Mac`: [ChatGPT_0.7.3_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.7.3/ChatGPT_0.7.3_x64.dmg) +- `Linux`: [chat-gpt_0.7.3_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.7.3/chat-gpt_0.7.3_amd64.deb) +- `Windows`: [ChatGPT_0.7.3_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.7.3/ChatGPT_0.7.3_x64_en-US.msi) [其他版本...](https://github.com/lencx/ChatGPT/releases) @@ -58,7 +58,7 @@ cask "popcorn-time", args: { "no-quarantine": true } ![chat cmd](./assets/chat-cmd-1.png) ![chat cmd](./assets/chat-cmd-2.png) -数据导入完成后,可以重新启动应用来使配置生效(`Menu -> Preferences -> Restart ChatGPT`)。 + 在 ChatGPT 文本输入区域,键入 `/` 开头的字符,则会弹出指令提示,按下空格键,它会默认将命令关联的文本填充到输入区域(注意:如果包含多个指令提示,它只会选择第一个作为填充,你可以持续输入,直到第一个提示命令为你想要时,再按下空格键。或者使用鼠标来点击多条指令中的某一个)。填充完成后,你只需要按下回车键即可。斜杠命令下,使用 TAB 键修改 `{q}` 标签内容(仅支持单个修改 [#54](https://github.com/lencx/ChatGPT/issues/54))。使用键盘 `⇧` 和 `⇩`(上下键)来选择斜杠指令。 @@ -74,7 +74,7 @@ cask "popcorn-time", args: { "no-quarantine": true } - 系统托盘悬浮窗 - 应用菜单功能强大 - 支持斜杠命令及其配置(可手动配置或从文件同步 [#55](https://github.com/lencx/ChatGPT/issues/55)) - +- 进入应用的全局快捷键 (mac: `Command + Shift + O`, windows: `Ctrl + Shift + O`) ### 菜单项 diff --git a/README.md b/README.md index 30df12b..3f804fb 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,9 @@ **Latest:** -- `Mac`: [ChatGPT_0.7.2_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.7.2/ChatGPT_0.7.2_x64.dmg) -- `Linux`: [chat-gpt_0.7.2_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.7.2/chat-gpt_0.7.2_amd64.deb) -- `Windows`: [ChatGPT_0.7.2_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.7.2/ChatGPT_0.7.2_x64_en-US.msi) +- `Mac`: [ChatGPT_0.7.3_x64.dmg](https://github.com/lencx/ChatGPT/releases/download/v0.7.3/ChatGPT_0.7.3_x64.dmg) +- `Linux`: [chat-gpt_0.7.3_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.7.3/chat-gpt_0.7.3_amd64.deb) +- `Windows`: [ChatGPT_0.7.3_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.7.3/ChatGPT_0.7.3_x64_en-US.msi) [Other version...](https://github.com/lencx/ChatGPT/releases) @@ -60,7 +60,7 @@ You can look at [awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-p ![chat cmd](./assets/chat-cmd-1.png) ![chat cmd](./assets/chat-cmd-2.png) -After the data import is done, you can restart the app to make the configuration take effect (`Menu -> Preferences -> Restart ChatGPT`). + In the chatgpt text input area, type a character starting with `/` to bring up the command prompt, press the spacebar, and it will fill the input area with the text associated with the command by default (note: if it contains multiple command prompts, it will only select the first one as the fill, you can keep typing until the first prompted command is the one you want, then press the spacebar. Or use the mouse to click on one of the multiple commands). When the fill is complete, you simply press the Enter key. Under the slash command, use the tab key to modify the contents of the `{q}` tag (only single changes are supported [#54](https://github.com/lencx/ChatGPT/issues/54)). Use the keyboard `⇧` (arrow up) and `⇩` (arrow down) keys to select the slash command. @@ -76,7 +76,7 @@ In the chatgpt text input area, type a character starting with `/` to bring up t - System tray hover window - Powerful menu items - Support for slash commands and their configuration (can be configured manually or synchronized from a file [#55](https://github.com/lencx/ChatGPT/issues/55)) - +- Global shortcuts to the chatgpt app (mac: `Command + Shift + O`, windows: `Ctrl + Shift + O`) ### MenuItem diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index e918c71..31259e6 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -1,5 +1,12 @@ # UPDATE LOG +## v0.7.3 + +chore: +- optimize slash command style +- optimize tray menu icon and button icons +- global shortcuts to the chatgpt app (mac: `Command + Shift + O`, windows: `Ctrl + Shift + O`) + ## v0.7.2 fix: some windows systems cannot start the application diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 72044f4..824bcdc 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,14 +17,14 @@ tauri-build = {version = "1.2.1", features = [] } anyhow = "1.0.66" serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.2.3", features = ["api-all", "devtools", "system-tray", "updater"] } +tauri = { version = "1.2.3", features = ["api-all", "devtools", "global-shortcut", "system-tray", "updater"] } tauri-plugin-positioner = { version = "1.0.4", features = ["system-tray"] } log = "0.4.17" csv = "1.1.6" thiserror = "1.0.38" walkdir = "2.3.2" regex = "1.7.0" -# tokio = { version = "1.23.0", features = ["macros"] } +tokio = { version = "1.23.0", features = ["macros"] } # reqwest = "0.11.13" [dependencies.tauri-plugin-log] diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 93d87bf..690860f 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -279,20 +279,32 @@ pub fn menu_handler(event: WindowMenuEvent) { // --- SystemTray Menu pub fn tray_menu() -> SystemTray { + if cfg!(target_os = "macos") { + return 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_native_item(SystemTrayMenuItem::Separator) + .add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")), + ); + } + 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_native_item(SystemTrayMenuItem::Separator) .add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")), ) diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs index 65f5be1..5a77aaf 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -1,49 +1,49 @@ use crate::{app::window, conf::ChatConfJson, utils}; use log::info; -use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, Manager}; +use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, GlobalShortcutManager, Manager}; pub fn init(app: &mut App) -> std::result::Result<(), Box> { + info!("stepup"); let chat_conf = ChatConfJson::get_chat_conf(); let url = chat_conf.origin.to_string(); let theme = ChatConfJson::theme(); let handle = app.app_handle(); - std::thread::spawn(move || { + tokio::spawn(async move { window::tray_window(&handle); }); - info!("stepup"); + { + info!("global_shortcut_start"); + let handle = app.app_handle(); + let mut shortcut = app.global_shortcut_manager(); + let core_shortcut = shortcut.is_registered("CmdOrCtrl+Shift+O"); - // fix: Global shortcuts can cause programs to exit under windows - // { - // info!("global_shortcut_start"); - // let handle = app.app_handle(); - // let mut shortcut = app.global_shortcut_manager(); - // let is_mini_key = shortcut.is_registered("CmdOrCtrl+Shift+O"); + info!("is_registered: {}", core_shortcut.is_ok()); - // if is_mini_key.is_ok() { - // shortcut - // .register("CmdOrCtrl+Shift+O", move || { - // if let Some(w) = handle.get_window("core") { - // if w.is_visible().unwrap() { - // w.hide().unwrap(); - // } else { - // w.show().unwrap(); - // w.set_focus().unwrap(); - // } - // } - // }) - // .unwrap(); - // }; - // info!("global_shortcut_end"); - // } + if core_shortcut.is_ok() { + shortcut + .register("CmdOrCtrl+Shift+O", move || { + if let Some(w) = handle.get_window("core") { + if w.is_visible().unwrap() { + w.hide().unwrap(); + } else { + w.show().unwrap(); + w.set_focus().unwrap(); + } + } + }) + .unwrap(); + }; + info!("global_shortcut_end"); + } if chat_conf.hide_dock_icon { #[cfg(target_os = "macos")] app.set_activation_policy(tauri::ActivationPolicy::Accessory); } else { let app = app.handle(); - std::thread::spawn(move || { + tokio::spawn(async move { #[cfg(target_os = "macos")] WindowBuilder::new(&app, "core", WindowUrl::App(url.into())) .title("ChatGPT") diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index 64e90cc..55c171e 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -6,7 +6,7 @@ pub fn tray_window(handle: &tauri::AppHandle) { let theme = conf::ChatConfJson::theme(); let app = handle.clone(); - std::thread::spawn(move || { + tokio::spawn(async move { WindowBuilder::new(&app, "tray", WindowUrl::App(chat_conf.origin.into())) .title("ChatGPT") .resizable(false) @@ -28,7 +28,7 @@ pub fn tray_window(handle: &tauri::AppHandle) { pub fn control_window(handle: &tauri::AppHandle) { let app = handle.clone(); - std::thread::spawn(move || { + tokio::spawn(async move { WindowBuilder::new(&app, "main", WindowUrl::App("index.html".into())) .title("ChatGPT") .resizable(true) diff --git a/src-tauri/src/assets/cmd.js b/src-tauri/src/assets/cmd.js index 245454f..6c712d1 100644 --- a/src-tauri/src/assets/cmd.js +++ b/src-tauri/src/assets/cmd.js @@ -13,13 +13,30 @@ function init() { z-index: 9999; } .chat-model-cmd-list>div { - border: solid 2px #d8d8d8; + border: solid 2px rgba(80,80,80,.3); border-radius: 5px; background-color: #fff; } + + html.dark .chat-model-cmd-list>div { + background-color: #4a4a4a; + } + html.dark .chat-model-cmd-list .cmd-item { + border-color: #666; + } + html.dark .chat-model-cmd-list .cmd-item b { + color: #e8e8e8; + } + html.dark .chat-model-cmd-list .cmd-item i { + color: #999; + } + html.dark .chat-model-cmd-list .cmd-item.selected { + background: rgba(59,130,246,.5); + } + .chat-model-cmd-list .cmd-item { font-size: 12px; - border-bottom: solid 1px #888; + border-bottom: solid 1px rgba(80,80,80,.2); padding: 2px 4px; display: flex; user-select: none; @@ -29,7 +46,7 @@ function init() { border-bottom: none; } .chat-model-cmd-list .cmd-item.selected { - background: #fea; + background: rgba(59,130,246,.3); } .chat-model-cmd-list .cmd-item b { display: inline-block; @@ -173,9 +190,6 @@ async function cmdTip() { delete window.__CHAT_MODEL_CMD_PROMPT__; } - console.log('«174» /src/assets/cmd.js ~> ', window.__CHAT_MODEL_CMD_PROMPT__); - - // ------------------ send -------------------------------------------------------------------- if (event.keyCode === 13 && window.__CHAT_MODEL_CMD_PROMPT__) { // Enter const data = searchInput.value.split('|->'); diff --git a/src-tauri/src/conf.rs b/src-tauri/src/conf.rs index 921804f..a72a5da 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -1,5 +1,6 @@ use crate::utils::{chat_root, create_file, exists}; use anyhow::Result; +use log::info; use serde_json::Value; use std::{collections::BTreeMap, fs, path::PathBuf, sync::Mutex}; use tauri::{Manager, Theme}; @@ -7,8 +8,8 @@ use tauri::{Manager, Theme}; #[cfg(target_os = "macos")] use tauri::TitleBarStyle; -// pub const USER_AGENT: &str = "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"; -// pub const PHONE_USER_AGENT: &str = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"; +// pub const USER_AGENT: &str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15"; +// pub const PHONE_USER_AGENT: &str = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1"; pub const ISSUES_URL: &str = "https://github.com/lencx/ChatGPT/issues"; pub const UPDATE_LOG_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/UPDATE_LOG.md"; @@ -66,6 +67,7 @@ impl ChatConfJson { /// init chat.conf.json /// path: ~/.chatgpt/chat.conf.json pub fn init() -> PathBuf { + info!("chat_conf_init"); let conf_file = ChatConfJson::conf_path(); let content = if cfg!(target_os = "macos") { DEFAULT_CHAT_CONF_MAC diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c94338e..7c6d3f3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -15,7 +15,8 @@ use tauri_plugin_log::{ LogTarget, LoggerBuilder, }; -fn main() { +#[tokio::main] +async fn main() { ChatConfJson::init(); // If the file does not exist, creating the file will block menu synchronization utils::create_chatgpt_prompts(); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index cac6ed8..d471aaf 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -7,7 +7,7 @@ }, "package": { "productName": "ChatGPT", - "version": "0.7.2" + "version": "0.7.3" }, "tauri": { "allowlist": { @@ -30,8 +30,8 @@ } }, "systemTray": { - "iconPath": "icons/tray-icon-light.png", - "iconAsTemplate": false, + "iconPath": "icons/tray-icon.png", + "iconAsTemplate": true, "menuOnLeftClick": false }, "bundle": {