Skip to content

Commit 96de5ff

Browse files
authored
Merge pull request #885 from Stremio/feat/settings-ass-subtitles-styling
feat: add ass_subtitles_styling setting
2 parents 2efe98d + 766ae7e commit 96de5ff

File tree

5 files changed

+86
-7
lines changed

5 files changed

+86
-7
lines changed

src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub const NEW_USER_DAYS: chrono::Duration = chrono::Duration::days(30);
4242
pub const WATCHED_THRESHOLD_COEF: f64 = 0.7;
4343
pub const CREDITS_THRESHOLD_COEF: f64 = 0.9;
4444
/// The latest migration scheme version
45-
pub const SCHEMA_VERSION: u32 = 20;
45+
pub const SCHEMA_VERSION: u32 = 21;
4646
pub const IMDB_LINK_CATEGORY: &str = "imdb";
4747
pub const GENRES_LINK_CATEGORY: &str = "Genres";
4848
pub const CINEMETA_TOP_CATALOG_ID: &str = "top";

src/runtime/env.rs

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ pub trait Env {
301301
.await?;
302302
schema_version = 20;
303303
}
304+
if schema_version == 20 {
305+
migrate_storage_schema_to_v21::<Self>()
306+
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error)))
307+
.await?;
308+
schema_version = 21;
309+
}
304310
if schema_version != SCHEMA_VERSION {
305311
panic!(
306312
"Storage schema version must be upgraded from {} to {}",
@@ -740,6 +746,29 @@ fn migrate_storage_schema_to_v20<E: Env>() -> TryEnvFuture<()> {
740746
.boxed_env()
741747
}
742748

749+
fn migrate_storage_schema_to_v21<E: Env>() -> TryEnvFuture<()> {
750+
E::get_storage::<serde_json::Value>(PROFILE_STORAGE_KEY)
751+
.and_then(|mut profile| {
752+
match profile
753+
.as_mut()
754+
.and_then(|profile| profile.as_object_mut())
755+
.and_then(|profile| profile.get_mut("settings"))
756+
.and_then(|settings| settings.as_object_mut())
757+
{
758+
Some(settings) => {
759+
settings.insert(
760+
"assSubtitlesStyling".to_owned(),
761+
serde_json::Value::Bool(false),
762+
);
763+
E::set_storage(PROFILE_STORAGE_KEY, Some(&profile))
764+
}
765+
_ => E::set_storage::<()>(PROFILE_STORAGE_KEY, None),
766+
}
767+
})
768+
.and_then(|_| E::set_storage(SCHEMA_VERSION_STORAGE_KEY, Some(&21)))
769+
.boxed_env()
770+
}
771+
743772
#[cfg(test)]
744773
mod test {
745774
use serde_json::{json, Value};
@@ -755,9 +784,9 @@ mod test {
755784
migrate_storage_schema_to_v14, migrate_storage_schema_to_v15,
756785
migrate_storage_schema_to_v16, migrate_storage_schema_to_v17,
757786
migrate_storage_schema_to_v18, migrate_storage_schema_to_v19,
758-
migrate_storage_schema_to_v20, migrate_storage_schema_to_v6,
759-
migrate_storage_schema_to_v7, migrate_storage_schema_to_v8,
760-
migrate_storage_schema_to_v9,
787+
migrate_storage_schema_to_v20, migrate_storage_schema_to_v21,
788+
migrate_storage_schema_to_v6, migrate_storage_schema_to_v7,
789+
migrate_storage_schema_to_v8, migrate_storage_schema_to_v9,
761790
},
762791
Env,
763792
},
@@ -1490,4 +1519,45 @@ mod test {
14901519
);
14911520
}
14921521
}
1522+
1523+
#[tokio::test]
1524+
async fn test_migration_from_20_to_21() {
1525+
{
1526+
let _test_env_guard = TestEnv::reset().expect("Should lock TestEnv");
1527+
let profile_before = json!({
1528+
"settings": {}
1529+
});
1530+
1531+
let migrated_profile = json!({
1532+
"settings": {
1533+
"assSubtitlesStyling": false,
1534+
}
1535+
});
1536+
1537+
// setup storage for migration
1538+
set_profile_and_schema_version(&profile_before, 20);
1539+
1540+
// migrate storage
1541+
migrate_storage_schema_to_v21::<TestEnv>()
1542+
.await
1543+
.expect("Should migrate");
1544+
1545+
let storage = STORAGE.read().expect("Should lock");
1546+
1547+
assert_eq!(
1548+
&21.to_string(),
1549+
storage
1550+
.get(SCHEMA_VERSION_STORAGE_KEY)
1551+
.expect("Should have the schema set"),
1552+
"Scheme version should now be updated"
1553+
);
1554+
assert_eq!(
1555+
&migrated_profile.to_string(),
1556+
storage
1557+
.get(PROFILE_STORAGE_KEY)
1558+
.expect("Should have the profile set"),
1559+
"Profile should match"
1560+
);
1561+
}
1562+
}
14931563
}

