dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
files/noctalia/keyhelp/controller.luau (1359B)
1local model = require("./lib/model.luau")
2local controller = require("./lib/controller.luau")
3local panelId = "maydayv7/keyhelp:panel"
4
5local function detect(compositor, done)
6 local argv
7 if compositor == "hyprland" then
8 argv = { noctalia.getConfig("hyprctl_path"), "-j", "activewindow" }
9 else
10 argv = { noctalia.getConfig("niri_path"), "msg", "--json", "focused-window" }
11 end
12 local accepted = noctalia.runAsync(argv, function(result)
13 if result.exitCode ~= 0 or result.timedOut or result.stdoutTruncated then
14 noctalia.log("Keyhelp: focused application unavailable; using Desktop")
15 done({})
16 return
17 end
18 local window = noctalia.json.decode(result.stdout)
19 done(model.appIds(compositor, window))
20 end)
21 if not accepted then
22 done({})
23 end
24end
25
26local control = controller.new({
27 detect = detect,
28 open = function(context)
29 noctalia.state.set("context", context)
30 noctalia.togglePanel(panelId)
31 end,
32 close = function()
33 noctalia.togglePanel(panelId)
34 end,
35}, noctalia.state.get("panel_open") == true)
36
37noctalia.state.watch("panel_open", function(open)
38 control.lifecycle(open == true)
39end)
40
41function onIpc(event, payload)
42 if event == "toggle" and not control.toggle(payload) then
43 noctalia.log("Keyhelp: toggle requires hyprland or niri")
44 end
45end
46
47function onExit()
48 control.stop()
49end