Save duration label display in config (fixes #57)
This commit is contained in:
@@ -242,6 +242,7 @@ impl Migrate<Config> for ConfigV1 {
|
|||||||
intro_skipper: self.video_player.intro_skipper,
|
intro_skipper: self.video_player.intro_skipper,
|
||||||
intro_skipper_auto_skip: self.video_player.intro_skipper_auto_skip,
|
intro_skipper_auto_skip: self.video_player.intro_skipper_auto_skip,
|
||||||
jellyscrub: self.video_player.jellyscrub,
|
jellyscrub: self.video_player.jellyscrub,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,32 +10,6 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
|
|
||||||
pub enum VideoPlayerBackendPreference {
|
|
||||||
Mpv,
|
|
||||||
Gst,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<VideoPlayerBackendPreference> for Arc<RefCell<dyn VideoPlayerBackend>> {
|
|
||||||
fn from(val: VideoPlayerBackendPreference) -> Self {
|
|
||||||
match val {
|
|
||||||
VideoPlayerBackendPreference::Mpv => Arc::<RefCell<VideoPlayerBackendMpv>>::default(),
|
|
||||||
VideoPlayerBackendPreference::Gst => {
|
|
||||||
#[cfg(feature = "gst")]
|
|
||||||
{
|
|
||||||
Arc::<RefCell<crate::video_player::backends::gst::VideoPlayerBackendGst>>::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "gst"))]
|
|
||||||
{
|
|
||||||
println!("GStreamer backend not available, falling back to MPV backend");
|
|
||||||
Arc::<RefCell<VideoPlayerBackendMpv>>::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
|
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct VideoPlayerConfig {
|
pub struct VideoPlayerConfig {
|
||||||
@@ -46,6 +20,7 @@ pub struct VideoPlayerConfig {
|
|||||||
pub skip_backwards_amount: VideoPlayerSkipAmount,
|
pub skip_backwards_amount: VideoPlayerSkipAmount,
|
||||||
pub skip_forwards_amount: VideoPlayerSkipAmount,
|
pub skip_forwards_amount: VideoPlayerSkipAmount,
|
||||||
pub on_left_click: VideoPlayerOnLeftClick,
|
pub on_left_click: VideoPlayerOnLeftClick,
|
||||||
|
pub duration_display: DurationDisplay,
|
||||||
|
|
||||||
#[serde(serialize_with = "round_one_place")]
|
#[serde(serialize_with = "round_one_place")]
|
||||||
pub subtitle_scale: f64,
|
pub subtitle_scale: f64,
|
||||||
@@ -71,7 +46,8 @@ impl Default for VideoPlayerConfig {
|
|||||||
|
|
||||||
skip_backwards_amount: VideoPlayerSkipAmount::Ten,
|
skip_backwards_amount: VideoPlayerSkipAmount::Ten,
|
||||||
skip_forwards_amount: VideoPlayerSkipAmount::Thirty,
|
skip_forwards_amount: VideoPlayerSkipAmount::Thirty,
|
||||||
on_left_click: VideoPlayerOnLeftClick::PlayPause,
|
on_left_click: VideoPlayerOnLeftClick::default(),
|
||||||
|
duration_display: DurationDisplay::default(),
|
||||||
|
|
||||||
subtitle_scale: 1.0,
|
subtitle_scale: 1.0,
|
||||||
subtitle_colour: "#FFFFFFFF".into(),
|
subtitle_colour: "#FFFFFFFF".into(),
|
||||||
@@ -79,7 +55,7 @@ impl Default for VideoPlayerConfig {
|
|||||||
subtitle_position: 100,
|
subtitle_position: 100,
|
||||||
subtitle_font: VideoPlayerSubtitleFont::default(),
|
subtitle_font: VideoPlayerSubtitleFont::default(),
|
||||||
|
|
||||||
backend: VideoPlayerBackendPreference::Mpv,
|
backend: VideoPlayerBackendPreference::default(),
|
||||||
hls_playback: false,
|
hls_playback: false,
|
||||||
intro_skipper: true,
|
intro_skipper: true,
|
||||||
intro_skipper_auto_skip: true,
|
intro_skipper_auto_skip: true,
|
||||||
@@ -101,8 +77,52 @@ impl From<VideoPlayerSkipAmount> for Duration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone, Copy)]
|
#[derive(Debug, Default, Deserialize, Serialize, PartialEq, Clone, Copy)]
|
||||||
pub enum VideoPlayerOnLeftClick {
|
pub enum VideoPlayerOnLeftClick {
|
||||||
|
#[default]
|
||||||
PlayPause,
|
PlayPause,
|
||||||
ToggleControls,
|
ToggleControls,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq)]
|
||||||
|
pub enum VideoPlayerBackendPreference {
|
||||||
|
#[default]
|
||||||
|
Mpv,
|
||||||
|
Gst,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<VideoPlayerBackendPreference> for Arc<RefCell<dyn VideoPlayerBackend>> {
|
||||||
|
fn from(val: VideoPlayerBackendPreference) -> Self {
|
||||||
|
match val {
|
||||||
|
VideoPlayerBackendPreference::Mpv => Arc::<RefCell<VideoPlayerBackendMpv>>::default(),
|
||||||
|
VideoPlayerBackendPreference::Gst => {
|
||||||
|
#[cfg(feature = "gst")]
|
||||||
|
{
|
||||||
|
Arc::<RefCell<crate::video_player::backends::gst::VideoPlayerBackendGst>>::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "gst"))]
|
||||||
|
{
|
||||||
|
println!("GStreamer backend not available, falling back to MPV backend");
|
||||||
|
Arc::<RefCell<VideoPlayerBackendMpv>>::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq)]
|
||||||
|
pub enum DurationDisplay {
|
||||||
|
#[default]
|
||||||
|
Total,
|
||||||
|
Remaining,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DurationDisplay {
|
||||||
|
pub fn toggle(&self) -> Self {
|
||||||
|
match self {
|
||||||
|
Self::Total => Self::Remaining,
|
||||||
|
Self::Remaining => Self::Total,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -7,6 +7,8 @@ use gtk::{gdk, gdk_pixbuf, graphene, prelude::*};
|
|||||||
use relm4::prelude::*;
|
use relm4::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::video_player_config::DurationDisplay,
|
||||||
|
globals::CONFIG,
|
||||||
tr,
|
tr,
|
||||||
utils::{bif::Thumbnail, message_broker::ResettableMessageBroker},
|
utils::{bif::Thumbnail, message_broker::ResettableMessageBroker},
|
||||||
video_player::backends::VideoPlayerBackend,
|
video_player::backends::VideoPlayerBackend,
|
||||||
@@ -17,21 +19,6 @@ const TIMESTAMP_WIDTH: i32 = 80;
|
|||||||
pub(crate) static SCRUBBER_BROKER: ResettableMessageBroker<ScrubberInput> =
|
pub(crate) static SCRUBBER_BROKER: ResettableMessageBroker<ScrubberInput> =
|
||||||
ResettableMessageBroker::new();
|
ResettableMessageBroker::new();
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
enum DurationDisplay {
|
|
||||||
Total,
|
|
||||||
Remaining,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DurationDisplay {
|
|
||||||
fn toggle(&self) -> Self {
|
|
||||||
match self {
|
|
||||||
Self::Total => Self::Remaining,
|
|
||||||
Self::Remaining => Self::Total,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ScrubberPopover {
|
struct ScrubberPopover {
|
||||||
position: f64,
|
position: f64,
|
||||||
timestamp: usize,
|
timestamp: usize,
|
||||||
@@ -63,6 +50,7 @@ pub enum ScrubberInput {
|
|||||||
ScrubberMouseHover(f64),
|
ScrubberMouseHover(f64),
|
||||||
ScrubberMouseLeave,
|
ScrubberMouseLeave,
|
||||||
LoadedThumbnails(Option<Vec<Thumbnail>>),
|
LoadedThumbnails(Option<Vec<Thumbnail>>),
|
||||||
|
DurationDisplayUpdated(DurationDisplay),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[relm4::component(pub(crate))]
|
#[relm4::component(pub(crate))]
|
||||||
@@ -202,12 +190,14 @@ impl Component for Scrubber {
|
|||||||
loading: true,
|
loading: true,
|
||||||
position: 0,
|
position: 0,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
duration_display: DurationDisplay::Total,
|
duration_display: CONFIG.read().video_player.duration_display,
|
||||||
scrubbing: false,
|
scrubbing: false,
|
||||||
popover: None,
|
popover: None,
|
||||||
thumbnails: None,
|
thumbnails: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
model.subscribe_to_config(&sender);
|
||||||
|
|
||||||
let widgets = view_output!();
|
let widgets = view_output!();
|
||||||
|
|
||||||
relm4::ComponentParts { model, widgets }
|
relm4::ComponentParts { model, widgets }
|
||||||
@@ -241,7 +231,13 @@ impl Component for Scrubber {
|
|||||||
self.loading = false;
|
self.loading = false;
|
||||||
}
|
}
|
||||||
ScrubberInput::ToggleDurationDisplay => {
|
ScrubberInput::ToggleDurationDisplay => {
|
||||||
self.duration_display = self.duration_display.toggle();
|
let mut config = CONFIG.write();
|
||||||
|
config.video_player.duration_display =
|
||||||
|
config.video_player.duration_display.toggle();
|
||||||
|
config.save().expect("Failed to save duration display");
|
||||||
|
}
|
||||||
|
ScrubberInput::DurationDisplayUpdated(duration_display) => {
|
||||||
|
self.duration_display = duration_display;
|
||||||
}
|
}
|
||||||
ScrubberInput::SetScrubbing(scrubbing) => {
|
ScrubberInput::SetScrubbing(scrubbing) => {
|
||||||
self.scrubbing = scrubbing;
|
self.scrubbing = scrubbing;
|
||||||
@@ -311,6 +307,12 @@ impl Scrubber {
|
|||||||
};
|
};
|
||||||
Some(Texture::for_pixbuf(&pixbuf))
|
Some(Texture::for_pixbuf(&pixbuf))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subscribe_to_config(&self, sender: &ComponentSender<Self>) {
|
||||||
|
CONFIG.subscribe(sender.input_sender(), |config| {
|
||||||
|
ScrubberInput::DurationDisplayUpdated(config.video_player.duration_display)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn seconds_to_timestamp(seconds: usize) -> String {
|
fn seconds_to_timestamp(seconds: usize) -> String {
|
||||||
|
Reference in New Issue
Block a user