Launcher: Reload session, and Log out moves in from its own module
CI / test (push) Failing after 17s

The Application Launcher's menu now ends in a session row: Reload, Log out, Suspend, Restart,
Power off. Log out, Restart and Power off take a second click on the same button (a status line
says "Click Log out again to confirm"); Reload and Suspend act at once.

- Reload calls the new session.reload, which reaches the shell as the ReloadSession request
  (native stub: request 8 with n 1; host plasmoids.wit: reload-session; host-wasm: Req::ReloadSession)
  and runs DesktopShell::reload_modules(""): every panel module again from disk, in place, with
  its settings. Windows and apps keep running. The compositor redraws the whole frame after it.
- Suspend / Restart / Power off use the power capability, the same calls as Settings > Power.
- The standalone logout module is gone (component, world, components.txt). Saved panels drop
  "logout", or get the launcher in its place when they had none; panel.edn is rewritten without
  it. A stale logout.wasm is hidden from Settings > Panel (retired_modules).
- Tests: lib/launcher session row, shell migrate_panel, host input tests for Log out and Reload,
  host-wasm launcher session row; control_test uses inspector.wasm instead of logout.wasm.
- README and docs/reloading.md describe the session row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjKUnSS3D92ThigvJf
This commit is contained in:
Claude committed 2026-11-25 21:01:17 +00:00
1 parent 68164ff75e
commit 99c6c66726
37 files changed
+420 -827

No files matched your search

