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
19 changes: 17 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ objc2 = "0.6.3"
objc2-app-kit = { version = "0.3.2", features = ["NSImage"] }
objc2-application-services = { version = "0.3.2", default-features = false, features = ["HIServices", "Processes"] }
objc2-core-foundation = "0.3.2"
objc2-core-graphics = { version = "0.3.2", features = ["CGEvent"] }
objc2-event-kit = "0.3.2"
objc2-foundation = { version = "0.3.2", features = ["NSDateFormatter", "NSFormatter", "NSString"] }
objc2-service-management = "0.3.2"
Expand Down
16 changes: 15 additions & 1 deletion src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::config::{Config, Shelly};
use crate::debounce::Debouncer;
use crate::platform::default_app_paths;
use crate::platform::macos::events::Event;
use crate::platform::macos::launching::Shortcut;
use crate::platform::macos::launching::{EventTapHandle, Shortcut};

use arboard::Clipboard;

Expand Down Expand Up @@ -207,11 +207,25 @@ pub struct Tile {
/// Stores the toggle [`HotKey`] and the Clipboard [`HotKey`]
#[derive(Clone, Debug)]
pub struct Hotkeys {
pub handle: Option<EventTapHandle>,
pub toggle: Shortcut,
pub clipboard_hotkey: Shortcut,
pub shells: HashMap<Shortcut, Shelly>,
}

impl Hotkeys {
pub fn all_hotkeys(&self) -> Vec<Shortcut> {
let mut a = vec![self.toggle.clone(), self.clipboard_hotkey.clone()];
a.extend(
self.shells
.keys()
.map(|x| x.to_owned())
.collect::<Vec<Shortcut>>(),
);
a
}
}

impl Tile {
/// This returns the theme of the window
pub fn theme(&self, _: window::Id) -> Option<Theme> {
Expand Down
19 changes: 15 additions & 4 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {

Message::SetSender(sender) => {
tile.sender = Some(sender.clone());
global_handler(sender.clone());
match global_handler(sender.clone(), tile.hotkeys.all_hotkeys()) {
Ok(a) => tile.hotkeys.handle = Some(a),
Err(e) => {
log::error!("Error when registering hotkey: {e}");
std::process::exit(1);
}
};
if tile.config.show_trayicon {
tile.tray_icon = Some(menu_icon(tile.config.clone(), sender));
}
Expand Down Expand Up @@ -413,7 +419,11 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {

tile.theme = new_config.theme.to_owned().into();
tile.config = new_config;
Task::batch([Task::done(Message::LoadRanking), update_apps_task])
Task::batch([
Task::done(Message::LoadRanking),
update_apps_task,
Task::done(Message::SetSender(tile.sender.clone().unwrap())),
])
}

Message::KeyPressed(shortcut) => {
Expand Down Expand Up @@ -760,7 +770,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {

Message::SetConfig(config) => {
let mut final_config = tile.config.clone();
match config {
match config.clone() {
SetConfigFields::ToggleHotkey(hk) => final_config.toggle_hotkey = hk,
SetConfigFields::ClipboardHotkey(hk) => final_config.clipboard_hotkey = hk,
SetConfigFields::ClipboardHistory(cbhist) => final_config.cbhist = cbhist,
Expand Down Expand Up @@ -1120,7 +1130,7 @@ fn execute_query(tile: &mut Tile, id: Id) -> Task<Message> {
_ => {}
}

let deferred_action = if let Some(action) =
let _deferred_action = if let Some(action) =
classify_query_action(&tile.page, &tile.query, &tile.query_lc)
{
match action {
Expand Down Expand Up @@ -1300,6 +1310,7 @@ mod tests {
toggle: Shortcut::parse("alt+space").unwrap(),
clipboard_hotkey: Shortcut::parse("cmd+shift+c").unwrap(),
shells: HashMap::new(),
handle: None,
},
clipboard_content: Vec::new(),
tray_icon: None,
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod utils;

use std::{collections::HashMap, fs::OpenOptions, path::Path};

use rustcast::{
use crate::{
app::tile::{self, Hotkeys, Tile},
config::Config,
platform::macos::{get_autostart_status, launching::Shortcut},
Expand All @@ -24,7 +24,7 @@ use rustcast::{
use log::info;
use tracing_subscriber::{EnvFilter, Layer, util::SubscriberInitExt};

use rustcast::platform::set_activation_policy_accessory;
use crate::platform::set_activation_policy_accessory;

fn main() -> iced::Result {
set_activation_policy_accessory();
Expand Down Expand Up @@ -84,6 +84,7 @@ fn main() -> iced::Result {
toggle: show_hide,
clipboard_hotkey: cbhist,
shells: shell_map,
handle: None,
};

info!("Hotkeys loaded");
Expand Down
Loading
Loading