Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Profile Settings - controls & esc for exiting fullscreen #546

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub const NOTIFICATION_ITEMS_COUNT: usize = 100;
/// `LibraryItem.state.time_watched` > `LibraryItem.state.duration` * [`WATCHED_THRESHOLD_COEF`]
pub const WATCHED_THRESHOLD_COEF: f64 = 0.7;
pub const CREDITS_THRESHOLD_COEF: f64 = 0.9;
pub const SCHEMA_VERSION: u32 = 8;
/// The latest migration scheme version
pub const SCHEMA_VERSION: u32 = 9;
pub const IMDB_LINK_CATEGORY: &str = "imdb";
pub const GENRES_LINK_CATEGORY: &str = "Genres";
pub const CINEMETA_TOP_CATALOG_ID: &str = "top";
Expand Down
99 changes: 89 additions & 10 deletions src/runtime/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,61 +177,67 @@ pub trait Env {
schema_version,
SCHEMA_VERSION,
));
};
}
if schema_version == 0 {
migrate_storage_schema_to_v1::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 1;
};
}
if schema_version == 1 {
migrate_storage_schema_to_v2::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 2;
};
}
if schema_version == 2 {
migrate_storage_schema_to_v3::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 3;
};
}
if schema_version == 3 {
migrate_storage_schema_to_v4::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 4;
};
}
if schema_version == 4 {
migrate_storage_schema_to_v5::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 5;
};
}
if schema_version == 5 {
migrate_storage_schema_to_v6::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 6;
};
}
if schema_version == 6 {
migrate_storage_schema_to_v7::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 7;
};
}
if schema_version == 7 {
migrate_storage_schema_to_v8::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 8;
}
if schema_version == 8 {
migrate_storage_schema_to_v9::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 9;
}
if schema_version != SCHEMA_VERSION {
panic!(
"Storage schema version must be upgraded from {} to {}",
schema_version, SCHEMA_VERSION
);
};
}
Ok(())
})
.boxed_env()
Expand Down Expand Up @@ -456,6 +462,35 @@ fn migrate_storage_schema_to_v8<E: Env>() -> TryEnvFuture<()> {
.boxed_env()
}

fn migrate_storage_schema_to_v9<E: Env>() -> TryEnvFuture<()> {
E::get_storage::<serde_json::Value>(PROFILE_STORAGE_KEY)
.and_then(|mut profile| {
match profile
.as_mut()
.and_then(|profile| profile.as_object_mut())
.and_then(|profile| profile.get_mut("settings"))
.and_then(|settings| settings.as_object_mut())
{
Some(settings) => {
// short (i.e. finer) seeking time is 3 seconds
settings.insert(
"seekShortTimeDuration".to_owned(),
serde_json::Value::Number(3_000_u32.into()),
);

// add the new setting for Escape key exiting full screen
settings.insert("escExitFullscreen".to_owned(), true.into());
// add the new setting for pause on minimize, which is disabled by default
settings.insert("pauseOnMinimize".to_owned(), false.into());
E::set_storage(PROFILE_STORAGE_KEY, Some(&profile))
}
_ => E::set_storage::<()>(PROFILE_STORAGE_KEY, None),
}
})
.and_then(|_| E::set_storage(SCHEMA_VERSION_STORAGE_KEY, Some(&9)))
.boxed_env()
}

#[cfg(test)]
mod test {
use serde_json::{json, Value};
Expand All @@ -467,7 +502,7 @@ mod test {
runtime::{
env::{
migrate_storage_schema_to_v6, migrate_storage_schema_to_v7,
migrate_storage_schema_to_v8,
migrate_storage_schema_to_v8, migrate_storage_schema_to_v9,
},
Env,
},
Expand Down Expand Up @@ -786,4 +821,48 @@ mod test {
);
}
}

