From 3424666ec951c38b3dd2727f903dfb6c2c739236 Mon Sep 17 00:00:00 2001 From: lencx Date: Wed, 28 Dec 2022 11:49:40 +0800 Subject: [PATCH 1/6] chore: tauri conf --- src-tauri/tauri.conf.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index cac6ed8..f910cb1 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -30,8 +30,8 @@ } }, "systemTray": { - "iconPath": "icons/tray-icon-light.png", - "iconAsTemplate": false, + "iconPath": "icons/tray-icon.png", + "iconAsTemplate": true, "menuOnLeftClick": false }, "bundle": { From 9a9fb24de8599900acfe9e297f7bd7f561b63407 Mon Sep 17 00:00:00 2001 From: lencx Date: Thu, 29 Dec 2022 01:41:22 +0800 Subject: [PATCH 2/6] chore: icon & global shortcuts --- README-ZH_CN.md | 2 +- README.md | 2 +- UPDATE_LOG.md | 6 +++++ src-tauri/Cargo.toml | 2 +- src-tauri/src/app/setup.rs | 48 +++++++++++++++++++------------------- src-tauri/src/conf.rs | 6 +++-- 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/README-ZH_CN.md b/README-ZH_CN.md index d2338fb..2d26cc5 100644 --- a/README-ZH_CN.md +++ b/README-ZH_CN.md @@ -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..f745a7b 100644 --- a/README.md +++ b/README.md @@ -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..40d00f5 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -1,5 +1,11 @@ # UPDATE LOG +## v0.7.3 + +chore: +- 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..47c3756 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,7 +17,7 @@ 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" diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs index 65f5be1..2ded0c6 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -1,8 +1,9 @@ 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(); @@ -12,31 +13,30 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box 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")] 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 From f1fa859961452b77f040d0cc51d8e260a24c2ba0 Mon Sep 17 00:00:00 2001 From: lencx Date: Thu, 29 Dec 2022 19:29:33 +0800 Subject: [PATCH 3/6] chore: optim --- README-ZH_CN.md | 2 +- README.md | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/src/app/setup.rs | 4 ++-- src-tauri/src/app/window.rs | 4 ++-- src-tauri/src/main.rs | 3 ++- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README-ZH_CN.md b/README-ZH_CN.md index 2d26cc5..dad137f 100644 --- a/README-ZH_CN.md +++ b/README-ZH_CN.md @@ -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))。使用键盘 `⇧` 和 `⇩`(上下键)来选择斜杠指令。 diff --git a/README.md b/README.md index f745a7b..369ea4f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 47c3756..824bcdc 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -24,7 +24,7 @@ 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/setup.rs b/src-tauri/src/app/setup.rs index 2ded0c6..5a77aaf 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -9,7 +9,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box let theme = ChatConfJson::theme(); let handle = app.app_handle(); - std::thread::spawn(move || { + tokio::spawn(async move { window::tray_window(&handle); }); @@ -43,7 +43,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box 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/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(); From 9cacad01207df7eed190449b1c5dcb03c37cf270 Mon Sep 17 00:00:00 2001 From: lencx Date: Thu, 29 Dec 2022 21:05:21 +0800 Subject: [PATCH 4/6] chore: optim style --- UPDATE_LOG.md | 1 + src-tauri/src/app/menu.rs | 28 ++++++++++++++++++++-------- src-tauri/src/assets/cmd.js | 26 ++++++++++++++++++++------ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index 40d00f5..31259e6 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -3,6 +3,7 @@ ## 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`) 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/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('|->'); From 2ab35bb9254a5e4eff30ab76fc938f8a5a46903b Mon Sep 17 00:00:00 2001 From: lencx Date: Thu, 29 Dec 2022 21:06:29 +0800 Subject: [PATCH 5/6] readme --- README-ZH_CN.md | 6 +++--- README.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README-ZH_CN.md b/README-ZH_CN.md index dad137f..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) diff --git a/README.md b/README.md index 369ea4f..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) From ba21fa85d25465aa63a37f9fba32bcd0ba462840 Mon Sep 17 00:00:00 2001 From: lencx Date: Thu, 29 Dec 2022 21:06:40 +0800 Subject: [PATCH 6/6] v0.7.3 --- src-tauri/tauri.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index f910cb1..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": {