Skip to content

Commit 1e2c978

Browse files
authored
Merge branch 'master' into favourited-apps
2 parents cfbf55f + 60c698e commit 1e2c978

5 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/app/tile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub struct Tile {
192192
pub struct Hotkeys {
193193
pub toggle: HotKey,
194194
pub clipboard_hotkey: HotKey,
195+
pub shells: HashMap<u32, String>,
195196
}
196197

197198
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
@@ -285,6 +285,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
285285
}
286286

287287
Message::KeyPressed(hk_id) => {
288+
if let Some(cmd) = tile.hotkeys.shells.get(&hk_id) {
289+
return Task::done(Message::RunFunction(Function::RunShellCommand(cmd.clone())));
290+
}
291+
288292
let is_clipboard_hotkey = tile.hotkeys.clipboard_hotkey.id == hk_id;
289293
let is_open_hotkey = hk_id == tile.hotkeys.toggle.id;
290294

src/config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ impl Default for Buffer {
189189
/// Alias is the text that is used to call this command / search for it
190190
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
191191
pub struct Shelly {
192-
command: String,
193-
icon_path: Option<String>,
194-
alias: String,
195-
alias_lc: String,
192+
pub command: String,
193+
pub icon_path: Option<String>,
194+
pub alias: String,
195+
pub alias_lc: String,
196+
pub hotkey: Option<String>,
196197
}
197198

198199
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)