Files
chandra/components/clock-digital/gen/interface/chandra/desktop/module-config/ffi.mbt
T
Claude 4fc4a963b4
CI / test (push) Failing after 15s
Module settings in each module's right-click menu, and System settings
- 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
2026-11-25 18:58:43 +00:00

115 lines
3.7 KiB
MoonBit

// 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_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_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_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
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)