diff --git a/compositor/shell/widgets.mbt b/compositor/shell/widgets.mbt index cc32c50..4d1ef62 100644 --- a/compositor/shell/widgets.mbt +++ b/compositor/shell/widgets.mbt @@ -59,6 +59,24 @@ fn stem(path : String) -> String { } } +///| The WIT world ("clock-widget", "taskbar-widget", ...) a module was built for, read from the +/// `.meta.json` that build-modules.sh writes next to it; "" when unknown (a module loaded +/// from elsewhere). Two modules are interchangeable only when their worlds match. +fn module_world(path : String) -> String { + let base = if path.has_suffix(".wasm") { path[:path.length() - 5].to_string() } else { path } + let text = @utf8.decode_lossy(@sys.read_file_bytes(base + ".meta.json")) + match text.find("\"world\":\"") { + None => "" + Some(i) => { + let rest = text[i + 9:].to_string() + match rest.find("\"") { + Some(j) => rest[:j].to_string() + None => "" + } + } + } +} + ///| Find every module file on the search path (earlier directories win on the same name). fn DesktopShell::scan_catalog(self : DesktopShell) -> Unit { self.catalog.clear() @@ -545,8 +563,14 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool Some(w) => { self.name_catalog() let rows : Array[MenuRow] = [] + // Only modules of the same kind (same WIT world) can stand in for this one. + let world = module_world(w.path) for e in self.catalog { - if e.id != w.module_id && e.path != w.path && rows.length() < max_replace_rows { + if world.length() > 0 && + e.id != w.module_id && + e.path != w.path && + rows.length() < max_replace_rows && + module_world(e.path) == world { rows.push({ label: "Replace with " + e.name, kind: 0, arg: e.path }) } }