#[tokio::test]
async fn test_migration_from_8_to_9() {
{
let _test_env_guard = TestEnv::reset().expect("Should lock TestEnv");
let profile_before = json!({
"settings": {
}
});

let migrated_profile = json!({
"settings": {
"escExitFullscreen": true,
"seekShortTimeDuration": 3000,
"pauseOnMinimize": false,
}
});

// setup storage for migration
set_profile_and_schema_version(&profile_before, 8);

// migrate storage
migrate_storage_schema_to_v9::<TestEnv>()
.await
.expect("Should migrate");

let storage = STORAGE.read().expect("Should lock");

assert_eq!(
&9.to_string(),
storage
.get(SCHEMA_VERSION_STORAGE_KEY)
.expect("Should have the schema set"),
"Scheme version should now be updated"
);
assert_eq!(
&migrated_profile.to_string(),
storage
.get(PROFILE_STORAGE_KEY)
.expect("Should have the profile set"),
"Profile should match"
);
}
}
}
11 changes: 11 additions & 0 deletions src/types/profile/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ pub struct Settings {
pub subtitles_text_color: String,
pub subtitles_background_color: String,
pub subtitles_outline_color: String,
/// Whether or not the Escape key should exists from the app when in Full screen.
pub esc_exit_fullscreen: bool,
/// The Seek time duration (in milliseconds) is when using the Arrow keys
pub seek_time_duration: u32,
/// The Seek short time duration (in milliseconds) is when we are finer seeking,
/// e.g. using the Arrow keys + Shift
pub seek_short_time_duration: u32,
/// Whether we should pause the playback when the application get's minimized
pub pause_on_minimize: bool,
pub streaming_server_warning_dismissed: Option<DateTime<Utc>>,
}

Expand Down Expand Up @@ -60,7 +68,10 @@ impl Default for Settings {
subtitles_text_color: "#FFFFFFFF".to_owned(),
subtitles_background_color: "#00000000".to_owned(),
subtitles_outline_color: "#000000".to_owned(),
esc_exit_fullscreen: true,
seek_time_duration: 10000,
seek_short_time_duration: 3000,
pause_on_minimize: false,
streaming_server_warning_dismissed: None,
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/unit_tests/serde/default_tokens_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl DefaultTokens for Settings {
vec![
Token::Struct {
name: "Settings",
len: 22,
len: 25,
},
Token::Str("interfaceLanguage"),
Token::Str("eng"),
Expand Down Expand Up @@ -416,8 +416,14 @@ impl DefaultTokens for Settings {
Token::Str("#00000000"),
Token::Str("subtitlesOutlineColor"),
Token::Str("#000000"),
Token::Str("escExitFullscreen"),
Token::Bool(true),
Token::Str("seekTimeDuration"),
Token::U32(10000),
Token::Str("seekShortTimeDuration"),
Token::U32(3000),
Token::Str("pauseOnMinimize"),
Token::Bool(false),
Token::Str("streamingServerWarningDismissed"),
Token::None,
Token::StructEnd,
Expand Down
23 changes: 19 additions & 4 deletions src/unit_tests/serde/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ fn settings() {
subtitles_text_color: "subtitles_text_color".to_owned(),
subtitles_background_color: "subtitles_background_color".to_owned(),
subtitles_outline_color: "subtitles_outline_color".to_owned(),
seek_time_duration: 1,
esc_exit_fullscreen: true,
seek_time_duration: 10,
seek_short_time_duration: 3,
pause_on_minimize: true,
streaming_server_warning_dismissed: Some(
Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap(),
),
},
&[
Token::Struct {
name: "Settings",
len: 22,
len: 25,
},
Token::Str("interfaceLanguage"),
Token::Str("interface_language"),
Expand Down Expand Up @@ -83,8 +86,14 @@ fn settings() {
Token::Str("subtitles_background_color"),
Token::Str("subtitlesOutlineColor"),
Token::Str("subtitles_outline_color"),
Token::Str("escExitFullscreen"),
Token::Bool(true),
Token::Str("seekTimeDuration"),
Token::U32(1),
Token::U32(10),
Token::Str("seekShortTimeDuration"),
Token::U32(3),
Token::Str("pauseOnMinimize"),
Token::Bool(true),
Token::Str("streamingServerWarningDismissed"),
Token::Some,
Token::Str("2021-01-01T00:00:00Z"),
Expand All @@ -100,7 +109,7 @@ fn settings_de() {
&[
Token::Struct {
name: "Settings",
len: 17,
len: 20,
},
Token::Str("interfaceLanguage"),
Token::Str("eng"),
Expand Down Expand Up @@ -141,8 +150,14 @@ fn settings_de() {
Token::Str("#00000000"),
Token::Str("subtitlesOutlineColor"),
Token::Str("#000000"),
Token::Str("escExitFullscreen"),
Token::Bool(true),
Token::Str("seekTimeDuration"),
Token::U32(10000),
Token::Str("seekShortTimeDuration"),
Token::U32(3000),
Token::Str("pauseOnMinimize"),
Token::Bool(false),
Token::Str("streamingServerWarningDismissed"),
Token::None,
Token::StructEnd,
Expand Down