From 9a9fb24de8599900acfe9e297f7bd7f561b63407 Mon Sep 17 00:00:00 2001 From: lencx Date: Thu, 29 Dec 2022 01:41:22 +0800 Subject: [PATCH] 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