From 322000de86767937a342f45e816975662eb3021e Mon Sep 17 00:00:00 2001 From: Avery Date: Mon, 30 Oct 2023 18:09:59 -0400 Subject: [PATCH] Refresh library when navigating back from video player --- delfin/src/library/mod.rs | 15 ++++++++++++++- delfin/src/video_player/session.rs | 6 +++++- delfin/src/video_player/video_player_component.rs | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/delfin/src/library/mod.rs b/delfin/src/library/mod.rs index a8f5357..15e8089 100644 --- a/delfin/src/library/mod.rs +++ b/delfin/src/library/mod.rs @@ -6,7 +6,7 @@ mod media_list; mod media_tile; use jellyfin_api::types::BaseItemDto; -use relm4::ComponentController; +use relm4::{ComponentController, SharedState}; use std::sync::{Arc, RwLock}; use adw::prelude::*; @@ -25,6 +25,8 @@ use crate::{ use self::home::{Home, HomeInit}; +pub static LIBRARY_REFRESH_QUEUED: SharedState = SharedState::new(); + enum LibraryState { Loading, Ready, @@ -41,6 +43,7 @@ pub struct Library { pub enum LibraryInput { MediaSelected(BaseItemDto), Refresh, + Shown, } #[derive(Debug)] @@ -149,6 +152,10 @@ impl Component for Library { add_setter: (&view_switcher_bar, "reveal", &true.into()), }, }, + + connect_shown[sender] => move |_| { + sender.input(LibraryInput::Shown); + }, } } @@ -205,6 +212,12 @@ impl Component for Library { self.initial_fetch(&sender); } + LibraryInput::Shown => { + if *LIBRARY_REFRESH_QUEUED.read() { + sender.input(LibraryInput::Refresh); + } + *LIBRARY_REFRESH_QUEUED.write() = false; + } } self.update_view(widgets, sender); diff --git a/delfin/src/video_player/session.rs b/delfin/src/video_player/session.rs index a162bb8..d792388 100644 --- a/delfin/src/video_player/session.rs +++ b/delfin/src/video_player/session.rs @@ -5,7 +5,9 @@ use std::{ use uuid::Uuid; -use crate::{globals::CONFIG, jellyfin_api::api_client::ApiClient}; +use crate::{ + globals::CONFIG, jellyfin_api::api_client::ApiClient, library::LIBRARY_REFRESH_QUEUED, +}; use super::backends::VideoPlayerBackend; @@ -18,6 +20,8 @@ pub fn start_session_reporting( let position_update_frequency = config.video_player.position_update_frequency; + *LIBRARY_REFRESH_QUEUED.write() = true; + video_player .borrow_mut() .connect_position_updated(Box::new({ diff --git a/delfin/src/video_player/video_player_component.rs b/delfin/src/video_player/video_player_component.rs index d1b0d70..1a62c61 100644 --- a/delfin/src/video_player/video_player_component.rs +++ b/delfin/src/video_player/video_player_component.rs @@ -11,6 +11,7 @@ use crate::app::{AppInput, APP_BROKER}; use crate::globals::CONFIG; use crate::jellyfin_api::api::shows::GetEpisodesOptionsBuilder; use crate::jellyfin_api::api_client::ApiClient; +use crate::library::LIBRARY_REFRESH_QUEUED; use crate::utils::ticks::ticks_to_seconds; use crate::video_player::controls::skip_forwards_backwards::{ SkipForwardsBackwardsInput, SKIP_BACKWARDS_BROKER, SKIP_FORWARDS_BROKER, @@ -317,6 +318,7 @@ impl Component for VideoPlayer { .report_playback_stopped(&item_id, position) .await .unwrap(); + *LIBRARY_REFRESH_QUEUED.write() = true; } });