diff --git a/amadeus/src/app.rs b/amadeus/src/app.rs index 5bd13df5a226bb0f4c0461a2b941326a669c8a7a..2d9295484095808fc5cf1a45c3c40e2519784b63 100644 --- a/amadeus/src/app.rs +++ b/amadeus/src/app.rs @@ -377,6 +377,7 @@ impl Amadeus { let cfg = self.connect_config.clone(); match req { ChangePlayback(state) => send(set_playback_state(cfg, state)), + TogglePlaybackState => send(toggle_playback_state(self.connect_config.clone())), PlayNext => send(play_next(cfg)), PlayPrevious => send(play_previous(cfg)), } @@ -497,26 +498,6 @@ impl Amadeus { } } - /// Handle the Event message. For now we only handle some keyboard events. - fn handle_event(&mut self, event: Event) -> Command<<Self as Application>::Message> { - match event { - Event::Keyboard(KbdEvent::KeyReleased { - key_code, - modifiers, - }) => match key_code { - KeyCode::Space => send(toggle_playback_state(self.connect_config.clone())), - KeyCode::N if modifiers.control() => { - Command::perform(async {}, |_| PlaybackRequest::PlayNext.into()) - } - KeyCode::P if modifiers.control() => { - Command::perform(async {}, |_| PlaybackRequest::PlayPrevious.into()) - } - _ => Command::none(), - }, - _ => Command::none(), - } - } - fn playlist_list(&self) -> &[Arc<str>] { self.sidebar.playlist_list() } @@ -625,7 +606,6 @@ impl Application for Amadeus { Message::ExitApplication => iced::window::close(), // Messages got from subscriptions. - Message::Event(event) => self.handle_event(event), Message::Tick(instant) => { let delta = instant.saturating_duration_since(self.last_instant); self.last_instant = instant; @@ -816,7 +796,18 @@ impl Application for Amadeus { /// We need a tick every second to query lektord plus we listen for any event. fn subscription(&self) -> iced::Subscription<Self::Message> { iced::Subscription::batch([ - iced::subscription::events().map(Message::Event), + iced::subscription::events().map(|event| match event { + Event::Keyboard(KbdEvent::KeyReleased { + key_code, + modifiers, + }) => match key_code { + KeyCode::Space => PlaybackRequest::TogglePlaybackState.into(), + KeyCode::N if modifiers.control() => PlaybackRequest::PlayNext.into(), + KeyCode::P if modifiers.control() => PlaybackRequest::PlayPrevious.into(), + _ => Message::None, + }, + _ => Message::None, + }), iced::time::every(iced::time::Duration::new(1, 0)).map(Message::Tick), ]) } diff --git a/amadeus/src/message.rs b/amadeus/src/message.rs index 4fc437ff053247ff2de1bf74ed353a1539ccf9ba..a3ddca6d7d98713da9280723a0ca5730e3064b84 100644 --- a/amadeus/src/message.rs +++ b/amadeus/src/message.rs @@ -20,6 +20,7 @@ pub enum MainPanelDisplay { #[derive(Debug, Clone, Copy)] pub enum PlaybackRequest { ChangePlayback(PlayState), + TogglePlaybackState, PlayNext, PlayPrevious, } @@ -44,9 +45,6 @@ pub enum Message { /// We got a tick. Tick(iced::time::Instant), - /// We got an event. - Event(iced::Event), - /// Open the issues link with firefox. OpenLinkInBrowser(&'static str),