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
@@ -18,6 +18,12 @@ fn wasmImportPopup(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0" "popup"
|
||||
///|
|
||||
fn wasmImportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int = "chandra:host/plasmoids@0.1.0" "on-event"
|
||||
|
||||
///|
|
||||
fn wasmImportConfigItems(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0" "config-items"
|
||||
|
||||
///|
|
||||
fn wasmImportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int = "chandra:host/plasmoids@0.1.0" "set-config"
|
||||
|
||||
///|
|
||||
fn wasmImportPublishTable(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/plasmoids@0.1.0" "publish-table"
|
||||
|
||||
@@ -51,10 +57,42 @@ fn wasmImportPickerStart() -> Int = "chandra:host/plasmoids@0.1.0" "picker-start
|
||||
///|
|
||||
fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll"
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array16
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
|
||||
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
@@ -63,43 +101,11 @@ extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
|
||||
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array16
|
||||
#| local.get 0)
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
@@ -30,6 +30,16 @@ fn wasmImportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportConfigItems(p0 : Int, p1 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPublishTable(p0 : Int, p1 : Int, p2 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
@@ -86,12 +96,7 @@ fn wasmImportPickerPoll(p0 : Int) -> Unit {
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_malloc(size : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
@@ -110,18 +115,18 @@ fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load64(offset : Int) -> Int64 {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_store32(offset : Int, value : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load32(offset : Int) -> Int {
|
||||
fn mbt_ffi_malloc(size : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
@@ -131,11 +136,16 @@ fn mbt_ffi_load8_u(offset : Int) -> Int {
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
|
||||
fn mbt_ffi_store32(offset : Int, value : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit {
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load32(offset : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
}
|
||||
|
||||
// Values
|
||||
pub fn config_items(UInt32) -> Array[ConfigItem]
|
||||
|
||||
pub fn list_wasm_files(String) -> Array[String]
|
||||
|
||||
pub fn load(String) -> Result[Loaded, String]
|
||||
@@ -35,6 +37,8 @@ pub fn publish_windows(Array[WindowEntry]) -> Unit
|
||||
|
||||
pub fn render(UInt32, @types.Size) -> Array[@types.DrawOp]
|
||||
|
||||
pub fn set_config(UInt32, String, String) -> Bool
|
||||
|
||||
pub fn set_tokens(@theme.Tokens) -> Unit
|
||||
|
||||
pub fn take_focus_request() -> UInt64?
|
||||
@@ -44,6 +48,13 @@ pub fn unload(UInt32) -> Unit
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
pub(all) struct ConfigItem {
|
||||
key : String
|
||||
label : String
|
||||
choices : Array[String]
|
||||
value : String
|
||||
}
|
||||
|
||||
pub(all) struct Loaded {
|
||||
handle : UInt32
|
||||
id : String
|
||||
|
||||
@@ -10,6 +10,12 @@ pub(all) struct PopupSurface {
|
||||
box : @types.Size; ops : Array[@types.DrawOp]
|
||||
}
|
||||
///|
|
||||
/// One of a module's own settings (chandra:desktop/module-config `config-item`): `choices`
|
||||
/// empty means an on/off switch whose value is "on" or "off".
|
||||
pub(all) struct ConfigItem {
|
||||
key : String; label : String; choices : Array[String]; value : String
|
||||
}
|
||||
///|
|
||||
pub(all) struct SystemSnapshot {
|
||||
cpu_permille : UInt; mem_used_kib : UInt64; mem_total_kib : UInt64; battery_percent : Int; charging : Bool; uptime_secs : UInt64; net_rx_bytes_per_sec : UInt64; net_tx_bytes_per_sec : UInt64; load_centi : UInt
|
||||
}
|
||||
@@ -309,6 +315,55 @@ pub fn on_event(handle : UInt, on_popup : Bool, event : @types.InputEvent) -> Bo
|
||||
cleanup_list.each(mbt_ffi_free)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// The module's settings for its right-click menu; empty when it doesn't export module-config.
|
||||
pub fn config_items(handle : UInt) -> Array[ConfigItem] {
|
||||
|
||||
let return_area = mbt_ffi_malloc(8)
|
||||
wasmImportConfigItems((handle).reinterpret_as_int(), return_area);
|
||||
|
||||
let array3 : Array[ConfigItem] = [];
|
||||
for index4 = 0; index4 < (mbt_ffi_load32((return_area) + 4)); index4 = index4 + 1 {
|
||||
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index4 * 32)
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
|
||||
|
||||
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
|
||||
|
||||
let array : Array[String] = [];
|
||||
for index = 0; index < (mbt_ffi_load32((iter_base) + 20)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index * 8)
|
||||
|
||||
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
|
||||
|
||||
array.push(result1)
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 16))
|
||||
|
||||
let result2 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 24), mbt_ffi_load32((iter_base) + 28))
|
||||
|
||||
array3.push(ConfigItem::{key : result, label : result0, choices : array, value : result2})
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||
let ret = array3
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// Set one of them. True when the module wants a redraw (false without module-config).
|
||||
pub fn set_config(handle : UInt, key : String, value : String) -> Bool {
|
||||
|
||||
let ptr = mbt_ffi_str2ptr(key)
|
||||
|
||||
let ptr0 = mbt_ffi_str2ptr(value)
|
||||
let result : Int = wasmImportSetConfig((handle).reinterpret_as_int(), ptr, key.length(), ptr0, value.length());
|
||||
let ret = (result != 0)
|
||||
mbt_ffi_free(ptr)
|
||||
mbt_ffi_free(ptr0)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// ---- host data modules read through their capabilities ----
|
||||
|
||||
Reference in new issue
Block a user