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 2 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
108 changes: 98 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,43 @@ 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) => {
// override the seekTimeDuration with the new value
// and take the old value to put in the seekShiftTimeDuration
let old_seek_time_duration = settings
// new default is 20 seconds
.insert(
"seekTimeDuration".into(),
serde_json::Value::Number(20_000_u32.into()),
);

// move the old value to the new seek shift time
settings.insert(
"seekShiftTimeDuration".to_owned(),
old_seek_time_duration
.unwrap_or(serde_json::Value::Number(10_000_u32.into())),
);

// add the new setting for Escape key exiting full screen
settings.insert("escExistsFullscreen".to_owned(), true.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 +510,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 +829,49 @@ 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": {
"seekTimeDuration": 10000,
}
});

let migrated_profile = json!({
"settings": {
"escExistsFullscreen": true,
"seekTimeDuration": 20000,
"seekShiftTimeDuration": 10000,
}
});

// 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"
);
}
}
}
9 changes: 8 additions & 1 deletion src/types/profile/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ 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_exists_fullscreen: bool,
elpiel marked this conversation as resolved.
Show resolved Hide resolved
/// The Seek time duration (in milliseconds) is when using the Arrow keys
pub seek_time_duration: u32,
/// The Seek shift time duration (in milliseconds) is when using the Arrow keys + Shift
pub seek_shift_time_duration: u32,
elpiel marked this conversation as resolved.
Show resolved Hide resolved
pub streaming_server_warning_dismissed: Option<DateTime<Utc>>,
}

Expand Down Expand Up @@ -60,7 +65,9 @@ impl Default for Settings {
subtitles_text_color: "#FFFFFFFF".to_owned(),
subtitles_background_color: "#00000000".to_owned(),
subtitles_outline_color: "#000000".to_owned(),
seek_time_duration: 10000,
esc_exists_fullscreen: true,
seek_time_duration: 20000,
seek_shift_time_duration: 10000,
streaming_server_warning_dismissed: None,
}
}
Expand Down
6 changes: 5 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: 24,
},
Token::Str("interfaceLanguage"),
Token::Str("eng"),
Expand Down Expand Up @@ -416,7 +416,11 @@ impl DefaultTokens for Settings {
Token::Str("#00000000"),
Token::Str("subtitlesOutlineColor"),
Token::Str("#000000"),
Token::Str("escExistsFullscreen"),
Token::Bool(true),
Token::Str("seekTimeDuration"),
Token::U32(20000),
Token::Str("seekShiftTimeDuration"),
Token::U32(10000),
Token::Str("streamingServerWarningDismissed"),
Token::None,
Expand Down
14 changes: 12 additions & 2 deletions src/unit_tests/serde/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ 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(),
esc_exists_fullscreen: true,
seek_time_duration: 1,
seek_shift_time_duration: 2,
streaming_server_warning_dismissed: Some(
Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap(),
),
},
&[
Token::Struct {
name: "Settings",
len: 22,
len: 24,
},
Token::Str("interfaceLanguage"),
Token::Str("interface_language"),
Expand Down Expand Up @@ -83,8 +85,12 @@ fn settings() {
Token::Str("subtitles_background_color"),
Token::Str("subtitlesOutlineColor"),
Token::Str("subtitles_outline_color"),
Token::Str("escExistsFullscreen"),
Token::Bool(true),
Token::Str("seekTimeDuration"),
Token::U32(1),
Token::Str("seekShiftTimeDuration"),
Token::U32(2),
Token::Str("streamingServerWarningDismissed"),
Token::Some,
Token::Str("2021-01-01T00:00:00Z"),
Expand All @@ -100,7 +106,7 @@ fn settings_de() {
&[
Token::Struct {
name: "Settings",
len: 17,
len: 19,
},
Token::Str("interfaceLanguage"),
Token::Str("eng"),
Expand Down Expand Up @@ -141,7 +147,11 @@ fn settings_de() {
Token::Str("#00000000"),
Token::Str("subtitlesOutlineColor"),
Token::Str("#000000"),
Token::Str("escExistsFullscreen"),
Token::Bool(true),
Token::Str("seekTimeDuration"),
Token::U32(20000),
Token::Str("seekShiftTimeDuration"),
Token::U32(10000),
Token::Str("streamingServerWarningDismissed"),
Token::None,
Expand Down