-
Notifications
You must be signed in to change notification settings - Fork 73
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
Feature/add new mobile app settings #748
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b66d794
feature: Add service in foreground mobile app setting
TRtomasz 3c62ccb
feat: add setting for sending crash reports
TRtomasz 1529dfb
other: fix formatting
TRtomasz 0304f3f
fix: change default send crash reports value to true
TRtomasz 798742e
other: fix formatting
TRtomasz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -271,6 +271,12 @@ pub trait Env { | |||||
.await?; | ||||||
schema_version = 15; | ||||||
} | ||||||
if schema_version == 15 { | ||||||
migrate_storage_schema_to_v16::<Self>() | ||||||
.map_err(|error| EnvError::StorageSchemaVersionUpgrade(Box::new(error))) | ||||||
.await?; | ||||||
schema_version = 16; | ||||||
} | ||||||
if schema_version != SCHEMA_VERSION { | ||||||
panic!( | ||||||
"Storage schema version must be upgraded from {} to {}", | ||||||
|
@@ -606,6 +612,33 @@ fn migrate_storage_schema_to_v15<E: Env>() -> TryEnvFuture<()> { | |||||
.boxed_env() | ||||||
} | ||||||
|
||||||
fn migrate_storage_schema_to_v16<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( | ||||||
"serverInForeground".to_owned(), | ||||||
serde_json::Value::Bool(false), | ||||||
); | ||||||
settings.insert( | ||||||
"sendCrashReports".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(&16))) | ||||||
.boxed_env() | ||||||
} | ||||||
|
||||||
#[cfg(test)] | ||||||
mod test { | ||||||
use serde_json::{json, Value}; | ||||||
|
@@ -619,8 +652,9 @@ mod test { | |||||
migrate_storage_schema_to_v10, migrate_storage_schema_to_v11, | ||||||
migrate_storage_schema_to_v12, migrate_storage_schema_to_v13, | ||||||
migrate_storage_schema_to_v14, migrate_storage_schema_to_v15, | ||||||
migrate_storage_schema_to_v6, migrate_storage_schema_to_v7, | ||||||
migrate_storage_schema_to_v8, migrate_storage_schema_to_v9, | ||||||
migrate_storage_schema_to_v16, migrate_storage_schema_to_v6, | ||||||
migrate_storage_schema_to_v7, migrate_storage_schema_to_v8, | ||||||
migrate_storage_schema_to_v9, | ||||||
}, | ||||||
Env, | ||||||
}, | ||||||
|
@@ -1150,4 +1184,43 @@ mod test { | |||||
assert_storage_schema_version(15); | ||||||
} | ||||||
} | ||||||
|
||||||
#[tokio::test] | ||||||
async fn test_migration_from_15_to_16() { | ||||||
let _test_env_guard = TestEnv::reset().expect("Should lock TestEnv"); | ||||||
|
||||||
let init_profile = json!({ | ||||||
"settings": {} | ||||||
}); | ||||||
|
||||||
let migrated_profile = json!({ | ||||||
"settings": { | ||||||
"serverInForeground": false, | ||||||
"sendCrashReports": false | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
}); | ||||||
|
||||||
set_profile_and_schema_version(&init_profile, 15); | ||||||
|
||||||
migrate_storage_schema_to_v16::<TestEnv>() | ||||||
.await | ||||||
.expect("Should migrate"); | ||||||
|
||||||
let storage = STORAGE.read().expect("Should lock"); | ||||||
|
||||||
assert_eq!( | ||||||
&16.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" | ||||||
); | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.