feat(tahuantinsuyu): persistir flex de los splitters entre sesiones

Hasta ahora cada boot reseteaba los splitters al default (1:4
horizontal, 4:1 vertical), forzando a rearrastrar manualmente cada
vez. Ahora el flex se guarda en la tabla `settings` ya existente.

- `tahuantinsuyu-store`: nuevos `get_setting`/`set_setting` con
  upsert + test de roundtrip.
- `tahuantinsuyu` shell: al boot, `load_split_flex` lee
  `layout.main_split` y `layout.outer_split` (formato "a,b" como
  texto). Si no hay entry o está corrupto cae a defaults.
- Subscribe a `SplitEvent::DragEnd` en cada splitter — `save_split_flex`
  escribe los flex actuales al settings. Mouseup-driven, no
  cada-frame: 0 escrituras durante el drag, 1 al final.

`module_configs` ya estaba persistido por carta vía la tabla
`module_state` (`persist_module` + `load_persisted_module_states`),
no requiere cambios.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
sergio
2026-05-18 00:51:31 +00:00
parent 904f334069
commit e044d47516
2 changed files with 107 additions and 7 deletions
@@ -419,6 +419,35 @@ impl Store {
Ok(out)
}
// -----------------------------------------------------------------
// Settings (key/value libre — layout, last-opened chart, etc.)
// -----------------------------------------------------------------
/// Lee un valor de la tabla `settings`. `None` si no existe.
pub fn get_setting(&self, key: &str) -> StoreResult<Option<String>> {
let conn = self.conn.lock().unwrap();
let val = conn
.query_row(
"SELECT value FROM settings WHERE key = ?1",
params![key],
|row| row.get::<_, String>(0),
)
.optional()?;
Ok(val)
}
/// Upsert un setting. El valor es texto libre — para JSON, el caller
/// serializa antes de llamar.
pub fn set_setting(&self, key: &str, value: &str) -> StoreResult<()> {
let conn = self.conn.lock().unwrap();
conn.execute(
"INSERT INTO settings (key, value) VALUES (?1, ?2) \
ON CONFLICT(key) DO UPDATE SET value = excluded.value",
params![key, value],
)?;
Ok(())
}
// -----------------------------------------------------------------
// Recursive descent: charts under a group/contact (para thumbnails)
// -----------------------------------------------------------------
@@ -676,6 +705,23 @@ mod tests {
assert_eq!(by_id["transit"].enabled, false);
}
#[test]
fn settings_upsert_and_read() {
let s = Store::in_memory().unwrap();
assert_eq!(s.get_setting("layout.outer").unwrap(), None);
s.set_setting("layout.outer", "4.0,1.0").unwrap();
assert_eq!(
s.get_setting("layout.outer").unwrap().as_deref(),
Some("4.0,1.0")
);
// Upsert — el segundo set sobreescribe.
s.set_setting("layout.outer", "3.5,1.5").unwrap();
assert_eq!(
s.get_setting("layout.outer").unwrap().as_deref(),
Some("3.5,1.5")
);
}
#[test]
fn full_hierarchy_roundtrip() {
let s = Store::in_memory().unwrap();