M1.9a: engine dirs and settings backend
EngineConfig and Engine::with_config; the desktop resolves Tauri's app config and data dirs. Settings model (appearance.theme, editor.fontSize, ui.language) with typed validation, persistence in settings.json via write_atomic (1 MiB cap, unknown keys kept, corrupt file backed up with a warning notification), settings.list/get/set/reset, settingsChanged and notification events. Property test over random settings.json content, control-channel test for persistence and corrupt-file recovery. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
851d438e2a
commit
f9357ee4b5
17 changed files with 1406 additions and 41 deletions
|
|
@ -11,6 +11,7 @@
|
|||
//! Paths are project-relative with `/` separators, the root is `""`.
|
||||
|
||||
use serde::Serialize;
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
/// A state change.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
|
|
@ -76,13 +77,48 @@ pub enum Event {
|
|||
/// Why.
|
||||
message: String,
|
||||
},
|
||||
/// The effective value of settings changed; refetch them with
|
||||
/// `settings.get`.
|
||||
SettingsChanged {
|
||||
/// The changed keys.
|
||||
keys: Vec<String>,
|
||||
},
|
||||
/// A message for the user, shown as a toast.
|
||||
Notification {
|
||||
/// Unique id of this notification, for dismissing it.
|
||||
id: String,
|
||||
/// Severity.
|
||||
level: NotificationLevel,
|
||||
/// Message-catalog key of the text.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
message_key: Option<String>,
|
||||
/// English text, for messages without a catalog key and as a
|
||||
/// fallback.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
message: Option<String>,
|
||||
/// Interpolation params for the catalog text.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
params: Option<Map<String, Value>>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Severity of an [`Event::Notification`].
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum NotificationLevel {
|
||||
/// Information; dismissed automatically.
|
||||
Info,
|
||||
/// Something went wrong but Lutra kept working.
|
||||
Warning,
|
||||
/// An action failed.
|
||||
Error,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use super::Event;
|
||||
use super::{Event, NotificationLevel};
|
||||
|
||||
#[test]
|
||||
fn serialises_with_kind_and_camel_case_fields() {
|
||||
|
|
@ -100,4 +136,34 @@ mod tests {
|
|||
json!({"kind": "projectClosed"})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notification_and_settings_shapes() {
|
||||
let mut params = serde_json::Map::new();
|
||||
params.insert("backup".into(), json!("settings.json.bad-x"));
|
||||
let n = Event::Notification {
|
||||
id: "n1".into(),
|
||||
level: NotificationLevel::Warning,
|
||||
message_key: Some("notification.settings.corrupt".into()),
|
||||
message: None,
|
||||
params: Some(params),
|
||||
};
|
||||
assert_eq!(
|
||||
serde_json::to_value(n).unwrap(),
|
||||
json!({
|
||||
"kind": "notification",
|
||||
"id": "n1",
|
||||
"level": "warning",
|
||||
"messageKey": "notification.settings.corrupt",
|
||||
"params": {"backup": "settings.json.bad-x"},
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(Event::SettingsChanged {
|
||||
keys: vec!["editor.fontSize".into()]
|
||||
})
|
||||
.unwrap(),
|
||||
json!({"kind": "settingsChanged", "keys": ["editor.fontSize"]})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue