Skip to content

Commit b1b2097

Browse files
lencxSomsak Meesangpetch
authored and
Somsak Meesangpetch
committed
fix: customize global shortcuts (lencx#108)
1 parent e169198 commit b1b2097

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

UPDATE_LOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# UPDATE LOG
22

3+
## v0.7.4
4+
5+
fix:
6+
- customize global shortcuts (`Menu -> Preferences -> Control Center -> General -> Global Shortcut`)
7+
38
## v0.7.3
49

510
chore:

src-tauri/src/app/setup.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,25 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
1313
window::tray_window(&handle);
1414
});
1515

16-
{
17-
info!("global_shortcut_start");
16+
if let Some(v) = chat_conf.global_shortcut {
17+
info!("global_shortcut");
1818
let handle = app.app_handle();
1919
let mut shortcut = app.global_shortcut_manager();
20-
let core_shortcut = shortcut.is_registered("CmdOrCtrl+Shift+O");
21-
22-
info!("is_registered: {}", core_shortcut.is_ok());
23-
24-
if core_shortcut.is_ok() {
25-
shortcut
26-
.register("CmdOrCtrl+Shift+O", move || {
27-
if let Some(w) = handle.get_window("core") {
28-
if w.is_visible().unwrap() {
29-
w.hide().unwrap();
30-
} else {
31-
w.show().unwrap();
32-
w.set_focus().unwrap();
33-
}
34-
}
35-
})
36-
.unwrap();
37-
};
38-
info!("global_shortcut_end");
39-
}
20+
shortcut.register(&v, move|| {
21+
if let Some(w) = handle.get_window("core") {
22+
if w.is_visible().unwrap() {
23+
w.hide().unwrap();
24+
} else {
25+
w.show().unwrap();
26+
w.set_focus().unwrap();
27+
}
28+
}
29+
}).unwrap_or_else(|err| {
30+
info!("global_shortcut_register_error: {}", err);
31+
});
32+
} else {
33+
info!("global_shortcut_unregister");
34+
};
4035

4136
if chat_conf.hide_dock_icon {
4237
#[cfg(target_os = "macos")]

src-tauri/src/conf.rs

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{
1818
"stay_on_top": false,
1919
"theme": "Light",
2020
"titlebar": true,
21+
"global_shortcut": "",
2122
"hide_dock_icon": false,
2223
"default_origin": "https://chat.openai.com",
2324
"origin": "https://chat.openai.com",
@@ -28,6 +29,7 @@ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{
2829
"stay_on_top": false,
2930
"theme": "Light",
3031
"titlebar": false,
32+
"global_shortcut": "",
3133
"hide_dock_icon": false,
3234
"default_origin": "https://chat.openai.com",
3335
"origin": "https://chat.openai.com",
@@ -61,6 +63,7 @@ pub struct ChatConfJson {
6163
pub origin: String,
6264
pub ua_window: String,
6365
pub ua_tray: String,
66+
pub global_shortcut: Option<String>,
6467
}
6568

6669
impl ChatConfJson {

src/view/General.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ const OriginLabel = ({ url }: { url: string }) => {
1717
)
1818
}
1919

20+
const GlobalShortcut = () => {
21+
return (
22+
<div>
23+
Global Shortcut
24+
{' '}
25+
<Tooltip title={(
26+
<div>
27+
<div>Shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q</div>
28+
<div style={{ margin: '10px 0'}}>If empty, the shortcut is disabled.</div>
29+
<a href="https://tauri.app/v1/api/js/globalshortcut" target="_blank">https://tauri.app/v1/api/js/globalshortcut</a>
30+
</div>
31+
)}>
32+
<QuestionCircleOutlined />
33+
</Tooltip>
34+
</div>
35+
)
36+
}
37+
2038
export default function General() {
2139
const [form] = Form.useForm();
2240
const [platformInfo, setPlatform] = useState<string>('');
@@ -71,6 +89,9 @@ export default function General() {
7189
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">
7290
<Switch />
7391
</Form.Item>
92+
<Form.Item label={<GlobalShortcut />} name="global_shortcut">
93+
<Input placeholder="CmdOrCtrl+Shift+O" {...DISABLE_AUTO_COMPLETE} />
94+
</Form.Item>
7495
{platformInfo === 'darwin' && (
7596
<Form.Item label="Titlebar" name="titlebar" valuePropName="checked">
7697
<Switch />

0 commit comments

Comments
 (0)