diff --git a/data/ui/shortcuts.ui b/data/ui/shortcuts.ui index 02bac83..114fbbd 100644 --- a/data/ui/shortcuts.ui +++ b/data/ui/shortcuts.ui @@ -21,6 +21,12 @@ {{ tr(key="sc-gen-close-window") }} + + + F10 + {{ tr(key="sc-gen-menu") }} + + <Ctrl>q diff --git a/delfin.cmb b/delfin.cmb index d5d89e9..ab272cc 100644 --- a/delfin.cmb +++ b/delfin.cmb @@ -21,7 +21,8 @@ (2,15,"GtkShortcutsShortcut",None,3,None,None,None,3,None), (2,16,"GtkShortcutsGroup",None,2,None,None,None,1,None), (2,17,"GtkShortcutsShortcut",None,16,None,None,None,None,None), - (2,18,"GtkShortcutsShortcut",None,16,None,None,None,1,None) + (2,18,"GtkShortcutsShortcut",None,16,None,None,None,1,None), + (2,19,"GtkShortcutsShortcut",None,3,None,None,None,3,None) (2,2,"GtkShortcutsSection","section-name","Video Player",None,None,None,None,None,None,None,None,None), @@ -45,12 +46,14 @@ (2,12,"GtkShortcutsShortcut","title","{{ tr(key=\"sc-vp-frame-step\") }}",None,None,None,None,None,None,None,None,None), (2,14,"GtkShortcutsShortcut","accelerator","<Ctrl>w",None,None,None,None,None,None,None,None,None), (2,14,"GtkShortcutsShortcut","title","{{ tr(key=\"sc-gen-close-window\") }}",None,None,None,None,None,None,None,None,None), - (2,15,"GtkShortcutsShortcut","accelerator","<Ctrl>q",None,None,None,None,None,None,None,None,None), - (2,15,"GtkShortcutsShortcut","title","{{ tr(key=\"sc-gen-quit\") }}",None,None,None,None,None,None,None,None,None), + (2,15,"GtkShortcutsShortcut","accelerator","F10",None,None,None,None,None,None,None,None,None), + (2,15,"GtkShortcutsShortcut","title","{{ tr(key=\"sc-gen-menu\") }}",None,None,None,None,None,None,None,None,None), (2,16,"GtkShortcutsGroup","title","{{ tr(key=\"sc-lib\") }}",None,None,None,None,None,None,None,None,None), (2,17,"GtkShortcutsShortcut","accelerator","<Ctrl>f",None,None,None,None,None,None,None,None,None), (2,17,"GtkShortcutsShortcut","title","{{ tr(key=\"sc-lib-search\") }}",None,None,None,None,None,None,None,None,None), (2,18,"GtkShortcutsShortcut","accelerator","<Ctrl>r",None,None,None,None,None,None,None,None,None), - (2,18,"GtkShortcutsShortcut","title","{{ tr(key=\"sc-lib-refresh\") }}",None,None,None,None,None,None,None,None,None) + (2,18,"GtkShortcutsShortcut","title","{{ tr(key=\"sc-lib-refresh\") }}",None,None,None,None,None,None,None,None,None), + (2,19,"GtkShortcutsShortcut","accelerator","<Ctrl>q",None,None,None,None,None,None,None,None,None), + (2,19,"GtkShortcutsShortcut","title","{{ tr(key=\"sc-gen-quit\") }}",None,None,None,None,None,None,None,None,None) diff --git a/delfin/src/app.rs b/delfin/src/app.rs index 7f3b4bc..6c1e3c4 100644 --- a/delfin/src/app.rs +++ b/delfin/src/app.rs @@ -14,6 +14,7 @@ use std::{ use crate::{ accounts::account_list::{AccountList, AccountListInput, AccountListOutput}, + borgar::borgar_menu::{BorgarMenuInput, BORGAR_MENU_SENDER}, config::{self, general::MostRecentLogin}, globals::CONFIG, jellyfin_api::api_client::ApiClient, @@ -357,10 +358,10 @@ impl App { let mut group = RelmActionGroup::::new(); - let quit_action: RelmAction = RelmAction::new_stateless(|_| { - relm4::main_application().quit(); + let menu_action: RelmAction = RelmAction::new_stateless(|_| { + BORGAR_MENU_SENDER.send(BorgarMenuInput::OpenMenu).unwrap(); }); - app.set_accelerators_for_action::(&["q"]); + app.set_accelerators_for_action::(&["F10"]); let preferences_action: RelmAction = RelmAction::new_stateless({ let sender = sender.clone(); @@ -370,8 +371,14 @@ impl App { }); app.set_accelerators_for_action::(&["comma"]); - group.add_action(quit_action); + let quit_action: RelmAction = RelmAction::new_stateless(|_| { + relm4::main_application().quit(); + }); + app.set_accelerators_for_action::(&["q"]); + + group.add_action(menu_action); group.add_action(preferences_action); + group.add_action(quit_action); group.register_for_main_application(); } } @@ -409,5 +416,6 @@ fn convert_library_output(output: LibraryOutput) -> AppInput { } relm4::new_action_group!(AppActionGroup, "app"); +relm4::new_stateless_action!(MenuAction, AppActionGroup, "menu"); relm4::new_stateless_action!(PreferencesAction, AppActionGroup, "preferences"); relm4::new_stateless_action!(QuitAction, AppActionGroup, "quit"); diff --git a/delfin/src/borgar/borgar_menu.rs b/delfin/src/borgar/borgar_menu.rs index 232d9a2..60f07e1 100644 --- a/delfin/src/borgar/borgar_menu.rs +++ b/delfin/src/borgar/borgar_menu.rs @@ -2,10 +2,13 @@ use std::sync::Arc; use gtk::gio; use gtk::prelude::*; +use once_cell::sync::Lazy; use relm4::{ actions::{AccelsPlus, RelmAction, RelmActionGroup}, + once_cell, prelude::*, }; +use tokio::sync::broadcast; use crate::app::AppInput; use crate::app::APP_BROKER; @@ -19,6 +22,9 @@ use crate::{ use super::about::About; +pub static BORGAR_MENU_SENDER: Lazy> = + Lazy::new(|| broadcast::channel(1).0); + pub struct BorgarMenuAuth { pub api_client: Arc, pub server: Server, @@ -31,8 +37,9 @@ pub struct BorgarMenu { about: Option>, } -#[derive(Debug)] +#[derive(Clone, Copy, Debug)] pub enum BorgarMenuInput { + OpenMenu, SignOut, About, } @@ -122,6 +129,15 @@ impl Component for BorgarMenu { group.register_for_widget(root); + relm4::spawn({ + let mut rx = BORGAR_MENU_SENDER.subscribe(); + async move { + while let Ok(msg) = rx.recv().await { + sender.input(msg); + } + } + }); + ComponentParts { model, widgets } } @@ -132,7 +148,14 @@ impl Component for BorgarMenu { sender: ComponentSender, root: &Self::Root, ) { + if !root.is_mapped() { + return; + } + match message { + BorgarMenuInput::OpenMenu => { + root.activate(); + } BorgarMenuInput::SignOut => 'msg: { let BorgarMenuAuth { api_client, diff --git a/locales/en-US/shortcuts.ftl b/locales/en-US/shortcuts.ftl index a95a193..4755f15 100644 --- a/locales/en-US/shortcuts.ftl +++ b/locales/en-US/shortcuts.ftl @@ -3,6 +3,7 @@ sc-gen = General sc-gen-shortcuts = Show shortcuts sc-gen-close-window = Close window +sc-gen-menu = Open menu sc-gen-quit = Quit # Library # =======