src/types/profile/settings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub struct Settings {
3030
pub subtitles_background_color: String,
3131
pub subtitles_outline_color: String,
3232
pub subtitles_opacity: u8,
33+
pub ass_subtitles_styling: bool,
3334
/// Whether or not the Escape key should exists from the app when in Full screen.
3435
pub esc_exit_fullscreen: bool,
3536
/// The Seek time duration (in milliseconds) is when using the Arrow keys
@@ -81,6 +82,7 @@ impl Default for Settings {
8182
subtitles_background_color: "#00000000".to_owned(),
8283
subtitles_outline_color: "#000000".to_owned(),
8384
subtitles_opacity: 100,
85+
ass_subtitles_styling: false,
8486
esc_exit_fullscreen: true,
8587
seek_time_duration: 10000,
8688
seek_short_time_duration: 3000,

src/unit_tests/serde/default_tokens_ext.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl DefaultTokens for Settings {
376376
vec![
377377
Token::Struct {
378378
name: "Settings",
379-
len: 33,
379+
len: 34,
380380
},
381381
Token::Str("interfaceLanguage"),
382382
Token::Str("eng"),
@@ -431,6 +431,8 @@ impl DefaultTokens for Settings {
431431
Token::Str("#000000"),
432432
Token::Str("subtitlesOpacity"),
433433
Token::U8(100),
434+
Token::Str("assSubtitlesStyling"),
435+
Token::Bool(false),
434436
Token::Str("escExitFullscreen"),
435437
Token::Bool(true),
436438
Token::Str("seekTimeDuration"),

src/unit_tests/serde/settings.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn settings() {
3131
subtitles_background_color: "subtitles_background_color".to_owned(),
3232
subtitles_outline_color: "subtitles_outline_color".to_owned(),
3333
subtitles_opacity: 1,
34+
ass_subtitles_styling: false,
3435
esc_exit_fullscreen: true,
3536
seek_time_duration: 10,
3637
seek_short_time_duration: 3,
@@ -46,7 +47,7 @@ fn settings() {
4647
&[
4748
Token::Struct {
4849
name: "Settings",
49-
len: 33,
50+
len: 34,
5051
},
5152
Token::Str("interfaceLanguage"),
5253
Token::Str("interface_language"),
@@ -105,6 +106,8 @@ fn settings() {
105106
Token::Str("subtitles_outline_color"),
106107
Token::Str("subtitlesOpacity"),
107108
Token::U8(1),
109+
Token::Str("assSubtitlesStyling"),
110+
Token::Bool(false),
108111
Token::Str("escExitFullscreen"),
109112
Token::Bool(true),
110113
Token::Str("seekTimeDuration"),
@@ -136,7 +139,7 @@ fn settings_de() {
136139
&[
137140
Token::Struct {
138141
name: "Settings",
139-
len: 33,
142+
len: 34,
140143
},
141144
Token::Str("interfaceLanguage"),
142145
Token::Str("eng"),
@@ -187,6 +190,8 @@ fn settings_de() {
187190
Token::Str("#000000"),
188191
Token::Str("subtitlesOpacity"),
189192
Token::U8(100),
193+
Token::Str("assSubtitlesStyling"),
194+
Token::Bool(false),
190195
Token::Str("escExitFullscreen"),
191196
Token::Bool(true),
192197
Token::Str("seekTimeDuration"),

0 commit comments

Comments
 (0)