Reload panel modules from outside the session: control socket, chandra-ctl, SIGUSR1
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
Until now a module reload was only reachable by clicking Settings > Panel inside the session. Now: - The compositor listens on $XDG_RUNTIME_DIR/chandra/<wayland socket name>.sock (the login session's is wayland-moon-0.sock) with a line protocol: ping, list, reload [NAME], help. Replies end with an "ok ..." or "error ..." line. It lives in compositor/host/control.mbt, runs from ChandraCompositor::step, and its fds join the idle loop's wait set, so an idle desktop still sleeps (measured ~0.4% CPU on wasmhost, ~0.1% on host-wasm) and wakes for a command. A path another live compositor answers on is left alone. - DesktopShell::reload_modules(name) reloads every loaded module (or those whose module id, stem, slot or path is NAME) in place via replace_slot: same panel position, saved :module-config applied, a module that fails to load stays as it was and the error is reported to the caller and shown as a notice. The catalog is rescanned. - SIGUSR1 to the host reloads every module (result in the log and the notice): new WIT function sys.take-sigusr1, implemented in compositor/sys (native build and wasmhost) and host-wasm; the handler has no SA_RESTART so it interrupts the idle poll. - session/chandra-ctl (installed to /usr/local/bin), `just reload [NAME]`, docs/reloading.md, README. - Tests: compositor/host/control_test.mbt (protocol, reload all / by name / by slot, order and settings kept, failing module kept, busy socket). Checked headless on both hosts with chandra-ctl and kill -USR1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjLJtvYcgW48okL6qQ
This commit is contained in:
21 files changed
+844
-31
No files matched your search
@@ -288,11 +288,19 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
///| Load the module file at `path` into the panel (any number of instances may be loaded).
|
||||
/// None, with a notice, when it is not a plasmoid or the panel has no room for it.
|
||||
pub fn DesktopShell::load_path(self : DesktopShell, path : String) -> Widget? {
|
||||
match @wasm.load(path, self.tokens) {
|
||||
match self.try_load_path(path) {
|
||||
Ok(w) => Some(w)
|
||||
Err(e) => {
|
||||
self.say("Can't load module: " + e)
|
||||
self.say(e)
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| `load_path` without the notice: the widget, or why it could not be loaded.
|
||||
fn DesktopShell::try_load_path(self : DesktopShell, path : String) -> Result[Widget, String] {
|
||||
match @wasm.load(path, self.tokens) {
|
||||
Err(e) => Err("Can't load module: " + e)
|
||||
Ok(pl) => {
|
||||
let id = stem(path)
|
||||
let known = match self.find_module(id) {
|
||||
@@ -320,10 +328,9 @@ pub fn DesktopShell::load_path(self : DesktopShell, path : String) -> Widget? {
|
||||
if self.screen_w > 0 && !self.panel_fits() {
|
||||
self.widgets.retain(x => x.slot != w.slot)
|
||||
pl.unload()
|
||||
self.say("No room in the panel for " + pl.name)
|
||||
None
|
||||
Err("No room in the panel for " + pl.name)
|
||||
} else {
|
||||
Some(w)
|
||||
Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,6 +400,20 @@ pub fn DesktopShell::move_slot(self : DesktopShell, slot : String, delta : Int)
|
||||
|
||||
///| Replace the module in `slot` with the module file at `path`, keeping its place in the panel.
|
||||
pub fn DesktopShell::replace_slot(self : DesktopShell, slot : String, path : String) -> Bool {
|
||||
match self.replace_slot_result(slot, path) {
|
||||
Ok(_) => true
|
||||
Err(e) => {
|
||||
if e != "" {
|
||||
self.say(e)
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| `replace_slot` without the notice: the new widget, or why not ("" when there is no `slot`).
|
||||
/// On failure the old module stays loaded where it was.
|
||||
fn DesktopShell::replace_slot_result(self : DesktopShell, slot : String, path : String) -> Result[Widget, String] {
|
||||
let mut idx = -1
|
||||
for i = 0; i < self.widgets.length(); i = i + 1 {
|
||||
if self.widgets[i].slot == slot {
|
||||
@@ -400,26 +421,90 @@ pub fn DesktopShell::replace_slot(self : DesktopShell, slot : String, path : Str
|
||||
}
|
||||
}
|
||||
if idx < 0 {
|
||||
return false
|
||||
return Err("")
|
||||
}
|
||||
let old = self.widgets[idx]
|
||||
self.widgets.remove(idx) |> ignore
|
||||
match self.load_path(path) {
|
||||
None => {
|
||||
match self.try_load_path(path) {
|
||||
Err(e) => {
|
||||
self.widgets.insert(idx, old)
|
||||
false
|
||||
Err(e)
|
||||
}
|
||||
Some(nw) => {
|
||||
// load_path appended it; move it into the old module's place, then drop the old one.
|
||||
Ok(nw) => {
|
||||
// try_load_path appended it; move it into the old module's place, then drop the old one.
|
||||
self.widgets.retain(x => x.slot != nw.slot)
|
||||
self.widgets.insert(idx, nw)
|
||||
if self.drag_slot == slot {
|
||||
self.drag_slot = ""
|
||||
self.drag_active = false
|
||||
}
|
||||
old.pl.unload()
|
||||
self.save_panel_config()
|
||||
true
|
||||
Ok(nw)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Reload panel modules from disk (after `just install-session` or a module rebuild): each
|
||||
/// loaded module whose module id, file stem, slot or path is `name` (every module when `name` is
|
||||
/// empty) is loaded again from its path and takes the old instance's place in the panel. Its
|
||||
/// settings (state.edn `:module-config`) are applied to the new instance as at login. A module
|
||||
/// that fails to load stays as it was. Returns one line per module ("reloaded w3 clock-digital"
|
||||
/// or "failed w3 clock-digital: why") and whether all of them reloaded; with no module matching
|
||||
/// `name`, a single "no module ..." line and false.
|
||||
pub fn DesktopShell::reload_modules(self : DesktopShell, name : String) -> (Array[String], Bool) {
|
||||
self.ensure_booted()
|
||||
self.scan_catalog() // a module installed since login shows up in Settings > Panel
|
||||
let targets : Array[(String, String, String)] = []
|
||||
for w in self.widgets {
|
||||
if name == "" || w.module_id == name || stem(w.path) == name || w.slot == name || w.path == name {
|
||||
targets.push((w.slot, w.module_id, w.path))
|
||||
}
|
||||
}
|
||||
if targets.length() == 0 {
|
||||
let msg = if name == "" {
|
||||
"no modules are loaded"
|
||||
} else {
|
||||
"no loaded module named '" + name + "'"
|
||||
}
|
||||
return ([msg], false)
|
||||
}
|
||||
let lines : Array[String] = []
|
||||
let mut failed = 0
|
||||
let mut last_err = ""
|
||||
for t in targets {
|
||||
let (slot, id, path) = t
|
||||
match self.replace_slot_result(slot, path) {
|
||||
Ok(nw) => lines.push("reloaded " + nw.slot + " " + id)
|
||||
Err(e) => {
|
||||
failed = failed + 1
|
||||
last_err = id + ": " + (if e == "" { "unloaded meanwhile" } else { e })
|
||||
lines.push("failed " + slot + " " + id + ": " + (if e == "" { "unloaded meanwhile" } else { e }))
|
||||
}
|
||||
}
|
||||
}
|
||||
if failed == 0 {
|
||||
self.say(if targets.length() == 1 {
|
||||
"Reloaded " + targets[0].1
|
||||
} else {
|
||||
"Reloaded " + targets.length().to_string() + " modules"
|
||||
})
|
||||
} else if failed == 1 {
|
||||
self.say("Reload failed: " + last_err)
|
||||
} else {
|
||||
self.say(
|
||||
"Reload: " + failed.to_string() + " of " + targets.length().to_string() + " modules failed (chandra-ctl reload shows why)",
|
||||
)
|
||||
}
|
||||
(lines, failed == 0)
|
||||
}
|
||||
|
||||
///| The loaded modules in panel order: (slot, module id, path).
|
||||
pub fn DesktopShell::loaded_modules(self : DesktopShell) -> Array[(String, String, String)] {
|
||||
self.ensure_booted()
|
||||
self.widgets.map(w => (w.slot, w.module_id, w.path))
|
||||
}
|
||||
|
||||
///| Unload every module (the compositor is closing).
|
||||
pub fn DesktopShell::shutdown(self : DesktopShell) -> Unit {
|
||||
for w in self.widgets {
|
||||
|
||||
Reference in new issue
Block a user