mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-20 09:05:51 +00:00
#3321: settings saved before turn Cache Frames When Idle on once (settings version 6)
This commit is contained in:
1 parent
d9a11b6917
commit
717b32fd10
4 files changed
+25
-6
No files matched your search
@@ -39,7 +39,7 @@ pub use sections::{
|
||||
use sections::{Extra, default_labels, lenient_comp_presets};
|
||||
|
||||
/// Current settings layout version.
|
||||
pub const PREFS_VERSION: u32 = 5;
|
||||
pub const PREFS_VERSION: u32 = 6;
|
||||
/// Settings file name in the config store.
|
||||
pub const PREFS_FILE: &str = "prefs.json";
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@ use super::{Appearance, General, Map, PREFS_VERSION, Prefs, Startup, Value, json
|
||||
/// - version 4 and earlier had the Layer Cache, Footage Frame Cache and Preview (RAM) Cache
|
||||
/// budgets (`memory.layerCacheMb` / `mediaCacheMb` / `previewCacheMb`); they are dropped: the
|
||||
/// caches share one budget (#3298).
|
||||
/// - version 5 and earlier saved Cache Frames When Idle off, the default then (every save kept
|
||||
/// it); it becomes the new default, on, once (#3321). Off saved later is the user's choice.
|
||||
/// (Released builds wrote version 4; version 5 came only from pre-release builds of #3301,
|
||||
/// nearly all of them with the default still off. A file without a version predates both.)
|
||||
pub fn migrate(mut v: Value) -> Value {
|
||||
let Some(obj) = v.as_object_mut() else { return json!({}) };
|
||||
let version = obj.get("version").and_then(Value::as_u64).unwrap_or(0);
|
||||
@@ -61,6 +65,12 @@ pub fn migrate(mut v: Value) -> Value {
|
||||
m.remove(key);
|
||||
}
|
||||
}
|
||||
if version < 6
|
||||
&& let Some(p) = obj.get_mut("previews").and_then(Value::as_object_mut)
|
||||
&& p.get("cacheFramesWhenIdle") == Some(&json!(false))
|
||||
{
|
||||
p.insert("cacheFramesWhenIdle".into(), json!(true));
|
||||
}
|
||||
// Settings saved before appearance modes had one theme: keep showing it, as a fixed Dark or
|
||||
// Light mode, instead of switching established users to Auto.
|
||||
if let Some(a) = obj.get_mut("appearance").and_then(Value::as_object_mut)
|
||||
|
||||
@@ -263,15 +263,23 @@ fn a_low_memory_episode_toasts_once_and_reapplies_the_budget() {
|
||||
assert_eq!(toasts(&mut s), 1);
|
||||
}
|
||||
|
||||
/// #3321: Cache Frames When Idle is on by default; a saved "off" stays off.
|
||||
/// #3321: Cache Frames When Idle is on by default. Settings saved before held the old default
|
||||
/// (off) and turn it on once; off saved after that is the user's choice and stays.
|
||||
#[test]
|
||||
fn cache_frames_when_idle_is_on_by_default() {
|
||||
use crate::prefs::Prefs;
|
||||
assert!(Prefs::default().previews.cache_frames_when_idle);
|
||||
assert!(Prefs::from_json(r#"{"version": 5, "previews": {"fastPreviews": true}}"#).previews.cache_frames_when_idle, "not saved: on");
|
||||
let off = Prefs::from_json(r#"{"version": 5, "previews": {"cacheFramesWhenIdle": false}}"#);
|
||||
assert!(Prefs::from_json(r#"{"version": 6, "previews": {"fastPreviews": true}}"#).previews.cache_frames_when_idle, "not saved: on");
|
||||
// An old file with the old default: on, once.
|
||||
let old = Prefs::from_json(r#"{"version": 5, "previews": {"cacheFramesWhenIdle": false}}"#);
|
||||
assert!(old.previews.cache_frames_when_idle, "the old default becomes the new one");
|
||||
assert!(Prefs::from_json(r#"{"version": 4, "previews": {"cacheFramesWhenIdle": true}}"#).previews.cache_frames_when_idle, "on stays on");
|
||||
// Turned off after the migration: stays off, also after the next save.
|
||||
let off = Prefs::from_json(r#"{"version": 6, "previews": {"cacheFramesWhenIdle": false}}"#);
|
||||
assert!(!off.previews.cache_frames_when_idle, "saved off: off");
|
||||
assert!(!Prefs::from_json(&off.to_json()).previews.cache_frames_when_idle, "and after the next save");
|
||||
let mut p = old;
|
||||
p.previews.cache_frames_when_idle = false;
|
||||
assert!(!Prefs::from_json(&p.to_json()).previews.cache_frames_when_idle, "and after the next save");
|
||||
}
|
||||
|
||||
/// #3298: settings saved with the three cache budgets (version 4, or a later file that still
|
||||
|
||||
Reference in new issue
Block a user