From 5912302043b95c5c9616e00d67c06488228ab63e Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 2 Mar 2025 16:52:34 +0000 Subject: [PATCH] Add connection indicator to client --- client/src/main_window.vala | 32 +++++++++++++++++++++++++++++++- client/src/session_manager.vala | 4 ++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/client/src/main_window.vala b/client/src/main_window.vala index a9ae882..08e1a77 100644 --- a/client/src/main_window.vala +++ b/client/src/main_window.vala @@ -12,8 +12,38 @@ namespace StudySystemClient { header_bar.title_widget = title; set_titlebar(header_bar); + var connection_indicator = new ConnectionIndicator(client); var activities_view = new ActivitiesView(client); - set_child(activities_view); + + var content = new Gtk.Box(Gtk.Orientation.VERTICAL, 0); + content.append(connection_indicator); + content.append(activities_view); + + set_child(content); + } + } + + private class ConnectionIndicator : Gtk.Box { + public ConnectionIndicator(Client client) { + var icon + = new Gtk.Image.from_icon_name("network-offline-symbolic"); + var label = new Gtk.Label("Disconnected"); + + var content = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 8); + content.margin_top = content.margin_bottom + = content.margin_start = content.margin_end = 12; + content.hexpand = true; + content.halign = Gtk.Align.CENTER; + content.append(icon); + content.append(label); + + var revealer = new Gtk.Revealer(); + revealer.set_child(content); + append(revealer); + + client.connection_status.connect((connected) => { + revealer.reveal_child = !connected; + }); } } } diff --git a/client/src/session_manager.vala b/client/src/session_manager.vala index ac8dd04..a5662e2 100644 --- a/client/src/session_manager.vala +++ b/client/src/session_manager.vala @@ -3,7 +3,7 @@ namespace StudySystemClient { public delegate void ReceiveCallback(owned uint8[] msg); private const uint INIT_RECONNECT_WAIT_MS = 500; - private const uint MAX_RECONNECT_WAIT_MS = 60000; + private const uint MAX_RECONNECT_WAIT_MS = 30000; private const double RECONNECT_BACKOFF = 1.6; private SessionFactory session_factory; @@ -72,7 +72,7 @@ namespace StudySystemClient { public class SessionFactory { private const string CA_FILENAME = "/ca.pem"; private const string CERT_FILENAME = "/client.pem"; - private const uint TIMEOUT_S = 1; + private const uint TIMEOUT_S = 2; private InetSocketAddress host; private TlsCertificate cert;