Skip to content

Commit

Permalink
fix(player): reset library item time offset if selected video don't m…
Browse files Browse the repository at this point in the history
…atch state
  • Loading branch information
tymmesyde committed Dec 23, 2024
1 parent 354f6b1 commit e6032c1
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/models/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
&self.meta_item,
&ctx.library,
);

let library_item_state_effects =
library_item_state_update(&mut self.library_item, &self.selected);

let watched_effects =
watched_update(&mut self.watched, &self.meta_item, &self.library_item);

Expand Down Expand Up @@ -280,6 +284,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
.join(update_streams_effects)
.join(series_info_effects)
.join(library_item_effects)
.join(library_item_state_effects)
.join(watched_effects)
.join(skip_gaps_effects)
.join(intro_outro_update_effects)
Expand Down Expand Up @@ -678,10 +683,15 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
&ctx.library,
);

let library_item_state_effects =
library_item_state_update(&mut self.library_item, &self.selected);

let watched_effects =
watched_update(&mut self.watched, &self.meta_item, &self.library_item);

library_item_effects.join(watched_effects)
library_item_effects
.join(library_item_state_effects)
.join(watched_effects)
}
Msg::Internal(Internal::StreamsChanged(_)) => {
stream_state_update(&mut self.stream_state, &self.selected, &ctx.streams)
Expand Down Expand Up @@ -761,6 +771,10 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
&self.meta_item,
&ctx.library,
);

let library_item_state_effects =
library_item_state_update(&mut self.library_item, &self.selected);

let watched_effects =
watched_update(&mut self.watched, &self.meta_item, &self.library_item);

Expand Down Expand Up @@ -803,6 +817,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
.join(next_stream_effects)
.join(series_info_effects)
.join(library_item_effects)
.join(library_item_state_effects)
.join(watched_effects)
.join(skip_gaps_effects)
}
Expand Down Expand Up @@ -1122,6 +1137,28 @@ fn watched_update(
eq_update(watched, next_watched)
}

fn library_item_state_update(
library_item: &mut Option<LibraryItem>,
selected: &Option<Selected>,
) -> Effects {
match (library_item, selected) {
(Some(library_item), Some(selected)) => {
match (&selected.stream_request, &library_item.state.video_id) {
(Some(stream_request), Some(state_video_id))
if stream_request.path.id != *state_video_id =>
{
library_item.state.time_offset = 0;
Effects::msg(Msg::Internal(Internal::UpdateLibraryItem(
library_item.to_owned(),
)))
}
_ => Effects::none().unchanged(),
}
}
_ => Effects::none().unchanged(),
}
}

fn subtitles_update<E: Env + 'static>(
subtitles: &mut Vec<ResourceLoadable<Vec<Subtitles>>>,
selected: &Option<Selected>,
Expand Down

0 comments on commit e6032c1

Please sign in to comment.