mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
fix: customize global shortcuts (#108)
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
# UPDATE LOG
|
# UPDATE LOG
|
||||||
|
|
||||||
|
## v0.7.4
|
||||||
|
|
||||||
|
fix:
|
||||||
|
- customize global shortcuts (`Menu -> Preferences -> Control Center -> General -> Global Shortcut`)
|
||||||
|
|
||||||
## v0.7.3
|
## v0.7.3
|
||||||
|
|
||||||
chore:
|
chore:
|
||||||
|
|||||||
@@ -13,30 +13,25 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
|
|||||||
window::tray_window(&handle);
|
window::tray_window(&handle);
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
if let Some(v) = chat_conf.global_shortcut {
|
||||||
info!("global_shortcut_start");
|
info!("global_shortcut");
|
||||||
let handle = app.app_handle();
|
let handle = app.app_handle();
|
||||||
let mut shortcut = app.global_shortcut_manager();
|
let mut shortcut = app.global_shortcut_manager();
|
||||||
let core_shortcut = shortcut.is_registered("CmdOrCtrl+Shift+O");
|
shortcut.register(&v, move|| {
|
||||||
|
if let Some(w) = handle.get_window("core") {
|
||||||
info!("is_registered: {}", core_shortcut.is_ok());
|
if w.is_visible().unwrap() {
|
||||||
|
w.hide().unwrap();
|
||||||
if core_shortcut.is_ok() {
|
} else {
|
||||||
shortcut
|
w.show().unwrap();
|
||||||
.register("CmdOrCtrl+Shift+O", move || {
|
w.set_focus().unwrap();
|
||||||
if let Some(w) = handle.get_window("core") {
|
}
|
||||||
if w.is_visible().unwrap() {
|
}
|
||||||
w.hide().unwrap();
|
}).unwrap_or_else(|err| {
|
||||||
} else {
|
info!("global_shortcut_register_error: {}", err);
|
||||||
w.show().unwrap();
|
});
|
||||||
w.set_focus().unwrap();
|
} else {
|
||||||
}
|
info!("global_shortcut_unregister");
|
||||||
}
|
};
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
};
|
|
||||||
info!("global_shortcut_end");
|
|
||||||
}
|
|
||||||
|
|
||||||
if chat_conf.hide_dock_icon {
|
if chat_conf.hide_dock_icon {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{
|
|||||||
"stay_on_top": false,
|
"stay_on_top": false,
|
||||||
"theme": "Light",
|
"theme": "Light",
|
||||||
"titlebar": true,
|
"titlebar": true,
|
||||||
|
"global_shortcut": "",
|
||||||
"hide_dock_icon": false,
|
"hide_dock_icon": false,
|
||||||
"default_origin": "https://chat.openai.com",
|
"default_origin": "https://chat.openai.com",
|
||||||
"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,
|
"stay_on_top": false,
|
||||||
"theme": "Light",
|
"theme": "Light",
|
||||||
"titlebar": false,
|
"titlebar": false,
|
||||||
|
"global_shortcut": "",
|
||||||
"hide_dock_icon": false,
|
"hide_dock_icon": false,
|
||||||
"default_origin": "https://chat.openai.com",
|
"default_origin": "https://chat.openai.com",
|
||||||
"origin": "https://chat.openai.com",
|
"origin": "https://chat.openai.com",
|
||||||
@@ -61,6 +63,7 @@ pub struct ChatConfJson {
|
|||||||
pub origin: String,
|
pub origin: String,
|
||||||
pub ua_window: String,
|
pub ua_window: String,
|
||||||
pub ua_tray: String,
|
pub ua_tray: String,
|
||||||
|
pub global_shortcut: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatConfJson {
|
impl ChatConfJson {
|
||||||
|
|||||||
21
src/view/General.tsx
vendored
21
src/view/General.tsx
vendored
@@ -17,6 +17,24 @@ const OriginLabel = ({ url }: { url: string }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GlobalShortcut = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Global Shortcut
|
||||||
|
{' '}
|
||||||
|
<Tooltip title={(
|
||||||
|
<div>
|
||||||
|
<div>Shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q</div>
|
||||||
|
<div style={{ margin: '10px 0'}}>If empty, the shortcut is disabled.</div>
|
||||||
|
<a href="https://tauri.app/v1/api/js/globalshortcut" target="_blank">https://tauri.app/v1/api/js/globalshortcut</a>
|
||||||
|
</div>
|
||||||
|
)}>
|
||||||
|
<QuestionCircleOutlined />
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default function General() {
|
export default function General() {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [platformInfo, setPlatform] = useState<string>('');
|
const [platformInfo, setPlatform] = useState<string>('');
|
||||||
@@ -71,6 +89,9 @@ export default function General() {
|
|||||||
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">
|
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">
|
||||||
<Switch />
|
<Switch />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item label={<GlobalShortcut />} name="global_shortcut">
|
||||||
|
<Input placeholder="CmdOrCtrl+Shift+O" {...DISABLE_AUTO_COMPLETE} />
|
||||||
|
</Form.Item>
|
||||||
{platformInfo === 'darwin' && (
|
{platformInfo === 'darwin' && (
|
||||||
<Form.Item label="Titlebar" name="titlebar" valuePropName="checked">
|
<Form.Item label="Titlebar" name="titlebar" valuePropName="checked">
|
||||||
<Switch />
|
<Switch />
|
||||||
|
|||||||
Reference in New Issue
Block a user