From 7f8793ce53dd318ea66bd54ef2626765424bed2f Mon Sep 17 00:00:00 2001
From: wheaney <42350981+wheaney@users.noreply.github.com>
Date: Mon, 6 May 2024 09:54:07 -0700
Subject: [PATCH] SettingsManager and StateManager working impls
---
.../breezydesktop@org.xronlinux/metadata.json | 2 +-
...> com.xronlinux.BreezyDesktop.gschema.xml} | 7 ++-
.../schemas/gschemas.compiled | Bin 740 -> 720 bytes
ui/.python-version | 1 +
ui/src/SettingsManager.py | 15 +++++
ui/src/StateManager.py | 54 ++++++++++++++++++
ui/src/connecteddevice.py | 9 +--
ui/src/connecteddevice.ui | 4 +-
ui/src/main.py | 20 -------
ui/src/meson.build | 2 +
ui/src/window.py | 15 +++--
11 files changed, 94 insertions(+), 35 deletions(-)
rename gnome/breezydesktop@org.xronlinux/schemas/{org.gnome.shell.extensions.breezy-desktop.gschema.xml => com.xronlinux.BreezyDesktop.gschema.xml} (89%)
create mode 100644 ui/.python-version
create mode 100644 ui/src/SettingsManager.py
create mode 100644 ui/src/StateManager.py
diff --git a/gnome/breezydesktop@org.xronlinux/metadata.json b/gnome/breezydesktop@org.xronlinux/metadata.json
index c740eb2..4343f7e 100644
--- a/gnome/breezydesktop@org.xronlinux/metadata.json
+++ b/gnome/breezydesktop@org.xronlinux/metadata.json
@@ -2,7 +2,7 @@
"uuid": "breezydesktop@org.xronlinux",
"name": "Breezy GNOME XR Desktop",
"description": "XR virtual desktop for GNOME.",
- "settings-schema": "org.gnome.shell.extensions.breezy-desktop",
+ "settings-schema": "com.xronlinux.BreezyDesktop",
"shell-version": [
"45", "46"
],
diff --git a/gnome/breezydesktop@org.xronlinux/schemas/org.gnome.shell.extensions.breezy-desktop.gschema.xml b/gnome/breezydesktop@org.xronlinux/schemas/com.xronlinux.BreezyDesktop.gschema.xml
similarity index 89%
rename from gnome/breezydesktop@org.xronlinux/schemas/org.gnome.shell.extensions.breezy-desktop.gschema.xml
rename to gnome/breezydesktop@org.xronlinux/schemas/com.xronlinux.BreezyDesktop.gschema.xml
index 55561be..8603943 100644
--- a/gnome/breezydesktop@org.xronlinux/schemas/org.gnome.shell.extensions.breezy-desktop.gschema.xml
+++ b/gnome/breezydesktop@org.xronlinux/schemas/com.xronlinux.BreezyDesktop.gschema.xml
@@ -1,5 +1,6 @@
-
-
+
+
+
true
@@ -54,5 +55,5 @@
End distance when using the "toggle display distance" shortcut.
-
+
\ No newline at end of file
diff --git a/gnome/breezydesktop@org.xronlinux/schemas/gschemas.compiled b/gnome/breezydesktop@org.xronlinux/schemas/gschemas.compiled
index ff1fbd430a791937caadf07e3b479886d74ea1c4..aae010ed2b172de76e71dd481aa97e3191c18b3f 100644
GIT binary patch
delta 329
zcmaFDdVzI`h<0YN<9M*u!=G;{0D*v5Qo8s0Yt|Dv9xQ0Do6yx)@1Nt=m63Mj0_Aw#E@T<
zu9u#dpPQ;zoRON7qnBDylA2eXnV(mzmsFIRT2-l=l3JWyl3xH+3j`V*5E`tP3CIRv
z76yii{i5|CBUu^B7%G7DG9b>3_u0n^lm@XSf#L^%^gAHFob)3EBo1N=0L4LO@Bs1Y
zCGImp;vlvHP}~4WCjfD+Di;e#9K@CdiZ=l19w3H!7sLj7Hx(?n1jsqYDbf$p0Alk3
zHS7S=dx6+3LZ}oZ4q{6K#cu%VCqS%MkXVud6xRm^hCVnj^ud9lj|dEXSYS-9V^rC^
If>DJL0POWossI20
diff --git a/ui/.python-version b/ui/.python-version
new file mode 100644
index 0000000..2419ad5
--- /dev/null
+++ b/ui/.python-version
@@ -0,0 +1 @@
+3.11.9
diff --git a/ui/src/SettingsManager.py b/ui/src/SettingsManager.py
new file mode 100644
index 0000000..c88ce68
--- /dev/null
+++ b/ui/src/SettingsManager.py
@@ -0,0 +1,15 @@
+
+from gi.repository import Gio
+
+class SettingsManager:
+ _instance = None
+
+ @staticmethod
+ def get_instance():
+ if not SettingsManager._instance:
+ SettingsManager._instance = SettingsManager()
+
+ return SettingsManager._instance
+
+ def __init__(self):
+ self.settings = Gio.Settings.new_with_path("com.xronlinux.BreezyDesktop", "/com/xronlinux/BreezyDesktop/")
diff --git a/ui/src/StateManager.py b/ui/src/StateManager.py
new file mode 100644
index 0000000..427200a
--- /dev/null
+++ b/ui/src/StateManager.py
@@ -0,0 +1,54 @@
+import threading
+from gi.repository import GObject
+from .XRDriverIPC import XRDriverIPC
+
+class Logger:
+ def info(self, message):
+ print(message)
+
+ def error(self, message):
+ print(message)
+
+class StateManager(GObject.GObject):
+ __gsignals__ = {
+ 'device_update': (GObject.SIGNAL_RUN_FIRST, None, (str,))
+ }
+
+ _instance = None
+
+ @staticmethod
+ def get_instance():
+ if not StateManager._instance:
+ StateManager._instance = StateManager()
+
+ return StateManager._instance
+
+ @staticmethod
+ def device_name(state):
+ if state.get('connected_device_brand') and state.get('connected_device_model'):
+ return f"{state['connected_device_brand']} {state['connected_device_model']}"
+
+ return None
+
+ def __init__(self):
+ GObject.GObject.__init__(self)
+ self.ipc = XRDriverIPC(logger = Logger(), user="wayne", user_home="/home/wayne")
+ self.connected_device_name = None
+
+ self.start()
+
+ def start(self):
+ self.running = True
+ self._refresh_state()
+
+ def stop(self):
+ self.running = False
+
+ def _refresh_state(self):
+ self.state = self.ipc.retrieve_driver_state()
+ new_device_name = StateManager.device_name(self.state)
+ if self.connected_device_name != new_device_name:
+ self.connected_device_name = new_device_name
+ self.emit('device_update', self.connected_device_name)
+
+ if self.running: threading.Timer(1.0, self._refresh_state).start()
diff --git a/ui/src/connecteddevice.py b/ui/src/connecteddevice.py
index 841d74c..d56afdd 100644
--- a/ui/src/connecteddevice.py
+++ b/ui/src/connecteddevice.py
@@ -1,5 +1,5 @@
-from gi.repository import Adw, Gtk
-
+from gi.repository import Adw, Gio, Gtk
+from .SettingsManager import SettingsManager
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/connecteddevice.ui')
class ConnectedDevice(Gtk.Box):
@@ -16,9 +16,10 @@ class ConnectedDevice(Gtk.Box):
def __init__(self):
super(Gtk.Box, self).__init__()
self.init_template()
+ self.settings = SettingsManager.get_instance().settings
- self.get_settings().bind('display-distance', display_distance_scale, 'value', Gio.SettingsBindFlags.DEFAULT)
- self.get_settings().bind('effect-enable', effect_enable_switch, 'active', Gio.SettingsBindFlags.DEFAULT)
+ self.settings.bind('display-distance', self.display_distance_scale, 'value', Gio.SettingsBindFlags.DEFAULT)
+ self.settings.bind('effect-enable', self.effect_enable_switch, 'active', Gio.SettingsBindFlags.DEFAULT)
def set_device_name(self, name):
self.device_label.set_markup(f"{name}")
diff --git a/ui/src/connecteddevice.ui b/ui/src/connecteddevice.ui
index afed595..919f472 100644
--- a/ui/src/connecteddevice.ui
+++ b/ui/src/connecteddevice.ui
@@ -41,7 +41,7 @@