Skip to content

Commit 8228052

Browse files
authored
Merge pull request #274 from RustCastLabs/hotkey-sleep-fix
Hotkey sleep fix
2 parents aabc3dd + a158c4e commit 8228052

4 files changed

Lines changed: 23 additions & 23 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use crate::app::menubar::menu_icon;
3232
use crate::app::tile::AppIndex;
3333
use crate::app::{Message, Page, tile::Tile};
3434
use crate::autoupdate::download_latest_app;
35-
use crate::autoupdate::relaunch_app;
3635
use crate::calculator::Expr;
3736
use crate::commands::Function;
3837
use crate::config::Config;
@@ -154,7 +153,6 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
154153
if tile.config.auto_update {
155154
thread::spawn(|| {
156155
download_latest_app().ok();
157-
relaunch_app();
158156
});
159157
}
160158
Task::done(Message::ReloadConfig)
@@ -948,6 +946,18 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
948946
Task::none()
949947
}
950948

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

src/autoupdate.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,6 @@ fn copy_dir_recursive(src: &std::path::Path, dst: &std::path::Path) -> std::io::
188188
Ok(())
189189
}
190190

191-
pub fn relaunch_app() {
192-
let app_path = match get_app_path() {
193-
Some(p) => p,
194-
None => {
195-
error!("Could not determine current app path for relaunch");
196-
return;
197-
}
198-
};
199-
200-
match std::process::Command::new("open").arg(&app_path).spawn() {
201-
Ok(_) => {
202-
info!("Relaunching app at {:?}", app_path);
203-
std::thread::sleep(std::time::Duration::from_millis(500));
204-
std::process::exit(0);
205-
}
206-
Err(e) => {
207-
error!("Could not relaunch app: {e}");
208-
}
209-
}
210-
}
211-
212191
pub fn get_app_path() -> Option<std::path::PathBuf> {
213192
let exe = std::env::current_exe().ok()?;
214193

0 commit comments

Comments
 (0)