Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub enum Message {
FileSearchClear,
SetFileSearchSender(tokio::sync::watch::Sender<(String, Vec<String>)>),
DebouncedSearch(Id),
CheckEventTap,
}

#[derive(Debug, Clone)]
Expand Down
10 changes: 10 additions & 0 deletions src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ impl Tile {
Subscription::run(handle_recipient),
Subscription::run(reload_events),
Subscription::run(handle_version_and_rankings),
Subscription::run(check_event_tap),
Subscription::run(handle_clipboard_history),
Subscription::run(handle_file_search),
window::close_events().map(Message::HideWindow),
Expand Down Expand Up @@ -794,6 +795,15 @@ fn reload_events() -> impl futures::Stream<Item = Message> {
})
}

fn check_event_tap() -> impl futures::Stream<Item = Message> {
stream::channel(100, async |mut output| {
loop {
tokio::time::sleep(Duration::from_secs(5)).await;
output.send(Message::CheckEventTap).await.ok();
}
})
}

fn handle_version_and_rankings() -> impl futures::Stream<Item = Message> {
stream::channel(100, async |mut output| {
loop {
Expand Down
14 changes: 12 additions & 2 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use crate::app::menubar::menu_icon;
use crate::app::tile::AppIndex;
use crate::app::{Message, Page, tile::Tile};
use crate::autoupdate::download_latest_app;
use crate::autoupdate::relaunch_app;
use crate::calculator::Expr;
use crate::commands::Function;
use crate::config::Config;
Expand Down Expand Up @@ -154,7 +153,6 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
if tile.config.auto_update {
thread::spawn(|| {
download_latest_app().ok();
relaunch_app();
});
}
Task::done(Message::ReloadConfig)
Expand Down Expand Up @@ -948,6 +946,18 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
Task::none()
}

Message::CheckEventTap => {
info!("Re-creating global event tap");
if let Some(ref sender) = tile.sender {
tile.hotkeys.handle = None;
match global_handler(sender.clone(), tile.hotkeys.all_hotkeys()) {
Ok(handle) => tile.hotkeys.handle = Some(handle),
Err(e) => log::error!("Failed to re-create event tap: {e}"),
}
}
Task::none()
}

Message::DebouncedSearch(id) => {
// Only execute if this is still the most recent debounce timer
if !tile.debouncer.is_ready() {
Expand Down
21 changes: 0 additions & 21 deletions src/autoupdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,6 @@ fn copy_dir_recursive(src: &std::path::Path, dst: &std::path::Path) -> std::io::
Ok(())
}

pub fn relaunch_app() {
let app_path = match get_app_path() {
Some(p) => p,
None => {
error!("Could not determine current app path for relaunch");
return;
}
};

match std::process::Command::new("open").arg(&app_path).spawn() {
Ok(_) => {
info!("Relaunching app at {:?}", app_path);
std::thread::sleep(std::time::Duration::from_millis(500));
std::process::exit(0);
}
Err(e) => {
error!("Could not relaunch app: {e}");
}
}
}

pub fn get_app_path() -> Option<std::path::PathBuf> {
let exe = std::env::current_exe().ok()?;

Expand Down
Loading