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
@@ -50,24 +50,30 @@ pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
|
||||
@plasmoid.wasmExportRender(p0, p1)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportInfoPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportRenderPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopup() -> Int {
|
||||
@plasmoid.wasmExportPopup()
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportConfigItems() -> Int {
|
||||
@module-config.wasmExportConfigItems()
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
@module-config.wasmExportSetConfig(p0, p1, p2, p3)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
||||
@@ -76,7 +82,19 @@ pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
@plasmoid.wasmExportOnEvent(p0, p1, p2, p3)
|
||||
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportInfoPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportConfigItemsPostReturn(p0 : Int) -> Unit {
|
||||
@module-config.wasmExportConfigItemsPostReturn(p0)
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
|
||||
@plasmoid.wasmExportRenderPostReturn(p0)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
Optional: a module's own settings. A module that exports this gets a "Module settings" entry in
|
||||
its right-click menu, listing the items below; the shell draws the menu (the same for every
|
||||
module), remembers each choice per module in state.edn (`:module-config`), and hands the saved
|
||||
values back through `set-config` right after the module is loaded. A module without it simply
|
||||
has no settings: the export is looked up by name, so older modules keep loading.
|
||||
@@ -0,0 +1,114 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportConfigItems() -> Int {
|
||||
|
||||
let (result) : (Array[ConfigItem]) = config_items();
|
||||
let return_area = mbt_ffi_malloc(8)
|
||||
|
||||
let address3 = mbt_ffi_malloc((result).length() * 32);
|
||||
for index4 = 0; index4 < (result).length(); index4 = index4 + 1 {
|
||||
let iter_elem : ConfigItem = (result)[(index4)]
|
||||
let iter_base = address3 + (index4 * 32);
|
||||
|
||||
let ptr = mbt_ffi_str2ptr((iter_elem).key)
|
||||
mbt_ffi_store32((iter_base) + 4, (iter_elem).key.length())
|
||||
mbt_ffi_store32((iter_base) + 0, ptr)
|
||||
|
||||
let ptr0 = mbt_ffi_str2ptr((iter_elem).label)
|
||||
mbt_ffi_store32((iter_base) + 12, (iter_elem).label.length())
|
||||
mbt_ffi_store32((iter_base) + 8, ptr0)
|
||||
|
||||
let address = mbt_ffi_malloc(((iter_elem).choices).length() * 8);
|
||||
for index = 0; index < ((iter_elem).choices).length(); index = index + 1 {
|
||||
let iter_elem : String = ((iter_elem).choices)[(index)]
|
||||
let iter_base = address + (index * 8);
|
||||
|
||||
let ptr1 = mbt_ffi_str2ptr(iter_elem)
|
||||
mbt_ffi_store32((iter_base) + 4, iter_elem.length())
|
||||
mbt_ffi_store32((iter_base) + 0, ptr1)
|
||||
|
||||
}
|
||||
mbt_ffi_store32((iter_base) + 20, ((iter_elem).choices).length())
|
||||
mbt_ffi_store32((iter_base) + 16, address)
|
||||
|
||||
let ptr2 = mbt_ffi_str2ptr((iter_elem).value)
|
||||
mbt_ffi_store32((iter_base) + 28, (iter_elem).value.length())
|
||||
mbt_ffi_store32((iter_base) + 24, ptr2)
|
||||
|
||||
}
|
||||
mbt_ffi_store32((return_area) + 4, (result).length())
|
||||
mbt_ffi_store32((return_area) + 0, address3)
|
||||
let ret = return_area
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportConfigItemsPostReturn(p0 : Int) -> Unit {
|
||||
|
||||
for index0 = 0; index0 < (mbt_ffi_load32((p0) + 4)); index0 = index0 + 1 {
|
||||
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index0 * 32)
|
||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 0))
|
||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 8))
|
||||
|
||||
for index = 0; index < (mbt_ffi_load32((iter_base) + 20)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index * 8)
|
||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 0))
|
||||
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 16))
|
||||
mbt_ffi_free(mbt_ffi_load32((iter_base) + 24))
|
||||
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
#doc(hidden)
|
||||
pub fn wasmExportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
|
||||
let result = mbt_ffi_ptr2str(p0, p1)
|
||||
|
||||
let result0 = mbt_ffi_ptr2str(p2, p3)
|
||||
|
||||
let (result1) : (Bool) = set_config(result, result0);
|
||||
let ret = (if result1 { 1 } else { 0 })
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
///|
|
||||
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_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.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_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)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import {
|
||||
"chandra/desktop/lib/clock" @logic,
|
||||
}
|
||||
|
||||
warnings = "-44"
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "chandra/desktop/components/clock-binary/gen/interface/chandra/desktop/module-config"
|
||||
|
||||
// Values
|
||||
pub fn config_items() -> Array[ConfigItem]
|
||||
|
||||
pub fn set_config(String, String) -> Bool
|
||||
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
pub(all) struct ConfigItem {
|
||||
key : String
|
||||
label : String
|
||||
choices : Array[String]
|
||||
value : String
|
||||
}
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
@@ -0,0 +1,16 @@
|
||||
///| The binary clock's right-click settings (seconds columns); the logic is in lib/clock.
|
||||
|
||||
///|
|
||||
pub fn config_items() -> Array[ConfigItem] {
|
||||
@logic.binary_config.binary_items().map(e => {
|
||||
key: e.key,
|
||||
label: e.label,
|
||||
choices: e.choices,
|
||||
value: e.value,
|
||||
})
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn set_config(key : String, value : String) -> Bool {
|
||||
@logic.binary_config.set(key, value)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
///|
|
||||
pub(all) struct ConfigItem {
|
||||
key : String; label : String; choices : Array[String]; value : String
|
||||
}
|
||||
///|
|
||||
declare pub fn config_items() -> Array[ConfigItem]
|
||||
///|
|
||||
/// Set `key` to `value` (unknown keys and values are ignored). True when the widget should redraw.
|
||||
declare pub fn set_config(key : String, value : String) -> Bool
|
||||
|
||||
@@ -15,7 +15,7 @@ pub fn info() -> PlasmoidInfo {
|
||||
|
||||
///|
|
||||
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
|
||||
@logic.render_binary(size, @theme.get_tokens(), @clock.now())
|
||||
@logic.render_binary(size, @theme.get_tokens(), @clock.now(), seconds=@logic.binary_config.seconds)
|
||||
}
|
||||
|
||||
///|
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
"chandra/desktop/components/clock-binary/gen/interface/chandra/desktop/module-config" @module-config,
|
||||
"chandra/desktop/components/clock-binary/gen/interface/chandra/desktop/plasmoid" @plasmoid,
|
||||
}
|
||||
|
||||
@@ -13,13 +14,16 @@ options(
|
||||
"heap-start-address": 16,
|
||||
"exports": [
|
||||
"mbt_ffi_cabi_realloc:cabi_realloc",
|
||||
"wasmExportConfigItems:chandra:desktop/module-config@0.1.0#config-items",
|
||||
"wasmExportConfigItemsPostReturn:cabi_post_chandra:desktop/module-config@0.1.0#config-items",
|
||||
"wasmExportInfo:chandra:desktop/plasmoid@0.1.0#info",
|
||||
"wasmExportInfoPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#info",
|
||||
"wasmExportOnEvent:chandra:desktop/plasmoid@0.1.0#on-event",
|
||||
"wasmExportPopup:chandra:desktop/plasmoid@0.1.0#popup",
|
||||
"wasmExportPopupPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#popup",
|
||||
"wasmExportRender:chandra:desktop/plasmoid@0.1.0#render",
|
||||
"wasmExportRenderPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#render"
|
||||
"wasmExportRenderPostReturn:cabi_post_chandra:desktop/plasmoid@0.1.0#render",
|
||||
"wasmExportSetConfig:chandra:desktop/module-config@0.1.0#set-config"
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user