53dbdf0f1d
Workspace en 4 ejes (core/modules/apps/shared):
- core/: 24 crates de arje (Init systemd-compatible: ente-card, ente-zero,
ente-kernel, ente-bus, ente-cas, ente-soma, ente-wasm, ente-snapshot,
ente-brain, ente-echo, ente-policy-provider, + 12 crates *-compat)
- modules/semantic_dht/: 5 crates de minga (minga-core con AST/CAS/MST,
minga-p2p con libp2p Kad, minga-store, minga-vfs, minga-cli)
- modules/ui_engine/: 11 crates de yahweh (libs/{core,theme,bus,providers},
widgets/{tree,splitter,tabs,tiled,container_core,text_input})
- apps/: 5 crates de yahweh (file_explorer, database_explorer, text_viewer,
image_viewer, yahweh-shell)
- shared_wit/protocol.wit: handshake/lifecycle inicial
Cargo.toml unificado: thiserror bumped a 2 (transparente para arje), tokio
"full", paths intra-workspace de yahweh redirigidos a su nueva ubicación.
cargo check --workspace: 0 errores, 17 warnings (dead code preexistente).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
1.8 KiB
Rust
53 lines
1.8 KiB
Rust
//! `Persister` — escribe el `LayoutModel` a disco en cada cambio.
|
|
//!
|
|
//! Es una entity sin estado visible (no se renderea). Solo existe para
|
|
//! mantener viva la subscripción al `LayoutModel`. Cualquier evento
|
|
//! (`StructureChanged` o `FlexChanged`) dispara una escritura sincrónica
|
|
//! al `path` configurado.
|
|
//!
|
|
//! Hoy NO hay debounce — cada drag de divisor emite UN solo `FlexChanged`
|
|
//! al final (en DragEnd, no por frame), y los swaps de kind son acción
|
|
//! manual del usuario. Si en el futuro las escrituras se vuelven
|
|
//! frecuentes, el lugar para sumar debounce es acá: spawn un task que
|
|
//! coalesce events dentro de N ms.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use gpui::{Context, Entity};
|
|
|
|
use crate::layout_model::{LayoutModel, LayoutModelEvent};
|
|
|
|
pub struct Persister {
|
|
path: PathBuf,
|
|
}
|
|
|
|
impl Persister {
|
|
pub fn new(path: PathBuf, model: Entity<LayoutModel>, cx: &mut Context<Self>) -> Self {
|
|
cx.subscribe(&model, |this: &mut Persister, model, _ev: &LayoutModelEvent, cx| {
|
|
this.write(model.read(cx).tree());
|
|
})
|
|
.detach();
|
|
Self { path }
|
|
}
|
|
|
|
fn write(&self, tree: &yahweh_core::LayerConfig) {
|
|
let json = tree.serialize_json();
|
|
// Anti-loop: si el contenido en disco ya coincide, skip. Esto
|
|
// matters cuando el watcher está corriendo: persister write →
|
|
// notify modify → replace_tree → persister write → ... sin esto
|
|
// sería un loop infinito de syscalls.
|
|
if let Ok(existing) = std::fs::read_to_string(&self.path) {
|
|
if existing == json {
|
|
return;
|
|
}
|
|
}
|
|
if let Err(e) = std::fs::write(&self.path, json) {
|
|
eprintln!(
|
|
"[Persister] error escribiendo {}: {}",
|
|
self.path.display(),
|
|
e
|
|
);
|
|
}
|
|
}
|
|
}
|