diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index 31259e680..c457bc7ac 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -1,5 +1,10 @@ # UPDATE LOG +## v0.7.4 + +fix: +- customize global shortcuts (`Menu -> Preferences -> Control Center -> General -> Global Shortcut`) + ## v0.7.3 chore: diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs index 5a77aafc4..f9105d2c7 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -13,30 +13,25 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box window::tray_window(&handle); }); - { - info!("global_shortcut_start"); + if let Some(v) = chat_conf.global_shortcut { + info!("global_shortcut"); let handle = app.app_handle(); let mut shortcut = app.global_shortcut_manager(); - let core_shortcut = shortcut.is_registered("CmdOrCtrl+Shift+O"); - - info!("is_registered: {}", core_shortcut.is_ok()); - - 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"); - } + shortcut.register(&v, 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_or_else(|err| { + info!("global_shortcut_register_error: {}", err); + }); + } else { + info!("global_shortcut_unregister"); + }; 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 a72a5da28..cf2e1f5bf 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -18,6 +18,7 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{ "stay_on_top": false, "theme": "Light", "titlebar": true, + "global_shortcut": "", "hide_dock_icon": false, "default_origin": "https://chat.openai.com", "origin": "https://chat.openai.com", @@ -28,6 +29,7 @@ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{ "stay_on_top": false, "theme": "Light", "titlebar": false, + "global_shortcut": "", "hide_dock_icon": false, "default_origin": "https://chat.openai.com", "origin": "https://chat.openai.com", @@ -61,6 +63,7 @@ pub struct ChatConfJson { pub origin: String, pub ua_window: String, pub ua_tray: String, + pub global_shortcut: Option, } impl ChatConfJson { diff --git a/src/view/General.tsx b/src/view/General.tsx index 5e7dbbeaf..20f29b936 100644 --- a/src/view/General.tsx +++ b/src/view/General.tsx @@ -17,6 +17,24 @@ const OriginLabel = ({ url }: { url: string }) => { ) } +const GlobalShortcut = () => { + return ( +
+ Global Shortcut + {' '} + +
Shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q
+
If empty, the shortcut is disabled.
+ https://tauri.app/v1/api/js/globalshortcut +
+ )}> + + + + ) +} + export default function General() { const [form] = Form.useForm(); const [platformInfo, setPlatform] = useState(''); @@ -71,6 +89,9 @@ export default function General() { + } name="global_shortcut"> + + {platformInfo === 'darwin' && (