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
|
|
@ -1,8 +1,11 @@
|
|||
//! Workspace state that commands read and change.
|
||||
|
||||
use crate::Event;
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::buffers::Buffers;
|
||||
use crate::settings::Settings;
|
||||
use crate::workspace::Workspace;
|
||||
use crate::{EngineConfig, Event, NotificationLevel};
|
||||
|
||||
/// Everything the engine knows about the running session.
|
||||
#[derive(Debug, Default)]
|
||||
|
|
@ -13,6 +16,13 @@ pub struct State {
|
|||
pub project: Option<Workspace>,
|
||||
/// Open buffers. Empty whenever no project is open.
|
||||
pub buffers: Buffers,
|
||||
/// Settings, saved to the config directory when the engine has one.
|
||||
pub settings: Settings,
|
||||
/// Where the engine stores its files; `None` for an engine without
|
||||
/// persistence ([`crate::Engine::new`]).
|
||||
pub config: Option<EngineConfig>,
|
||||
/// Number of notifications emitted, for their ids.
|
||||
notifications: u64,
|
||||
/// Events queued for the host, oldest first.
|
||||
events: Vec<Event>,
|
||||
}
|
||||
|
|
@ -23,6 +33,24 @@ impl State {
|
|||
self.events.push(event);
|
||||
}
|
||||
|
||||
/// Queues an [`Event::Notification`] with a fresh id (`n1`, `n2`…).
|
||||
pub fn notify(
|
||||
&mut self,
|
||||
level: NotificationLevel,
|
||||
message_key: Option<&str>,
|
||||
message: Option<String>,
|
||||
params: Option<Map<String, Value>>,
|
||||
) {
|
||||
self.notifications = self.notifications.saturating_add(1);
|
||||
self.emit(Event::Notification {
|
||||
id: format!("n{}", self.notifications),
|
||||
level,
|
||||
message_key: message_key.map(str::to_string),
|
||||
message,
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/// Takes the queued events, oldest first.
|
||||
pub fn take_events(&mut self) -> Vec<Event> {
|
||||
std::mem::take(&mut self.events)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue