Skip to content

Commit

Permalink
Merge pull request #567 from Stremio/surround_sound_enabled
Browse files Browse the repository at this point in the history
Surround sound enty added to Settings
  • Loading branch information
unclekingpin authored Nov 28, 2023
2 parents 0745d79 + c4e9cbe commit f2517fb
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub const NOTIFICATION_ITEMS_COUNT: usize = 100;
pub const WATCHED_THRESHOLD_COEF: f64 = 0.7;
pub const CREDITS_THRESHOLD_COEF: f64 = 0.9;
/// The latest migration scheme version
pub const SCHEMA_VERSION: u32 = 10;
pub const SCHEMA_VERSION: u32 = 11;
pub const IMDB_LINK_CATEGORY: &str = "imdb";
pub const GENRES_LINK_CATEGORY: &str = "Genres";
pub const CINEMETA_TOP_CATALOG_ID: &str = "top";
Expand Down
72 changes: 69 additions & 3 deletions src/runtime/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ pub trait Env {
.await?;
schema_version = 10;
}
if schema_version == 10 {
migrate_storage_schema_to_v11::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 11;
}
if schema_version != SCHEMA_VERSION {
panic!(
"Storage schema version must be upgraded from {} to {}",
Expand Down Expand Up @@ -503,6 +509,26 @@ fn migrate_storage_schema_to_v10<E: Env>() -> TryEnvFuture<()> {
.boxed_env()
}

fn migrate_storage_schema_to_v11<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) => {
settings.insert("surroundSound".to_owned(), serde_json::Value::Bool(false));
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(&11)))
.boxed_env()
}

#[cfg(test)]
mod test {
use serde_json::{json, Value};
Expand All @@ -513,9 +539,9 @@ mod test {
},
runtime::{
env::{
migrate_storage_schema_to_v10, migrate_storage_schema_to_v6,
migrate_storage_schema_to_v7, migrate_storage_schema_to_v8,
migrate_storage_schema_to_v9,
migrate_storage_schema_to_v10, migrate_storage_schema_to_v11,
migrate_storage_schema_to_v6, migrate_storage_schema_to_v7,
migrate_storage_schema_to_v8, migrate_storage_schema_to_v9,
},
Env,
},
Expand Down Expand Up @@ -903,4 +929,44 @@ mod test {
assert_storage_shema_version(10);
}
}

async fn test_migration_from_10_to_11() {
{
let _test_env_guard = TestEnv::reset().expect("Should lock TestEnv");
let profile_before = json!({
"settings": {}
});

let migrated_profile = json!({
"settings": {
"surroundSound": false,
}
});

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

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

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

assert_eq!(
&11.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"
);
}
}
}
2 changes: 1 addition & 1 deletion src/runtime/msg/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
types::{
addon::Descriptor,
api::AuthRequest,
library::{LibraryItemId, LibraryItem},
library::LibraryItemId,
profile::Settings as ProfileSettings,
resource::{MetaItemId, MetaItemPreview, Video},
},
Expand Down
2 changes: 2 additions & 0 deletions src/types/profile/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Settings {
pub seek_short_time_duration: u32,
/// Whether we should pause the playback when the application get's minimized
pub pause_on_minimize: bool,
pub surround_sound: bool,
pub streaming_server_warning_dismissed: Option<DateTime<Utc>>,
}

Expand Down Expand Up @@ -72,6 +73,7 @@ impl Default for Settings {
seek_time_duration: 10000,
seek_short_time_duration: 3000,
pause_on_minimize: false,
surround_sound: false,
streaming_server_warning_dismissed: None,
}
}
Expand Down
4 changes: 3 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: 25,
len: 26,
},
Token::Str("interfaceLanguage"),
Token::Str("eng"),
Expand Down Expand Up @@ -424,6 +424,8 @@ impl DefaultTokens for Settings {
Token::U32(3000),
Token::Str("pauseOnMinimize"),
Token::Bool(false),
Token::Str("surroundSound"),
Token::Bool(false),
Token::Str("streamingServerWarningDismissed"),
Token::None,
Token::StructEnd,
Expand Down
9 changes: 7 additions & 2 deletions src/unit_tests/serde/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ fn settings() {
seek_time_duration: 10,
seek_short_time_duration: 3,
pause_on_minimize: true,
surround_sound: false,
streaming_server_warning_dismissed: Some(
Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap(),
),
},
&[
Token::Struct {
name: "Settings",
len: 25,
len: 26,
},
Token::Str("interfaceLanguage"),
Token::Str("interface_language"),
Expand Down Expand Up @@ -94,6 +95,8 @@ fn settings() {
Token::U32(3),
Token::Str("pauseOnMinimize"),
Token::Bool(true),
Token::Str("surroundSound"),
Token::Bool(false),
Token::Str("streamingServerWarningDismissed"),
Token::Some,
Token::Str("2021-01-01T00:00:00Z"),
Expand All @@ -109,7 +112,7 @@ fn settings_de() {
&[
Token::Struct {
name: "Settings",
len: 20,
len: 21,
},
Token::Str("interfaceLanguage"),
Token::Str("eng"),
Expand Down Expand Up @@ -158,6 +161,8 @@ fn settings_de() {
Token::U32(3000),
Token::Str("pauseOnMinimize"),
Token::Bool(false),
Token::Str("surroundSound"),
Token::Bool(false),
Token::Str("streamingServerWarningDismissed"),
Token::None,
Token::StructEnd,
Expand Down

0 comments on commit f2517fb

Please sign in to comment.