feat(status-ui): improve bridge recovery and desktop controls
This commit is contained in:
@@ -16,16 +16,58 @@ local function socket_path()
|
||||
return runtime .. "/pi-status-bridge/bridge.sock"
|
||||
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 "
|
||||
.. binary .. " --toggle >/tmp/pi-status-ui.log 2>&1; else exit 1; fi"
|
||||
noctalia.runAsync(command, function(result)
|
||||
if result.exitCode ~= 0 then
|
||||
barWidget.setGlyph("alert-triangle")
|
||||
barWidget.setText("Pi UI unavailable")
|
||||
barWidget.setTooltip("Build Pi Status UI or set PI_STATUS_UI_BINARY")
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function start_bridge(open_after_start)
|
||||
if open_after_start then pending_ui_open = true end
|
||||
if bridge_start_in_flight then return end
|
||||
bridge_start_in_flight = true
|
||||
barWidget.setGlyph("terminal-2")
|
||||
barWidget.setText("Pi starting")
|
||||
barWidget.setTooltip("Bridge is starting")
|
||||
noctalia.runAsync("systemctl --user start pi-status-bridge.service", function(result)
|
||||
bridge_start_in_flight = false
|
||||
if result.exitCode ~= 0 then
|
||||
pending_ui_open = false
|
||||
barWidget.setGlyph("alert-triangle")
|
||||
barWidget.setText("Pi offline")
|
||||
barWidget.setTooltip("Could not start pi-status-bridge.service")
|
||||
return
|
||||
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 return end
|
||||
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
|
||||
@@ -42,9 +84,7 @@ function update()
|
||||
local agent_id = current_agent_id()
|
||||
local socket = socket_path()
|
||||
if socket == nil then
|
||||
barWidget.setGlyph("alert-triangle")
|
||||
barWidget.setText("Pi offline")
|
||||
barWidget.setTooltip("Bridge socket is unavailable")
|
||||
start_bridge(false)
|
||||
return
|
||||
end
|
||||
if agent_id == nil then
|
||||
@@ -63,7 +103,7 @@ function update()
|
||||
request_in_flight = false
|
||||
if result.exitCode ~= 0 then
|
||||
noctalia.state.set("agent_id", nil)
|
||||
discover_home_agent(socket)
|
||||
start_bridge(false)
|
||||
barWidget.setGlyph("terminal-2")
|
||||
barWidget.setText("Pi reconnecting")
|
||||
barWidget.setTooltip("Refreshing the Home Pi agent")
|
||||
@@ -77,13 +117,5 @@ function update()
|
||||
end
|
||||
|
||||
function onClick()
|
||||
local command = "setsid -f env TMPDIR=/tmp " .. shell_quote(ui_binary())
|
||||
.. " --show >/tmp/pi-status-ui.log 2>&1"
|
||||
noctalia.runAsync(command, function(result)
|
||||
if result.exitCode ~= 0 then
|
||||
barWidget.setGlyph("alert-triangle")
|
||||
barWidget.setText("Pi UI unavailable")
|
||||
barWidget.setTooltip("Build Pi Status UI or set PI_STATUS_UI_BINARY")
|
||||
end
|
||||
end)
|
||||
start_bridge(true)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user