Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub const NEW_USER_DAYS: chrono::Duration = chrono::Duration::days(30);
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 = 19;
pub const SCHEMA_VERSION: u32 = 20;
pub const IMDB_LINK_CATEGORY: &str = "imdb";
pub const GENRES_LINK_CATEGORY: &str = "Genres";
pub const CINEMETA_TOP_CATALOG_ID: &str = "top";
Expand Down
23 changes: 23 additions & 0 deletions src/runtime/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ pub trait Env {
.await?;
schema_version = 19;
}
if schema_version == 19 {
migrate_storage_schema_to_v20::<Self>()
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
.await?;
schema_version = 20;
}
if schema_version != SCHEMA_VERSION {
panic!(
"Storage schema version must be upgraded from {} to {}",
Expand Down Expand Up @@ -714,6 +720,23 @@ fn migrate_storage_schema_to_v19<E: Env>() -> TryEnvFuture<()> {
.boxed_env()
}

fn migrate_storage_schema_to_v20<E: Env>() -> TryEnvFuture<()> {
E::get_storage::<serde_json::Value>(PROFILE_STORAGE_KEY)
.and_then(|mut profile| {
if let Some(settings) = profile
.as_mut()
.and_then(|profile| profile.as_object_mut())
.and_then(|profile| profile.get_mut("settings"))
.and_then(|settings| settings.as_object_mut())
{
settings.insert("pwaAutoRotation".to_owned(), serde_json::Value::Bool(true));
}
E::set_storage(PROFILE_STORAGE_KEY, Some(&profile))
})
.and_then(|_| E::set_storage(SCHEMA_VERSION_STORAGE_KEY, Some(&20)))
.boxed_env()
}

#[cfg(test)]
mod test {
use serde_json::{json, Value};
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 @@ -44,6 +44,7 @@ pub struct Settings {
pub streaming_server_warning_dismissed: Option<DateTime<Utc>>,
pub server_in_foreground: bool,
pub send_crash_reports: bool,
pub pwa_auto_rotation: bool,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -88,6 +89,7 @@ impl Default for Settings {
streaming_server_warning_dismissed: None,
server_in_foreground: false,
send_crash_reports: true,
pwa_auto_rotation: true,
}
}
}
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 @@ -376,7 +376,7 @@ impl DefaultTokens for Settings {
vec![
Token::Struct {
name: "Settings",
len: 32,
len: 33,
},
Token::Str("interfaceLanguage"),
Token::Str("eng"),
Expand Down Expand Up @@ -447,6 +447,8 @@ impl DefaultTokens for Settings {
Token::Bool(false),
Token::Str("sendCrashReports"),
Token::Bool(true),
Token::Str("pwaAutoRotation"),
Token::Bool(true),
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 @@ -41,11 +41,12 @@ fn settings() {
),
server_in_foreground: false,
send_crash_reports: true,
pwa_auto_rotation: true,
},
&[
Token::Struct {
name: "Settings",
len: 32,
len: 33,
},
Token::Str("interfaceLanguage"),
Token::Str("interface_language"),
Expand Down Expand Up @@ -120,6 +121,8 @@ fn settings() {
Token::Bool(false),
Token::Str("sendCrashReports"),
Token::Bool(true),
Token::Str("pwaAutoRotation"),
Token::Bool(true),
Token::StructEnd,
],
);
Expand All @@ -132,7 +135,7 @@ fn settings_de() {
&[
Token::Struct {
name: "Settings",
len: 32,
len: 33,
},
Token::Str("interfaceLanguage"),
Token::Str("eng"),
Expand Down Expand Up @@ -199,6 +202,8 @@ fn settings_de() {
Token::Bool(false),
Token::Str("sendCrashReports"),
Token::Bool(true),
Token::Str("pwaAutoRotation"),
Token::Bool(true),
Token::StructEnd,
],
);
Expand Down