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
@@ -87,6 +87,11 @@ fn DesktopShell::remember_module_setting(self : DesktopShell, id : String, key :
|
||||
self.module_cfg.set(id, m)
|
||||
}
|
||||
}
|
||||
self.write_module_cfg()
|
||||
}
|
||||
|
||||
///| Write `:module-config` to state.edn, keeping every other key (a no-op without `persist`).
|
||||
fn DesktopShell::write_module_cfg(self : DesktopShell) -> Unit {
|
||||
if !self.persist {
|
||||
return
|
||||
}
|
||||
@@ -107,6 +112,35 @@ fn DesktopShell::remember_module_setting(self : DesktopShell, id : String, key :
|
||||
write_state_file(entries)
|
||||
}
|
||||
|
||||
///| A panel saved before the 12-hour clock (clock-digital12) became part of the Digital Clock
|
||||
/// (panel.edn version 1, `saved` its module list as written): keep each clock as it was. The
|
||||
/// 12-hour clock's settings become the Digital Clock's, starting from 12-hour mode; a panel that
|
||||
/// had only the Digital Clock keeps it in 24-hour mode (its old default) unless a format was chosen.
|
||||
/// A panel with both now has two Digital Clocks sharing the Digital Clock's settings.
|
||||
fn DesktopShell::migrate_module_cfg(self : DesktopShell, saved : Array[String]) -> Unit {
|
||||
self.read_module_cfg()
|
||||
let had12 = saved.contains("clock-digital12")
|
||||
let had24 = saved.contains("clock-digital")
|
||||
let old12 = self.module_cfg.get("clock-digital12")
|
||||
if had12 && !had24 {
|
||||
let m : Map[String, String] = { "format": "12-hour" }
|
||||
match old12 {
|
||||
Some(o) => for k, v in o { m.set(k, v) }
|
||||
None => ()
|
||||
}
|
||||
self.module_cfg.set("clock-digital", m)
|
||||
} else if had24 && !had12 {
|
||||
match self.module_cfg.get("clock-digital") {
|
||||
Some(m) => if !m.contains("format") { m.set("format", "24-hour") }
|
||||
None => self.module_cfg.set("clock-digital", { "format": "24-hour" })
|
||||
}
|
||||
}
|
||||
if (had12 && !had24) || (had24 && !had12) || old12 is Some(_) {
|
||||
self.module_cfg.remove("clock-digital12")
|
||||
self.write_module_cfg()
|
||||
}
|
||||
}
|
||||
|
||||
///| The setting `key` of module `id` as last chosen, if any.
|
||||
pub fn DesktopShell::module_setting(self : DesktopShell, id : String, key : String) -> String? {
|
||||
self.read_module_cfg()
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
|
||||
let default_panel : Array[String] = [
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital12", "screenshot",
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital", "screenshot",
|
||||
"session-settings", "logout",
|
||||
]
|
||||
|
||||
@@ -25,7 +25,7 @@ fn fresh_panel(has_battery : Bool) -> Array[String] {
|
||||
}
|
||||
let out : Array[String] = []
|
||||
for m in default_panel {
|
||||
if m == "clock-digital12" {
|
||||
if m == "clock-digital" {
|
||||
out.push("battery")
|
||||
}
|
||||
out.push(m)
|
||||
@@ -37,7 +37,21 @@ fn fresh_panel(has_battery : Bool) -> Array[String] {
|
||||
test "a fresh panel gets the battery module only on a machine with a battery" {
|
||||
assert_false(fresh_panel(false).contains("battery"))
|
||||
let p = fresh_panel(true)
|
||||
assert_eq(p.search("battery").unwrap() + 1, p.search("clock-digital12").unwrap())
|
||||
assert_eq(p.search("battery").unwrap() + 1, p.search("clock-digital").unwrap())
|
||||
}
|
||||
|
||||
///| Modules folded into another one: old id -> the module that took over. The old id still
|
||||
/// works everywhere a module is named (saved panels, load_module), it is just never listed:
|
||||
/// a stale build/components/clock-digital12.wasm or an old installed copy stays out of the picker.
|
||||
/// - clock-digital12, the 12-hour clock, is the Digital Clock, which now starts in 12-hour mode.
|
||||
let retired_modules : Map[String, String] = { "clock-digital12": "clock-digital" }
|
||||
|
||||
///| The id a module goes by now ("clock-digital12" -> "clock-digital").
|
||||
fn current_module_id(id : String) -> String {
|
||||
match retired_modules.get(id) {
|
||||
Some(n) => n
|
||||
None => id
|
||||
}
|
||||
}
|
||||
|
||||
///| The module whose popup holds the wasm picker (its Modules tab).
|
||||
@@ -111,7 +125,7 @@ fn DesktopShell::scan_catalog(self : DesktopShell) -> Unit {
|
||||
for dir in module_dirs() {
|
||||
for f in @wasm.list_wasm_files(dir) {
|
||||
let id = stem(f)
|
||||
if !seen.contains(id) {
|
||||
if !seen.contains(id) && !retired_modules.contains(id) {
|
||||
seen.set(id, true)
|
||||
self.catalog.push({ id, path: dir + "/" + f, name: "" })
|
||||
}
|
||||
@@ -145,6 +159,7 @@ fn DesktopShell::name_catalog(self : DesktopShell) -> Unit {
|
||||
|
||||
///| Catalog entry for module id `id`.
|
||||
fn DesktopShell::find_module(self : DesktopShell, id : String) -> CatalogEntry? {
|
||||
let id = current_module_id(id)
|
||||
for e in self.catalog {
|
||||
if e.id == id {
|
||||
return Some(e)
|
||||
@@ -199,7 +214,8 @@ fn wall_secs() -> Int {
|
||||
|
||||
///| Panels saved before the wallpaper chooser and the module manager moved into the settings
|
||||
/// module list "wallpaper" or "module-manager": the settings module takes the first one's place
|
||||
/// (a panel that already has it just drops them).
|
||||
/// (a panel that already has it just drops them). Retired modules (clock-digital12) become
|
||||
/// the module that replaced them.
|
||||
fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||
let has_settings = entries.contains("session-settings")
|
||||
let out : Array[String] = []
|
||||
@@ -209,7 +225,7 @@ fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||
out.push("session-settings")
|
||||
}
|
||||
} else {
|
||||
out.push(e)
|
||||
out.push(current_module_id(e))
|
||||
}
|
||||
}
|
||||
out
|
||||
@@ -223,6 +239,13 @@ test "a saved panel's wallpaper button becomes the settings module" {
|
||||
assert_eq(migrate_panel(["clock"]), ["clock"])
|
||||
}
|
||||
|
||||
///|
|
||||
test "a saved panel's 12-hour clock becomes the digital clock" {
|
||||
assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["tasks", "clock-digital", "logout"])
|
||||
assert_eq(current_module_id("clock-digital12"), "clock-digital")
|
||||
assert_eq(current_module_id("clock-binary"), "clock-binary")
|
||||
}
|
||||
|
||||
///| Load the panel on first use: the saved layout if there is one, else the default modules.
|
||||
fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
if self.booted {
|
||||
@@ -230,10 +253,20 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
}
|
||||
self.booted = true
|
||||
self.scan_catalog()
|
||||
let entries = match self.load_panel_config() {
|
||||
let saved = self.load_panel_config()
|
||||
let entries = match saved {
|
||||
Some(e) => migrate_panel(e)
|
||||
None => fresh_panel(read_battery().state != 0)
|
||||
}
|
||||
match saved {
|
||||
Some(old) if saved_panel_version() < panel_version => {
|
||||
// Once, before the modules load so they pick up the moved settings; then the file is
|
||||
// rewritten with the new names and version (also keeping modules that fail to load).
|
||||
self.migrate_module_cfg(old)
|
||||
write_panel_file(entries)
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
for e in entries {
|
||||
let path = if e.has_prefix("/") {
|
||||
e
|
||||
@@ -380,6 +413,7 @@ pub fn DesktopShell::slot_module(self : DesktopShell, slot : String) -> String {
|
||||
///| Slot of the first loaded instance of module `id` ("" if none).
|
||||
pub fn DesktopShell::slot_of(self : DesktopShell, id : String) -> String {
|
||||
self.ensure_booted()
|
||||
let id = current_module_id(id)
|
||||
for w in self.widgets {
|
||||
if w.module_id == id {
|
||||
return w.slot
|
||||
@@ -1007,30 +1041,74 @@ fn read_config_file(name : String) -> Bytes {
|
||||
}
|
||||
|
||||
///| Write the loaded modules, in panel order, as EDN:
|
||||
/// {:panel ["launcher" "layout" "tasks" "/home/me/my-widget.wasm"]}
|
||||
/// {:panel ["launcher" "layout" "tasks" "/home/me/my-widget.wasm"] :version 2}
|
||||
/// (catalog modules by name, others by path). A no-op unless `persist` is on.
|
||||
pub fn DesktopShell::save_panel_config(self : DesktopShell) -> Unit {
|
||||
if !self.persist || !self.booted {
|
||||
return
|
||||
}
|
||||
write_panel_file(self.widgets.map(w => w.module_id))
|
||||
}
|
||||
|
||||
///| panel.edn's format version (`:version`; files without one are 1). 2: written after the
|
||||
/// 12-hour clock (clock-digital12) became part of the Digital Clock, whose default went from
|
||||
/// 24-hour to 12-hour; an older file gets its clock settings moved over once (migrate_module_cfg).
|
||||
let panel_version : Int = 2
|
||||
|
||||
///|
|
||||
fn write_panel_file(names : Array[String]) -> Unit {
|
||||
let sb = StringBuilder::new()
|
||||
sb.write_string(";; Chandra panel: the wasm modules loaded into it, in order\n")
|
||||
sb.write_string("{:panel [")
|
||||
let mut first = true
|
||||
for w in self.widgets {
|
||||
for n in names {
|
||||
if !first {
|
||||
sb.write_string("\n ")
|
||||
}
|
||||
first = false
|
||||
sb.write_string("\"" + w.module_id + "\"")
|
||||
sb.write_string("\"" + n + "\"")
|
||||
}
|
||||
sb.write_string("]}\n")
|
||||
sb.write_string("]\n :version " + panel_version.to_string() + "}\n")
|
||||
let dir = panel_config_dir()
|
||||
if @sys.mkdir_p(dir) {
|
||||
ignore(@sys.write_file_bytes(dir + "/panel.edn", @utf8.encode(sb.to_string())))
|
||||
}
|
||||
}
|
||||
|
||||
///| The `:version` of the saved panel.edn (1 when it has none).
|
||||
fn saved_panel_version() -> Int {
|
||||
let text = @utf8.decode_lossy(read_config_file("panel.edn"))
|
||||
panel_text_version(text)
|
||||
}
|
||||
|
||||
///|
|
||||
fn panel_text_version(text : String) -> Int {
|
||||
match text.find(":version") {
|
||||
None => 1
|
||||
Some(i) => {
|
||||
let mut v = 0
|
||||
let mut seen = false
|
||||
for j = i + 8; j < text.length(); j = j + 1 {
|
||||
let c = text[j]
|
||||
if c >= '0' && c <= '9' {
|
||||
v = v * 10 + (c.to_int() - '0'.to_int())
|
||||
seen = true
|
||||
} else if seen || (c != ' ' && c != '\t' && c != '\n' && c != '\r' && c != ',') {
|
||||
break
|
||||
}
|
||||
}
|
||||
if seen { v } else { 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "panel.edn version" {
|
||||
assert_eq(panel_text_version("{:panel [\"clock-digital12\"]}"), 1)
|
||||
assert_eq(panel_text_version("{:panel [\"clock-digital\"]\n :version 2}\n"), 2)
|
||||
assert_eq(panel_text_version("{:version 12 :panel []}"), 12)
|
||||
}
|
||||
|
||||
///| The module list saved in panel.edn; None when persistence is off or there is no saved panel.
|
||||
fn DesktopShell::load_panel_config(self : DesktopShell) -> Array[String]? {
|
||||
if !self.persist {
|
||||
|
||||
Reference in new issue
Block a user