+215 -8
View File
@@ -1,5 +1,10 @@
///| Kickoff-style application launcher: state machine + render logic. Pure;
/// host capabilities (app list, launch) are passed in by the component stub.
/// host capabilities (app list, launch, session and power actions) are passed in by the
/// component stub.
///
/// The popup ends in a session row: Reload (reload the session's modules from disk), Log out,
/// Suspend, Restart and Power off. Log out, Restart and Power off take a second click on the same
/// button, like the Settings Power tab; Reload and Suspend act at once.
///| Which surface an event is addressed to (mirrors the WIT `surface` enum).
pub(all) enum Target {
@@ -13,11 +18,45 @@ pub struct State {
mut query : String
mut hover : Int
mut error : String
/// Session button under the pointer (-1: none).
mut hover_action : Int
/// Session button waiting for its confirming second click (-1: none).
mut armed : Int
}
///|
pub fn State::new() -> State {
{ open: false, query: "", hover: -1, error: "" }
{ open: false, query: "", hover: -1, error: "", hover_action: -1, armed: -1 }
}
///| The session row's buttons, in order. `handle_event`'s `session` callback gets the index.
pub let session_actions : Array[String] = [
"Reload", "Log out", "Suspend", "Restart", "Power off",
]
///| Index of each session action.
pub let action_reload : Int = 0
///|
pub let action_logout : Int = 1
///|
pub let action_suspend : Int = 2
///|
pub let action_restart : Int = 3
///|
pub let action_power_off : Int = 4
///| Whether an action ends or interrupts the session and so takes a second click.
pub fn needs_confirm(action : Int) -> Bool {
action == action_logout || action == action_restart || action == action_power_off
}
///| What the status line says while `action` is armed.
fn confirm_hint(action : Int) -> String {
"Click " + session_actions[action] + " again to confirm"
}
///|
@@ -32,6 +71,19 @@ let row_h : Int = 46
///|
let max_rows : Int = 8
///| The session row at the bottom of the popup, and the status line above it (shown only when
/// there is something to say: a launch error, or which button is waiting to be confirmed).
let footer_h : Int = 44
///|
let status_h : Int = 22
///|
let footer_margin : Int = 8
///|
let button_gap : Int = 4
///|
fn ascii_lower(s : String) -> String {
let sb = StringBuilder()
@@ -75,7 +127,43 @@ fn visible_rows(n : Int) -> Int {
pub fn popup_size(apps : Array[@types.AppEntry], st : State) -> @types.Size {
let rows = visible_rows(filter(apps, st.query).length())
let rows = if rows == 0 { 1 } else { rows }
@ui.size(popup_w, header_h + rows * row_h + 8)
let status = if status_text(st) == "" { 0 } else { status_h }
@ui.size(popup_w, header_h + rows * row_h + 8 + status + footer_h)
}
///| The status line's text: the launch error, else the confirm hint, else "".
fn status_text(st : State) -> String {
if st.error.length() > 0 {
st.error
} else if st.armed >= 0 {
confirm_hint(st.armed)
} else {
""
}
}
///| Width of each session button.
fn button_w() -> Int {
let n = session_actions.length()
(popup_w - 2 * footer_margin - (n - 1) * button_gap) / n
}
///| Popup-local rectangle (x, y, w, h) of session button `i` in a popup of height `h`.
fn button_rect(i : Int, h : Int) -> (Int, Int, Int, Int) {
let bw = button_w()
(footer_margin + i * (bw + button_gap), h - footer_h + 6, bw, footer_h - 14)
}
///| Session button under a popup-local point, or -1.
pub fn action_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> Int {
let h = popup_size(apps, st).h.reinterpret_as_int()
for i = 0; i < session_actions.length(); i = i + 1 {
let (x, y, w, bh) = button_rect(i, h)
if p.x >= x && p.x < x + w && p.y >= y && p.y < y + bh {
return i
}
}
-1
}
///|
@@ -83,6 +171,8 @@ pub fn close(st : State) -> Unit {
st.open = false
st.query = ""
st.hover = -1
st.hover_action = -1
st.armed = -1
}
///| The panel button: a crescent moon plus a label.
@@ -150,8 +240,30 @@ pub fn render_popup(
ops.push(@ui.text(56, y + 14, a.name, fs, fg, bold=true))
ops.push(@ui.text(56, y + 31, a.comment, fs - 3, sub))
}
if st.error.length() > 0 {
ops.push(@ui.text(14, h - 12, st.error, fs - 3, @ui.color(240, 90, 90, 255)))
let status = status_text(st)
if status != "" {
let color = if st.error.length() > 0 { @ui.color(240, 90, 90, 255) } else { p.accent }
ops.push(@ui.text(14, h - footer_h - status_h / 2, status, fs - 3, color, bold=st.error == ""))
}
// The session row, under a divider.
ops.push(@ui.fill_rect(@ui.rect(footer_margin, h - footer_h, w - 2 * footer_margin, 1), p.border))
for i = 0; i < session_actions.length(); i = i + 1 {
let (bx, by, bw, bh) = button_rect(i, h)
let armed = st.armed == i
let hot = st.hover_action == i
if armed {
ops.push(@ui.fill_rect(@ui.rect(bx, by, bw, bh), p.accent, radius=r))
} else if hot {
ops.push(@ui.fill_rect(@ui.rect(bx, by, bw, bh), p.surface_hover, radius=r))
}
let fg = if armed {
p.accent_foreground
} else if hot {
p.foreground
} else {
p.foreground_muted
}
ops.push(@ui.text(bx + bw / 2, by + bh / 2, session_actions[i], fs - 3, fg, align=CENTER, bold=armed))
}
ops
}
@@ -165,13 +277,15 @@ pub fn row_at(apps : Array[@types.AppEntry], st : State, p : @types.Point) -> In
if i < visible_rows(filter(apps, st.query).length()) { i } else { -1 }
}
///| Handle an event. `launch` is the host capability. Returns true on redraw.
///| Handle an event. `launch` is the host capability; `session` carries out a session-row action
/// (an index into `session_actions`) once it is confirmed. Returns true on redraw.
pub fn handle_event(
apps : Array[@types.AppEntry],
st : State,
target : Target,
ev : @types.InputEvent,
launch : (String) -> Result[Unit, String],
session~ : (Int) -> Unit = _ => (),
) -> Bool {
match (target, ev) {
(Widget, PointerDown(_)) => {
@@ -185,21 +299,30 @@ pub fn handle_event(
}
(Popup, PointerMove(p)) => {
let i = row_at(apps, st, p)
if i != st.hover {
let a = action_at(apps, st, p)
if i != st.hover || a != st.hover_action {
st.hover = i
st.hover_action = a
true
} else {
false
}
}
(Popup, PointerLeave) =>
if st.hover != -1 {
if st.hover != -1 || st.hover_action != -1 {
st.hover = -1
st.hover_action = -1
true
} else {
false
}
(Popup, PointerDown(p)) => {
let a = action_at(apps, st, p)
if a >= 0 {
session_click(st, a, session)
return true
}
st.armed = -1
let i = row_at(apps, st, p)
if i >= 0 {
activate(apps, st, i, launch)
@@ -241,6 +364,17 @@ pub fn handle_event(
}
}
///| A click on session button `a`: act now, or arm it and act on a second click.
fn session_click(st : State, a : Int, session : (Int) -> Unit) -> Unit {
if needs_confirm(a) && st.armed != a {
st.armed = a
st.error = ""
return
}
close(st)
session(a)
}
///| Launch the i-th filtered app; a failure is shown in the popup (not hidden).
fn activate(
apps : Array[@types.AppEntry],
@@ -332,3 +466,76 @@ test "search matches the app id and ranks name matches first" {
let r = filter(apps, "kate")
assert_eq(r.map(a => a.id), ["x.pad", "org.kde.kate"])
}
///| Popup-local centre of session button `a` for the apps and state given.
fn button_centre(apps : Array[@types.AppEntry], st : State, a : Int) -> @types.Point {
let h = popup_size(apps, st).h.reinterpret_as_int()
let (x, y, w, bh) = button_rect(a, h)
{ x: x + w / 2, y: y + bh / 2 }
}
///|
test "session row: Reload and Suspend act at once, closing the menu" {
let apps = sample_apps()
let st = State::new()
st.open = true
let done : Array[Int] = []
let p = button_centre(apps, st, action_reload)
assert_eq(action_at(apps, st, p), action_reload)
assert_true(handle_event(apps, st, Popup, PointerDown(p), _ => Ok(()), session=a => done.push(a)))
assert_eq(done, [action_reload])
assert_false(st.open)
st.open = true
let p = button_centre(apps, st, action_suspend)
let _ = handle_event(apps, st, Popup, PointerDown(p), _ => Ok(()), session=a => done.push(a))
assert_eq(done, [action_reload, action_suspend])
}
///|
test "session row: Log out, Restart and Power off take a second click" {
let apps = sample_apps()
let st = State::new()
st.open = true
let done : Array[Int] = []
let session = a => done.push(a)
let click = a => {
let p = button_centre(apps, st, a)
ignore(handle_event(apps, st, Popup, PointerDown(p), _ => Ok(()), session~))
}
click(action_logout)
assert_eq(done, [])
assert_eq(st.armed, action_logout)
assert_true(st.open)
// The popup grew a status line; the hint names the button.
assert_eq(status_text(st), "Click Log out again to confirm")
// Another armed button takes over; nothing runs.
click(action_power_off)
assert_eq(st.armed, action_power_off)
assert_eq(done, [])
click(action_power_off)
assert_eq(done, [action_power_off])
assert_false(st.open)
assert_eq(st.armed, -1)
// Closing the menu disarms: reopening and clicking once does nothing yet.
st.open = true
click(action_restart)
ignore(handle_event(apps, st, Widget, FocusLost, _ => Ok(()), session~))
st.open = true
click(action_restart)
assert_eq(done, [action_power_off])
click(action_restart)
assert_eq(done, [action_power_off, action_restart])
}
///|
test "session row: a click on an app disarms, and app rows don't reach the row" {
let apps = sample_apps()
let st = State::new()
st.open = true
let p = button_centre(apps, st, action_logout)
assert_eq(row_at(apps, st, p), -1)
ignore(handle_event(apps, st, Popup, PointerDown(p), _ => Ok(())))
assert_eq(st.armed, action_logout)
ignore(handle_event(apps, st, Popup, PointerDown({ x: 20, y: 60 }), _ => Ok(())))
assert_eq(st.armed, -1)
}