Global shortcut now hides the main window when the window is already open

This commit is contained in:
Benno 2025-02-11 20:12:35 +01:00 committed by Exidex
parent 8c017baedd
commit c8b3cfe09c
No known key found for this signature in database
GPG key ID: AC63AA86DD4F2D45
4 changed files with 13 additions and 1 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
/node_modules
/.direnv
result
.DS_Store

View file

@ -9,6 +9,7 @@ For changes in `@project-gauntlet/tools` see [separate CHANGELOG.md](https://git
## [Unreleased]
- Global shortcut how hides the main window if it is already open
- It is now possible to run commands and open views using CLI command
- Format: `gauntlet run <plugin-id> <entrypoint-id> <action-id>`
- Plugin ID can be found in Settings UI

View file

@ -17,7 +17,7 @@ pub fn register_listener(msg_sender: Sender<AppMsg>) {
if let global_hotkey::HotKeyState::Released = e.state() {
handle.spawn(async move {
if let Err(err) = msg_sender.send(AppMsg::ShowWindow).await {
if let Err(err) = msg_sender.send(AppMsg::ToggleWindowFocus).await {
tracing::warn!(target = "rpc", "error occurred when receiving shortcut event {:?}", err)
}
});

View file

@ -245,6 +245,7 @@ pub enum AppMsg {
FontLoaded(Result<(), font::Error>),
ShowWindow,
HideWindow,
ToggleWindowFocus,
ToggleActionPanel {
keyboard: bool,
},
@ -1132,6 +1133,7 @@ fn update(state: &mut AppModel, message: AppMsg) -> Task<AppMsg> {
result.expect("unable to load font");
Task::none()
}
AppMsg::ToggleWindowFocus => state.toggle_window_focus(),
AppMsg::ShowWindow => state.show_window(),
AppMsg::HideWindow => state.hide_window(),
AppMsg::ShowPreferenceRequiredView {
@ -2203,6 +2205,14 @@ impl AppModel {
}
}
fn toggle_window_focus(&mut self) -> Task<AppMsg> {
if self.focused {
self.hide_window()
} else {
self.show_window()
}
}
fn hide_window(&mut self) -> Task<AppMsg> {
self.focused = false;
self.opened = false;