feat(qt): restore and persist the main window geometry
The reported symptom was titles eliding early in every bar mode. Root
cause was not the breakpoints: Main.qml pinned 1280x800 on every launch
while Slint restores window_width from the shared ui_prefs.json (1716 on
the owner's profile). 1280 sits one tier below the 1366 breakpoint, so
Classic's song card capped at 446px instead of reaching its 560px cap --
the ~114px of early elision.
Restoring alone would have fixed that. Saving is the half that makes the
feature real, and it is where the risk lives, so it is built to Slint's
semantics rather than invented: floating-size-only keys, the app minimum
as a gate, the >0.5px dirty check, maximized only ever re-applied.
Two things Qt makes harder than winit and both bit:
Visibility is ONE enum where Minimized replaces Maximized, while winit
keeps them orthogonal and still reports maximized while iconified. So
the flag is latched from the last non-transient visibility. The first
attempt read that through a derived property inside the handler for the
same signal that dirties it, which is one transition stale -- it passed
grep, qmllint and rustfmt, and was caught only by driving real
transitions under qml6. It is a function now; a function has no cached
value to be stale.
And the writes share a file with the shipping Slint app. A truncating
fs::write plus a json!({}) fallback on parse failure meant either side
could flatten the other's document: Slint reading inside the truncate
window falls back to UiPrefs::default() and writes those defaults back.
Every writer in the crate now goes through one atomic read-modify-write
(tmp + rename), and a file that is present but unparsable aborts the
save instead of being rebuilt from nothing.
The Slint side keeps its own non-atomic write, so the cross-process race
is narrowed, not closed.
cc
This commit is contained in:
6 files changed
+992
-175
No files matched your search
@@ -101,35 +101,34 @@ fn rank_within<T>(query: &str, kind: &str, items: &mut Vec<T>, id_of: impl Fn(&T
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ui_prefs intelligent_search (the 2.0.0 opt-out, additive like the others)
|
||||
// ui_prefs intelligent_search (the 2.0.0 opt-out).
|
||||
//
|
||||
// Both halves are settings_qt's now. This module used to keep its own path,
|
||||
// its own `json!({})` fallback and its own truncating `std::fs::write` on
|
||||
// ui_prefs.json — the file the SHIPPING Slint build has open — so one search
|
||||
// toggle could hand Slint's `load()` an empty document and let its next save
|
||||
// flatten the whole profile. See the write-discipline block in settings_qt.rs.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub fn intelligent_search_pref() -> bool {
|
||||
let Some(path) = dirs::data_dir().map(|d| d.join("qbz").join("ui_prefs.json")) else {
|
||||
return true;
|
||||
};
|
||||
std::fs::read_to_string(path)
|
||||
.ok()
|
||||
.and_then(|text| serde_json::from_str::<serde_json::Value>(&text).ok())
|
||||
.and_then(|v| v.get("intelligent_search").and_then(|q| q.as_bool()))
|
||||
.unwrap_or(true)
|
||||
crate::settings_qt::pref_bool("intelligent_search", true)
|
||||
}
|
||||
|
||||
/// Flip + persist the pref and flip the live kill switch; returns the new value.
|
||||
///
|
||||
/// The read and the write share ONE document (`toggle_pref_bool`): reading the
|
||||
/// old value through `intelligent_search_pref` first would answer a torn read
|
||||
/// with the default `true` and then commit `false` over a user who already had
|
||||
/// it off. When nothing could be written the live switch is left alone too —
|
||||
/// the two must not diverge.
|
||||
pub fn toggle_intelligent_search() -> bool {
|
||||
let next = !intelligent_search_pref();
|
||||
if let Some(path) = dirs::data_dir().map(|d| d.join("qbz").join("ui_prefs.json")) {
|
||||
let mut value: serde_json::Value = std::fs::read_to_string(&path)
|
||||
.ok()
|
||||
.and_then(|text| serde_json::from_str(&text).ok())
|
||||
.unwrap_or_else(|| serde_json::json!({}));
|
||||
if let Some(obj) = value.as_object_mut() {
|
||||
obj.insert("intelligent_search".to_string(), serde_json::Value::Bool(next));
|
||||
if let Ok(text) = serde_json::to_string_pretty(&value) {
|
||||
let _ = std::fs::write(&path, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some(next) = crate::settings_qt::toggle_pref_bool("intelligent_search", true) else {
|
||||
let current = intelligent_search_pref();
|
||||
log::warn!(
|
||||
"[qbz-qt] intelligent_search toggle skipped (prefs unreadable) — staying {current}"
|
||||
);
|
||||
return current;
|
||||
};
|
||||
set_enabled(next);
|
||||
next
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user