Skip to content

Commit 14cef73

Browse files
committed
fix: hotkey stops working when mac sleeps
used AI to find and implement this fix
1 parent aabc3dd commit 14cef73

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub enum Message {
118118
FileSearchClear,
119119
SetFileSearchSender(tokio::sync::watch::Sender<(String, Vec<String>)>),
120120
DebouncedSearch(Id),
121+
CheckEventTap,
121122
}
122123

123124
#[derive(Debug, Clone)]

src/app/tile.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ impl Tile {
266266
Subscription::run(handle_recipient),
267267
Subscription::run(reload_events),
268268
Subscription::run(handle_version_and_rankings),
269+
Subscription::run(check_event_tap),
269270
Subscription::run(handle_clipboard_history),
270271
Subscription::run(handle_file_search),
271272
window::close_events().map(Message::HideWindow),
@@ -794,6 +795,15 @@ fn reload_events() -> impl futures::Stream<Item = Message> {
794795
})
795796
}
796797

798+
fn check_event_tap() -> impl futures::Stream<Item = Message> {
799+
stream::channel(100, async |mut output| {
800+
loop {
801+
tokio::time::sleep(Duration::from_secs(5)).await;
802+
output.send(Message::CheckEventTap).await.ok();
803+
}
804+
})
805+
}
806+
797807
fn handle_version_and_rankings() -> impl futures::Stream<Item = Message> {
798808
stream::channel(100, async |mut output| {
799809
loop {

src/app/tile/update.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,18 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
948948
Task::none()
949949
}
950950

951+
Message::CheckEventTap => {
952+
info!("Re-creating global event tap");
953+
if let Some(ref sender) = tile.sender {
954+
tile.hotkeys.handle = None;
955+
match global_handler(sender.clone(), tile.hotkeys.all_hotkeys()) {
956+
Ok(handle) => tile.hotkeys.handle = Some(handle),
957+
Err(e) => log::error!("Failed to re-create event tap: {e}"),
958+
}
959+
}
960+
Task::none()
961+
}
962+
951963
Message::DebouncedSearch(id) => {
952964
// Only execute if this is still the most recent debounce timer
953965
if !tile.debouncer.is_ready() {

0 commit comments

Comments
 (0)