feat: add multi-session desktop workspace
This commit is contained in:
@@ -10,6 +10,12 @@ local function ui_binary()
|
||||
return (noctalia.getenv("HOME") or "") .. "/projects/pi-status-bridge/ui/src-tauri/target/release/pi-status-ui"
|
||||
end
|
||||
|
||||
local function bridge_client_binary()
|
||||
local configured = noctalia.getenv("PI_STATUS_BRIDGE_CLIENT")
|
||||
if configured ~= nil and configured ~= "" then return shell_quote(configured) end
|
||||
return "pi-status-bridge-client"
|
||||
end
|
||||
|
||||
local function socket_path()
|
||||
local runtime = noctalia.getenv("XDG_RUNTIME_DIR")
|
||||
if runtime == nil or runtime == "" then return nil end
|
||||
@@ -19,10 +25,6 @@ end
|
||||
local bridge_start_in_flight = false
|
||||
local pending_ui_open = false
|
||||
|
||||
local function current_agent_id()
|
||||
return noctalia.state.get("agent_id")
|
||||
end
|
||||
|
||||
local function open_ui()
|
||||
local binary = shell_quote(ui_binary())
|
||||
local command = "if test -x " .. binary .. "; then setsid -f env TMPDIR=/tmp "
|
||||
@@ -52,67 +54,46 @@ local function start_bridge(open_after_start)
|
||||
barWidget.setTooltip("Could not start pi-status-bridge.service")
|
||||
return
|
||||
end
|
||||
if pending_ui_open then
|
||||
pending_ui_open = false
|
||||
open_ui()
|
||||
end
|
||||
if pending_ui_open then pending_ui_open = false; open_ui() end
|
||||
end)
|
||||
end
|
||||
|
||||
local function discover_home_agent(socket)
|
||||
if request_in_flight then return end
|
||||
request_in_flight = true
|
||||
noctalia.runAsync("pi-status-bridge-client --socket \"" .. socket .. "\" request '{\"op\":\"list_agents\"}'", function(result)
|
||||
request_in_flight = false
|
||||
if result.exitCode ~= 0 then
|
||||
start_bridge(false)
|
||||
return
|
||||
end
|
||||
local home = noctalia.getenv("HOME")
|
||||
for id, worktree in string.gmatch(result.stdout, "\"id\":\"([^\"]+)\",\"worktreePath\":\"([^\"]+)\"") do
|
||||
if worktree == home then
|
||||
noctalia.state.set("agent_id", id)
|
||||
noctalia.state.set("project_path", worktree)
|
||||
return
|
||||
end
|
||||
end
|
||||
end)
|
||||
local function json_count(payload, key)
|
||||
local value = string.match(payload, '"' .. key .. '":(%d+)')
|
||||
return tonumber(value) or 0
|
||||
end
|
||||
|
||||
local function update_summary(payload)
|
||||
local open = json_count(payload, "openCount")
|
||||
local working = json_count(payload, "workingCount")
|
||||
local attention = json_count(payload, "attentionCount")
|
||||
local recovering = json_count(payload, "recoveringCount")
|
||||
local errors = json_count(payload, "errorCount")
|
||||
local glyph = errors > 0 and "alert-triangle" or attention > 0 and "circle-alert" or working > 0 and "terminal-2" or recovering > 0 and "refresh-cw" or "terminal"
|
||||
local text = errors > 0 and "Pi needs attention" or working > 0 and "Pi working" or recovering > 0 and "Pi recovering" or "Pi ready"
|
||||
local detail = open .. " open · " .. working .. " working · " .. attention .. " attention · " .. recovering .. " recovering · " .. errors .. " errors"
|
||||
barWidget.setGlyph(glyph)
|
||||
barWidget.setText(text)
|
||||
barWidget.setTooltip(detail .. "; click to open Pi Status UI")
|
||||
end
|
||||
|
||||
function update()
|
||||
noctalia.setUpdateInterval(2000)
|
||||
local agent_id = current_agent_id()
|
||||
local socket = socket_path()
|
||||
if socket == nil then
|
||||
start_bridge(false)
|
||||
return
|
||||
end
|
||||
if agent_id == nil then
|
||||
discover_home_agent(socket)
|
||||
barWidget.setGlyph("terminal-2")
|
||||
barWidget.setText("Pi home")
|
||||
barWidget.setTooltip("Starting the default Home agent; click to open Pi Status UI")
|
||||
return
|
||||
end
|
||||
if socket == nil then start_bridge(false); return end
|
||||
if request_in_flight then return end
|
||||
|
||||
request_in_flight = true
|
||||
local command = "pi-status-bridge-client --socket \"" .. socket
|
||||
.. "\" request '{\"op\":\"get_state\",\"agentId\":\"" .. agent_id .. "\"}'"
|
||||
local command = bridge_client_binary() .. " --socket \"" .. socket .. "\" request '{\"op\":\"get_workspace_summary\"}'"
|
||||
noctalia.runAsync(command, function(result)
|
||||
request_in_flight = false
|
||||
if result.exitCode ~= 0 then
|
||||
noctalia.state.set("agent_id", nil)
|
||||
start_bridge(false)
|
||||
barWidget.setGlyph("terminal-2")
|
||||
barWidget.setText("Pi reconnecting")
|
||||
barWidget.setTooltip("Refreshing the Home Pi agent")
|
||||
barWidget.setTooltip("Refreshing Pi workspace summary")
|
||||
return
|
||||
end
|
||||
local streaming = string.find(result.stdout, "\"isStreaming\":true", 1, true) ~= nil
|
||||
barWidget.setGlyph(streaming and "terminal-2" or "terminal")
|
||||
barWidget.setText(streaming and "Pi working" or "Pi ready")
|
||||
barWidget.setTooltip(noctalia.state.get("project_path") or "Selected Pi folder")
|
||||
update_summary(result.stdout)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user