Module settings in each module's right-click menu, and System settings
CI / test (push) Failing after 15s
CI / test (push) Failing after 15s
- New optional WIT export `chandra:desktop/module-config` (wit/plasmoid.wit): config-items (key,
label, choices, current value; no choices = an on/off switch) and set-config. Hosts look it up
by name, so modules without it (or prebuilt ones like Pulse) load as before.
- Right-click a panel module: "Module settings..." (or a greyed "No module settings"), then
"System settings..." (the settings module, Session tab), then Replace with... and Remove widget.
The "Modules..." row is gone; right-clicking empty panel space offers "System settings..." on the
Panel tab instead. Module settings open in the same menu: on/off rows with a check box, choices
under a heading with the current one ticked; clicking applies at once and the menu stays open.
- Choices are saved per module id in state.edn as :module-config {"clock-digital" {"format"
"12-hour"}} (module_config.mbt; not an owned key, so save_state keeps it) and handed back through
set-config whenever the module is loaded. Other instances of the module follow a change.
- Both hosts: wasmer stub (optional exports 8-10, canonical-ABI decoding in wasm_native.mbt) and
host-wasm (chandra:host/plasmoids config-items/set-config, bound with a separate `configurable`
world so the export stays optional).
- Adopted by the digital clock (Time format 24-hour/12-hour, Show date) and the binary clock (Show
seconds); clock-widget now exports module-config.
- Tests: native menu end-to-end (open, pick 12-hour, heading inert, reload keeps it), state.edn
round trip, EDN unit test, wasmer and host-wasm module-config tests, lib/clock settings test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjuApkJR4sVRYDpDLy
This commit is contained in:
37 files changed
+1285
-128
No files matched your search
@@ -327,7 +327,7 @@ test "right-click a panel module to replace it in place, or remove it" {
|
||||
let bin = find_row("Replace with Binary Clock")
|
||||
assert_true(bin >= 0)
|
||||
assert_true(find_row("Remove widget") >= 0)
|
||||
assert_true(find_row("Module manager...") >= 0)
|
||||
assert_true(find_row("System settings...") >= 0)
|
||||
// Hover the row (hand cursor), click it: the binary clock takes the digital clock's place.
|
||||
let ix = m.x + m.w / 2
|
||||
let iy = m.y + 26 + 28 * bin + 14
|
||||
@@ -353,6 +353,82 @@ test "right-click a panel module to replace it in place, or remove it" {
|
||||
assert_eq(comp.shell.slots().length(), before.length() - 1)
|
||||
}
|
||||
|
||||
///|
|
||||
test "right-click a module for its own settings: they apply at once and are remembered" {
|
||||
let comp = new_comp("modcfg")
|
||||
assert_true(comp.shell.load_module("clock-digital"))
|
||||
ignore(comp.compose_frame())
|
||||
let clock = rect_of(comp, "clock-digital")
|
||||
assert_true(clock.w > 0)
|
||||
let row_y = fn(k : Int) { comp.shell.menu_rect.y + 26 + 28 * k + 14 }
|
||||
let find_row = fn(label : String) {
|
||||
let mut i = -1
|
||||
for k = 0; k < comp.shell.menu_rows.length(); k = k + 1 {
|
||||
if comp.shell.menu_rows[k].label == label {
|
||||
i = k
|
||||
}
|
||||
}
|
||||
i
|
||||
}
|
||||
let time_text = fn() {
|
||||
let mut t = ""
|
||||
for op in comp.shell.slot_ops(comp.shell.slot_of("clock-digital")) {
|
||||
match op {
|
||||
Text(x) => if t == "" { t = x.text }
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
t
|
||||
}
|
||||
assert_false(time_text().has_suffix("M")) // 24-hour by default
|
||||
click_at(comp, clock.x + clock.w / 2, clock.y + clock.h / 2, 1U, btn=273U)
|
||||
assert_true(comp.shell.menu_open)
|
||||
assert_eq(comp.shell.menu_rows[0].label, "Module settings...")
|
||||
assert_eq(comp.shell.menu_rows[1].label, "System settings...")
|
||||
click_at(comp, comp.shell.menu_rect.x + 60, row_y(0), 10U)
|
||||
// The module's own menu: a "Time format" heading, its two choices, and the "Show date" switch.
|
||||
assert_true(comp.shell.menu_open)
|
||||
assert_eq(comp.shell.menu_title, "Digital Clock settings")
|
||||
let h12 = find_row("12-hour")
|
||||
assert_true(h12 > 0 && find_row("Time format") == h12 - 2)
|
||||
assert_true(comp.shell.menu_rows[h12 - 1].ticked) // 24-hour
|
||||
click_at(comp, comp.shell.menu_rect.x + 60, row_y(h12), 20U)
|
||||
assert_true(comp.shell.menu_open) // stays open, now ticking 12-hour
|
||||
assert_true(comp.shell.menu_rows[find_row("12-hour")].ticked)
|
||||
assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM"))
|
||||
assert_eq(comp.shell.module_setting("clock-digital", "format"), Some("12-hour"))
|
||||
// A heading does nothing; Escape closes.
|
||||
click_at(comp, comp.shell.menu_rect.x + 60, row_y(find_row("Time format")), 30U)
|
||||
assert_true(comp.shell.menu_open)
|
||||
comp.handle_input(@nested.InputEvent::Key(1U, true), 40U)
|
||||
assert_false(comp.shell.menu_open)
|
||||
// A second instance of the module starts with the chosen setting.
|
||||
assert_true(comp.shell.unload_slot(comp.shell.slot_of("clock-digital")))
|
||||
assert_true(comp.shell.load_module("clock-digital"))
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM"))
|
||||
}
|
||||
|
||||
///|
|
||||
test "module settings are saved in state.edn and handed back at the next start" {
|
||||
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
|
||||
let theme = @scene.ThemeTokens::moon_night()
|
||||
let a = @shell.DesktopShell::new("x")
|
||||
a.persist = true
|
||||
a.set_output(theme, 1280, 720)
|
||||
assert_true(a.load_module("clock-binary"))
|
||||
a.set_module_setting(a.slot_of("clock-binary"), "seconds", "off")
|
||||
a.save_state() // the rest of state.edn is rewritten: :module-config stays
|
||||
let b = @shell.DesktopShell::new("x")
|
||||
b.persist = true
|
||||
b.set_output(theme, 1280, 720)
|
||||
assert_eq(b.module_setting("clock-binary", "seconds"), Some("off"))
|
||||
let slot = b.slot_of("clock-binary")
|
||||
assert_true(slot != "")
|
||||
assert_eq(b.slot_config(slot)[0].value, "off")
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "tapping Super toggles the launcher; Super+key does not" {
|
||||
let comp = new_comp("super")
|
||||
@@ -404,7 +480,7 @@ test "the wasm picker opens the settings module's Panel tab, which loads and unl
|
||||
let panel = comp.shell.panel_rect
|
||||
click_at(comp, 1, panel.y + 5, 1U, btn=273U)
|
||||
assert_true(comp.shell.menu_open)
|
||||
assert_eq(comp.shell.menu_rows[0].label, "Modules...")
|
||||
assert_eq(comp.shell.menu_rows[0].label, "System settings...")
|
||||
let m = comp.shell.menu_rect
|
||||
click_at(comp, m.x + m.w / 2, m.y + 26 + 14, 10U)
|
||||
assert_eq(comp.shell.slots().length(), n0) // nothing new was loaded for it
|
||||
|
||||
Reference in new issue
Block a user