Merge pull request #1857 from storytold/fix/1747-prefs-on-ok
Fix #1747: Preferences are written when confirmed, not only at exit
This commit is contained in:
commit
c3a830bc38
|
|
@ -95,6 +95,11 @@ impl eframe::App for App {
|
||||||
self.app.titlebar_inset = inset.unwrap_or(mac_window::DEFAULT_INSET);
|
self.app.titlebar_inset = inset.unwrap_or(mac_window::DEFAULT_INSET);
|
||||||
}
|
}
|
||||||
file_access::unconfined(|| self.app.ui(ui));
|
file_access::unconfined(|| self.app.ui(ui));
|
||||||
|
// Preferences are written when confirmed, not only at exit: a session ended any other way
|
||||||
|
// (the system shutting down, the process ended or crashing) used to lose them (#1747).
|
||||||
|
if self.app.take_prefs_changed() {
|
||||||
|
file_access::unconfined(|| save_prefs(&self.app));
|
||||||
|
}
|
||||||
// Not while a file dialog's sheet has the keyboard: its name field's composition would go.
|
// Not while a file dialog's sheet has the keyboard: its name field's composition would go.
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
if !self.app.file_dialog_open() && self.app.take_ime_discard() {
|
if !self.app.file_dialog_open() && self.app.take_ime_discard() {
|
||||||
|
|
|
||||||
|
|
@ -425,6 +425,8 @@ pub struct VectorcraftApp {
|
||||||
pub(crate) ime_marked: Option<String>,
|
pub(crate) ime_marked: Option<String>,
|
||||||
/// The IME must drop its marked text (see [`Self::take_ime_discard`]).
|
/// The IME must drop its marked text (see [`Self::take_ime_discard`]).
|
||||||
pub(crate) ime_discard: bool,
|
pub(crate) ime_discard: bool,
|
||||||
|
/// Preferences were confirmed (see [`Self::take_prefs_changed`]).
|
||||||
|
pub(crate) prefs_changed: bool,
|
||||||
/// A numeric field is being scrubbed: the document's edits meanwhile are one undo step
|
/// A numeric field is being scrubbed: the document's edits meanwhile are one undo step
|
||||||
/// ([`scrub::begin_frame`]).
|
/// ([`scrub::begin_frame`]).
|
||||||
scrub_group: bool,
|
scrub_group: bool,
|
||||||
|
|
@ -518,6 +520,7 @@ impl VectorcraftApp {
|
||||||
synthetic_modifiers: false,
|
synthetic_modifiers: false,
|
||||||
ime_marked: None,
|
ime_marked: None,
|
||||||
ime_discard: false,
|
ime_discard: false,
|
||||||
|
prefs_changed: false,
|
||||||
scrub_group: false,
|
scrub_group: false,
|
||||||
automation_roots: None,
|
automation_roots: None,
|
||||||
synthetic_frame: false,
|
synthetic_frame: false,
|
||||||
|
|
@ -857,6 +860,12 @@ impl VectorcraftApp {
|
||||||
std::mem::take(&mut self.ime_discard)
|
std::mem::take(&mut self.ime_discard)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Was Preferences confirmed since the last call? The host then writes the preferences file,
|
||||||
|
/// so what the user just set survives a session that doesn't end with a normal quit (#1747).
|
||||||
|
pub fn take_prefs_changed(&mut self) -> bool {
|
||||||
|
std::mem::take(&mut self.prefs_changed)
|
||||||
|
}
|
||||||
|
|
||||||
/// Linked files another app changed while their document is open: every two seconds, and as
|
/// Linked files another app changed while their document is open: every two seconds, and as
|
||||||
/// soon as the window comes back to the front, stamp the active document's linked files on a
|
/// soon as the window comes back to the front, stamp the active document's linked files on a
|
||||||
/// worker thread and act on the changed ones as Preferences › File Handling › Update Links
|
/// worker thread and act on the changed ones as Preferences › File Handling › Update Links
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ pub fn confirm(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||||
app.ui.task_bar = d.fields.get("__taskBar").and_then(Value::as_bool).unwrap_or(app.ui.task_bar);
|
app.ui.task_bar = d.fields.get("__taskBar").and_then(Value::as_bool).unwrap_or(app.ui.task_bar);
|
||||||
app.ui.dialog = None;
|
app.ui.dialog = None;
|
||||||
app.ui.engine_prefs = app.session.prefs.to_json();
|
app.ui.engine_prefs = app.session.prefs.to_json();
|
||||||
|
app.prefs_changed = true;
|
||||||
Ok(Value::Null)
|
Ok(Value::Null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -557,7 +558,10 @@ mod tests {
|
||||||
assert!(shown.iter().any(|t| t == "Automatic"), "{shown:?}");
|
assert!(shown.iter().any(|t| t == "Automatic"), "{shown:?}");
|
||||||
assert!(shown.iter().any(|t| t == "Applies the next time VectorCraft starts."), "{shown:?}");
|
assert!(shown.iter().any(|t| t == "Applies the next time VectorCraft starts."), "{shown:?}");
|
||||||
a.ui.dialog.as_mut().unwrap().fields.insert("gpuPreference".into(), json!("highPerformance"));
|
a.ui.dialog.as_mut().unwrap().fields.insert("gpuPreference".into(), json!("highPerformance"));
|
||||||
|
assert!(!a.take_prefs_changed(), "nothing to write before OK");
|
||||||
confirm(&mut a).unwrap();
|
confirm(&mut a).unwrap();
|
||||||
|
assert!(a.take_prefs_changed(), "OK asks the host to write the preferences file");
|
||||||
|
assert!(!a.take_prefs_changed());
|
||||||
assert_eq!(a.session.prefs.gpu_preference, "highPerformance");
|
assert_eq!(a.session.prefs.gpu_preference, "highPerformance");
|
||||||
let saved: Value = serde_json::from_slice(&serde_json::to_vec(&a.ui).unwrap()).unwrap();
|
let saved: Value = serde_json::from_slice(&serde_json::to_vec(&a.ui).unwrap()).unwrap();
|
||||||
assert_eq!(saved["engine_prefs"]["gpuPreference"], json!("highPerformance"));
|
assert_eq!(saved["engine_prefs"]["gpuPreference"], json!("highPerformance"));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue