mirror of
https://github.com/DeeJanuz/frametop.git
synced 2026-10-06 06:00:09 +02:00
Remote Access: check the status every 5 s instead of every 2 s
While its window was open, Frametop Remote Access ran remote-ctl.sh status every 2 s, and each run spawns bash, curl (the tailnet name from tailscaled) and python3 to parse it. It now checks every 5 s, plus when the window comes to the front and once more 2 s after turning remote access on or off or changing the password, so a change still shows within a couple of seconds. A check doesn't start while one is still running. Doing the check in-process would duplicate remote-ctl.sh's idea of "running", which the session and the pause code share. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
57617d4a14
commit
6cae2e0afe
1 file changed
+17
-5
@@ -83,6 +83,7 @@ class Window(Adw.ApplicationWindow):
|
||||
self.status = {}
|
||||
self.revealed = False
|
||||
self.setting = False # the switch is being set from the status, not by the user
|
||||
self.asking = False # a status check is running
|
||||
|
||||
self.toasts = Adw.ToastOverlay()
|
||||
view = Adw.ToolbarView()
|
||||
@@ -139,16 +140,27 @@ class Window(Adw.ApplicationWindow):
|
||||
"/tmp/frametop-remote.log and /tmp/frametop-vnc.log.")
|
||||
page.add(about)
|
||||
|
||||
# Each check runs remote-ctl.sh (bash, curl, and python3 for the tailnet name), so
|
||||
# it runs every 5 seconds, when the window comes to the front, and after a change.
|
||||
self.refresh()
|
||||
GLib.timeout_add_seconds(2, self.refresh)
|
||||
GLib.timeout_add_seconds(5, self.refresh)
|
||||
self.connect("notify::is-active", lambda win, _param: win.is_active() and win.refresh())
|
||||
|
||||
# --- status ---
|
||||
def refresh(self):
|
||||
proc = Gio.Subprocess.new([CTL, "status"], Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_SILENCE)
|
||||
proc.communicate_utf8_async(None, None, self.on_status)
|
||||
if not self.asking:
|
||||
self.asking = True
|
||||
proc = Gio.Subprocess.new([CTL, "status"], Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_SILENCE)
|
||||
proc.communicate_utf8_async(None, None, self.on_status)
|
||||
return True
|
||||
|
||||
def refresh_soon(self):
|
||||
"""Again in a moment: remote access takes a second or two to start or stop."""
|
||||
self.refresh()
|
||||
GLib.timeout_add_seconds(2, lambda: self.refresh() and False)
|
||||
|
||||
def on_status(self, proc, result):
|
||||
self.asking = False
|
||||
try:
|
||||
_, out, _ = proc.communicate_utf8_finish(result)
|
||||
except GLib.Error:
|
||||
@@ -197,7 +209,7 @@ class Window(Adw.ApplicationWindow):
|
||||
self.toast("Remote access turns on at the next desktop restart")
|
||||
else:
|
||||
self.toast("Remote access on")
|
||||
self.refresh()
|
||||
self.refresh_soon()
|
||||
|
||||
def on_reveal(self, button):
|
||||
self.revealed = button.get_active()
|
||||
@@ -221,7 +233,7 @@ class Window(Adw.ApplicationWindow):
|
||||
if self.status.get("running") == "1":
|
||||
subprocess.run([CTL, "restart"], stdin=subprocess.DEVNULL, capture_output=True)
|
||||
self.toast("New password set" + (": remote access restarted" if self.status.get("running") == "1" else ""))
|
||||
self.refresh()
|
||||
self.refresh_soon()
|
||||
|
||||
def copy(self, text, done):
|
||||
if text:
|
||||
|
||||
Reference in new issue
Block a user