Skip to content

Commit 738369b

Browse files
authored
Merge branch 'master' into settings-page
2 parents c3785a2 + 60c698e commit 738369b

5 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/app/tile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub struct Tile {
179179
pub struct Hotkeys {
180180
pub toggle: HotKey,
181181
pub clipboard_hotkey: HotKey,
182+
pub shells: HashMap<u32, String>,
182183
}
183184

184185
impl Tile {

src/app/tile/elm.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,22 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
6060
options.par_sort_by_key(|x| x.display_name.len());
6161
let options = AppIndex::from_apps(options);
6262

63+
let mut shells_map = HashMap::new();
64+
for shell in &config.shells {
65+
if let Some(hk_str) = &shell.hotkey
66+
&& let Ok(hk) = hk_str.parse::<HotKey>()
67+
{
68+
shells_map.insert(hk.id, shell.command.clone());
69+
}
70+
}
71+
6372
let hotkeys = Hotkeys {
6473
toggle: hotkey,
6574
clipboard_hotkey: config
6675
.clipboard_hotkey
6776
.parse()
6877
.unwrap_or("SUPER+SHIFT+C".parse().unwrap()),
78+
shells: shells_map,
6979
};
7080

7181
let home = std::env::var("HOME").unwrap_or("/".to_string());

src/app/tile/update.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
291291
}
292292

293293
Message::KeyPressed(hk_id) => {
294+
if let Some(cmd) = tile.hotkeys.shells.get(&hk_id) {
295+
return Task::done(Message::RunFunction(Function::RunShellCommand(cmd.clone())));
296+
}
297+
294298
let is_clipboard_hotkey = tile.hotkeys.clipboard_hotkey.id == hk_id;
295299
let is_open_hotkey = hk_id == tile.hotkeys.toggle.id;
296300

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ pub struct Shelly {
184184
pub icon_path: Option<String>,
185185
pub alias: String,
186186
pub alias_lc: String,
187+
pub hotkey: Option<String>,
187188
}
188189

189190
impl ToApp for Shelly {

src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,18 @@ fn main() -> iced::Result {
7676
.parse()
7777
.unwrap_or("SUPER+SHIFT+C".parse().unwrap());
7878

79-
let hotkeys = vec![show_hide, cbhist];
79+
let mut hotkeys = vec![show_hide, cbhist];
80+
for shell in &config.shells {
81+
if let Some(hk_str) = &shell.hotkey
82+
&& let Ok(hk) = hk_str.parse::<HotKey>()
83+
{
84+
hotkeys.push(hk);
85+
}
86+
}
8087

8188
manager
8289
.register_all(&hotkeys)
83-
.expect("Unable to register hotkey");
90+
.expect("Unable to register hotkeys");
8491

8592
info!("Hotkeys loaded");
8693
info!("Starting rustcast");

0 commit comments

Comments
 (0)