clock-digital12 and clock-digital had become the same module (same lib/clock code, same right-click settings), differing only in the starting format. Keep one: the Digital Clock now starts in 12-hour mode with AM/PM, and its "Time format" setting switches to 24-hour. - components/clock-digital12 is gone (and from scripts/components.txt); lib/clock drops digital12_info/digital12_config. - The default panel loads clock-digital. - "clock-digital12" stays an alias (find_module, slot_of, saved panels) and is never listed in the module picker, even if an old .wasm is still installed. - panel.edn gets :version 2. A version-1 panel is migrated once: the old 12-hour clock becomes the Digital Clock with its settings (state.edn :module-config) moved over in 12-hour mode; a panel that had the old 24-hour Digital Clock keeps 24-hour. The file is rewritten afterwards. - Tests updated, plus a migration test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgnZsS91fwCreut8FL
This commit is contained in:
25 files changed
+207
-925
No files matched your search
@@ -370,7 +370,7 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
|
||||
test "right-click a panel module to replace it in place, or remove it" {
|
||||
let comp = new_comp("swap")
|
||||
let before = comp.shell.slots()
|
||||
let clock = rect_of(comp, "clock-digital12")
|
||||
let clock = rect_of(comp, "clock-digital")
|
||||
assert_true(clock.w > 0)
|
||||
let find_row = fn(label : String) {
|
||||
let mut i = -1
|
||||
@@ -396,7 +396,7 @@ test "right-click a panel module to replace it in place, or remove it" {
|
||||
assert_eq(comp.desired_cursor(), 4U)
|
||||
click_at(comp, ix, iy, 11U)
|
||||
assert_true(!comp.shell.menu_open)
|
||||
assert_eq(comp.shell.slot_of("clock-digital12"), "")
|
||||
assert_eq(comp.shell.slot_of("clock-digital"), "")
|
||||
let after = comp.shell.slots()
|
||||
assert_eq(after.length(), before.length())
|
||||
assert_eq(after[after.length() - 1], comp.shell.slot_of("clock-binary")) // same place in the panel
|
||||
@@ -417,6 +417,8 @@ test "right-click a panel module to replace it in place, or remove it" {
|
||||
///|
|
||||
test "right-click a module for its own settings: they apply at once and are remembered" {
|
||||
let comp = new_comp("modcfg")
|
||||
// A fresh instance next to nothing else: drop the default panel's clock first.
|
||||
assert_true(comp.shell.unload_slot(comp.shell.slot_of("clock-digital")))
|
||||
assert_true(comp.shell.load_module("clock-digital"))
|
||||
ignore(comp.compose_frame())
|
||||
let clock = rect_of(comp, "clock-digital")
|
||||
@@ -441,23 +443,25 @@ test "right-click a module for its own settings: they apply at once and are reme
|
||||
}
|
||||
t
|
||||
}
|
||||
assert_false(time_text().has_suffix("M")) // 24-hour by default
|
||||
assert_true(time_text().has_suffix("AM") || time_text().has_suffix("PM")) // 12-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.
|
||||
// The module's own menu: a "Time format" heading, its two choices, then the switches.
|
||||
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"))
|
||||
let h24 = find_row("24-hour")
|
||||
assert_true(h24 > 0 && find_row("Time format") == h24 - 1)
|
||||
assert_true(comp.shell.menu_rows[h24 + 1].ticked) // 12-hour
|
||||
assert_true(find_row("Show AM/PM") >= 0)
|
||||
click_at(comp, comp.shell.menu_rect.x + 60, row_y(h24), 20U)
|
||||
assert_true(comp.shell.menu_open) // stays open, now ticking 24-hour
|
||||
assert_true(comp.shell.menu_rows[find_row("24-hour")].ticked)
|
||||
assert_eq(find_row("Show AM/PM"), -1) // only offered in 12-hour mode
|
||||
assert_false(time_text().has_suffix("M"))
|
||||
assert_eq(comp.shell.module_setting("clock-digital", "format"), Some("24-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)
|
||||
@@ -467,7 +471,7 @@ test "right-click a module for its own settings: they apply at once and are reme
|
||||
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"))
|
||||
assert_false(time_text().has_suffix("M"))
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -529,6 +533,50 @@ test "the panel is saved to panel.edn and restored" {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "a panel saved with the old 12-hour clock gets the Digital Clock with the same settings" {
|
||||
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
|
||||
let dir = @sys.getenv("XDG_CONFIG_HOME") + "/chandra"
|
||||
assert_true(@sys.mkdir_p(dir))
|
||||
let state0 = @sys.read_file_bytes(dir + "/state.edn")
|
||||
let write = fn(name : String, text : String) {
|
||||
ignore(@sys.write_file_bytes(dir + "/" + name, @utf8.encode(text)))
|
||||
}
|
||||
let boot = fn() {
|
||||
let s = @shell.DesktopShell::new("x")
|
||||
s.persist = true
|
||||
s.set_output(@scene.ThemeTokens::moon_night(), 1280, 720)
|
||||
ignore(s.slots())
|
||||
s
|
||||
}
|
||||
// The default panel's 12-hour clock, its date line switched off.
|
||||
write("panel.edn", "{:panel [\"tasks\" \"clock-digital12\" \"logout\"]}\n")
|
||||
write("state.edn", "{:module-config {\"clock-digital12\" {\"date\" \"off\"} \"clock-digital\" {\"format\" \"24-hour\"}}}\n")
|
||||
let a = boot()
|
||||
assert_true(a.slot_of("clock-digital") != "")
|
||||
assert_eq(a.slot_of("clock-digital12"), a.slot_of("clock-digital")) // the old id is an alias
|
||||
assert_eq(a.module_setting("clock-digital", "format"), Some("12-hour"))
|
||||
assert_eq(a.module_setting("clock-digital", "date"), Some("off"))
|
||||
assert_eq(a.module_setting("clock-digital12", "date"), None)
|
||||
let panel = @utf8.decode_lossy(@sys.read_file_bytes(dir + "/panel.edn"))
|
||||
assert_true(panel.contains("\"clock-digital\"") && !panel.contains("clock-digital12"))
|
||||
assert_true(panel.contains(":version 2"))
|
||||
// Only once: a format chosen afterwards sticks across restarts.
|
||||
a.set_module_setting(a.slot_of("clock-digital"), "format", "24-hour")
|
||||
assert_eq(boot().module_setting("clock-digital", "format"), Some("24-hour"))
|
||||
// A panel that had the (then 24-hour) Digital Clock keeps it in 24-hour mode.
|
||||
write("panel.edn", "{:panel [\"tasks\" \"clock-digital\"]}\n")
|
||||
write("state.edn", "{}\n")
|
||||
assert_eq(boot().module_setting("clock-digital", "format"), Some("24-hour"))
|
||||
// A panel saved since then is left alone.
|
||||
write("panel.edn", "{:panel [\"tasks\" \"clock-digital\"]\n :version 2}\n")
|
||||
write("state.edn", "{}\n")
|
||||
assert_eq(boot().module_setting("clock-digital", "format"), None)
|
||||
write("panel.edn", "")
|
||||
ignore(@sys.write_file_bytes(dir + "/state.edn", state0))
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "the wasm picker opens the settings module's Panel tab, which loads and unloads modules" {
|
||||
let comp = new_comp("manager")
|
||||
@@ -591,7 +639,7 @@ test "dragging a panel module reorders it" {
|
||||
let comp = new_comp("wdrag")
|
||||
let order0 = comp.shell.slots()
|
||||
let moon = rect_of(comp, "moon-disc")
|
||||
let clock = rect_of(comp, "clock-digital12")
|
||||
let clock = rect_of(comp, "clock-digital")
|
||||
assert_true(moon.x < clock.x)
|
||||
let cy = (clock.y + clock.h / 2).to_double()
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((clock.x + clock.w / 2).to_double(), cy), 1U)
|
||||
@@ -605,8 +653,8 @@ test "dragging a panel module reorders it" {
|
||||
let order1 = comp.shell.slots()
|
||||
assert_eq(order1.length(), order0.length())
|
||||
assert_true(order1 != order0)
|
||||
assert_eq(order1[order1.length() - 2], comp.shell.slot_of("clock-digital12"))
|
||||
assert_true(rect_of(comp, "clock-digital12").x < rect_of(comp, "moon-disc").x)
|
||||
assert_eq(order1[order1.length() - 2], comp.shell.slot_of("clock-digital"))
|
||||
assert_true(rect_of(comp, "clock-digital").x < rect_of(comp, "moon-disc").x)
|
||||
assert_true(comp.desired_cursor() != 17U)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ test "inspector shows the WIT interface of the hovered component" {
|
||||
ignore(@sys.write_file_bytes("_build/inspector_launcher.png", png))
|
||||
|
||||
// Clock, panel, window title bar and desktop resolve to their own components.
|
||||
let (cx, cy) = center_of(comp, "clock-digital12")
|
||||
let (cx, cy) = center_of(comp, "clock-digital")
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(cx, cy), 5U)
|
||||
assert_eq(comp.shell.hover_id, comp.shell.slot_of("clock-digital12"))
|
||||
assert_eq(comp.shell.hover_id, comp.shell.slot_of("clock-digital"))
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(1270.0, 5.0), 6U)
|
||||
assert_eq(comp.shell.hover_id, "desktop")
|
||||
|
||||
|
||||
Reference in new issue
Block a user