Add support for case where no license is present

This commit is contained in:
wheaney 2024-05-23 23:07:56 -07:00
parent 0d3f9ff757
commit c25219353a
11 changed files with 91 additions and 28 deletions

View File

@ -6,6 +6,7 @@
<file preprocess="xml-stripblanks">gtk/license-dialog.ui</file>
<file preprocess="xml-stripblanks">gtk/no-device.ui</file>
<file preprocess="xml-stripblanks">gtk/no-extension.ui</file>
<file preprocess="xml-stripblanks">gtk/no-license.ui</file>
<file preprocess="xml-stripblanks">gtk/shortcut-dialog.ui</file>
<file preprocess="xml-stripblanks">gtk/window.ui</file>
</gresource>

View File

@ -1,4 +1,4 @@
from gi.repository import Adw, Gtk
from gi.repository import Gtk
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/gtk/failed-verification.ui')
class FailedVerification(Gtk.Box):

31
ui/src/gtk/no-license.ui Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="NoLicense" parent="GtkBox">
<property name="orientation">1</property>
<property name="margin-top">20</property>
<property name="margin-bottom">20</property>
<property name="margin-start">20</property>
<property name="margin-end">20</property>
<property name="spacing">20</property>
<child>
<object class="AdwStatusPage">
<property name="title" translatable="true">No license file was found</property>
<property name="description" translatable="true">
The first time you use Breezy Desktop, an internet connection is required to retrieve your device's license.
Don't worry, there's no obligation to donate at this time. If you haven't, you'll be given a trial license so you can decide if Breezy Desktop fits your needs.
Once you obtain a license, trial or otherwise, you can use Breezy Desktop offline until features expire (or indefinitely, if you've chosen lifetime access).
</property>
<property name="width-request">650</property>
<property name="height-request">400</property>
</object>
</child>
<child type="action">
<object class="GtkButton" id="refresh_license_button">
<property name="label" translatable="true">Try Again</property>
</object>
</child>
</template>
</interface>

View File

@ -19,7 +19,7 @@ class LicenseDialog(Gtk.Dialog):
self.init_template()
self.ipc = XRDriverIPC.get_instance()
StateManager.get_instance().connect('license-action-needed', self._handle_license)
StateManager.get_instance().connect('notify::license-action-needed', self._handle_license)
self._handle_license(StateManager.get_instance())
self.request_token.connect('apply', self._on_request_token)

View File

@ -1,4 +1,4 @@
from gi.repository import Adw, Gtk
from gi.repository import Adw
from .time import time_remaining_text

View File

@ -38,6 +38,7 @@ breezydesktop_sources = [
'main.py',
'nodevice.py',
'noextension.py',
'nolicense.py',
'settingsmanager.py',
'shortcutdialog.py',
'statemanager.py',

View File

@ -1,4 +1,4 @@
from gi.repository import Adw, Gtk
from gi.repository import Gtk
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/gtk/no-device.ui')
class NoDevice(Gtk.Box):

View File

@ -1,4 +1,4 @@
from gi.repository import Adw, Gtk
from gi.repository import Gtk
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/gtk/no-extension.ui')
class NoExtension(Gtk.Box):

20
ui/src/nolicense.py Normal file
View File

@ -0,0 +1,20 @@
from gi.repository import Gtk, GLib, GObject
from .xrdriveripc import XRDriverIPC
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/gtk/no-license.ui')
class NoLicense(Gtk.Box):
__gtype_name__ = "NoLicense"
refresh_license_button = Gtk.Template.Child()
def __init__(self, **kwargs):
super(Gtk.Box, self).__init__()
self.init_template()
self.ipc = XRDriverIPC.get_instance()
self.refresh_license_button.connect("clicked", self.on_refresh_license_button_clicked)
def on_refresh_license_button_clicked(self, button):
self.ipc.write_control_flags({'refresh_device_license': True})

View File

@ -16,14 +16,14 @@ class Logger:
class StateManager(GObject.GObject):
__gsignals__ = {
'device-update': (GObject.SIGNAL_RUN_FIRST, None, (str,)),
'license-action-needed': (GObject.SIGNAL_RUN_FIRST, None, (bool,)),
'device-update': (GObject.SIGNAL_RUN_FIRST, None, (str,))
}
__gproperties__ = {
'follow-mode': (bool, 'Follow Mode', 'Whether the follow mode is enabled', False, GObject.ParamFlags.READWRITE),
'follow-threshold': (float, 'Follow Threshold', 'The follow threshold', 1.0, 45.0, 15.0, GObject.ParamFlags.READWRITE),
'license-action-needed-seconds': (int, 'License Action Needed Seconds', 'The remaining time until the license action is needed', 0, LICENSE_ACTION_NEEDED_MAX, 0, GObject.ParamFlags.READWRITE),
'license-action-needed': (bool, 'License Action Needed', 'Whether the license needs attention', False, GObject.ParamFlags.READWRITE),
'license-present': (bool, 'License Present', 'Whether a license is present', False, GObject.ParamFlags.READWRITE),
}
_instance = None
@ -55,6 +55,7 @@ class StateManager(GObject.GObject):
self.license_action_needed = False
self.license_action_needed_seconds = 0
self.confirmed_token = False
self.license_present = False
self.start()
@ -74,30 +75,36 @@ class StateManager(GObject.GObject):
license_view = self.state['ui_view'].get('license')
if license_view:
confirmed_token = license_view.get('confirmed_token') == True
if not self.license_present:
self.set_property('license-present', True)
self.confirmed_token = license_view.get('confirmed_token') == True
action_needed_details = license_view.get('action_needed')
action_needed_seconds = action_needed_details.get('seconds') if action_needed_details else None
action_needed = action_needed_seconds is not None and action_needed_seconds < LICENSE_WARN_SECONDS
if (action_needed != self.license_action_needed or self.confirmed_token != confirmed_token):
if (action_needed != self.license_action_needed):
self.license_action_needed = action_needed
self.license_action_needed_seconds = action_needed_seconds
self.confirmed_token = confirmed_token
self.emit('license-action-needed', action_needed or not confirmed_token)
self.set_property('license-action-needed', action_needed)
elif self.license_present:
self.set_property('license-present', False)
self.set_property('follow-mode', self.state.get('breezy_desktop_smooth_follow_enabled'))
self.set_property('license-action-needed-seconds', self.license_action_needed_seconds)
if self.running: threading.Timer(1.0, self._refresh_state).start()
def do_set_property(self, prop, value):
if prop.name == 'follow-mode':
self.follow_mode = value
if prop.name == 'license-action-needed-seconds':
self.license_action_needed_seconds = value
if prop.name == 'license-action-needed':
self.license_action_needed = value
if prop.name == 'license-present':
self.license_present = value
def do_get_property(self, prop):
if prop.name == 'follow-mode':
return self.follow_mode
if prop.name == 'license-action-needed-seconds':
return self.license_action_needed_seconds
if prop.name == 'license-action-needed':
return self.license_action_needed
if prop.name == 'license-present':
return self.license_present

View File

@ -25,6 +25,7 @@ from .connecteddevice import ConnectedDevice
from .failedverification import FailedVerification
from .nodevice import NoDevice
from .noextension import NoExtension
from .nolicense import NoLicense
from .verify import verify_installation
from .time import LICENSE_WARN_SECONDS
@ -39,33 +40,35 @@ class BreezydesktopWindow(Gtk.ApplicationWindow):
super().__init__(**kwargs)
self.state_manager = StateManager.get_instance()
self.state_manager.connect('device-update', self._handle_device_update)
self.state_manager.connect('license-action-needed', self._handle_device_update)
self.state_manager.connect('device-update', self._handle_state_update)
self.state_manager.connect('notify::license-action-needed', self._handle_state_update)
self.state_manager.connect('notify::license-present', self._handle_state_update)
self.connected_device = ConnectedDevice()
self.failed_verification = FailedVerification()
self.no_device = NoDevice()
self.no_extension = NoExtension()
self.failed_verification = FailedVerification()
self.no_license = NoLicense()
self.license_action_needed_banner.connect('button-clicked', self._on_license_action_needed_button_clicked)
self._handle_device_update(self.state_manager, None)
self._handle_state_update(self.state_manager, None)
self.connect("destroy", self._on_window_destroy)
def _handle_device_update(self, state_manager, val):
GLib.idle_add(self._handle_device_update_gui, state_manager)
def _handle_state_update(self, state_manager, val):
GLib.idle_add(self._handle_state_update_gui, state_manager)
def _handle_device_update_gui(self, state_manager):
license_action_needed_seconds = state_manager.get_property('license-action-needed-seconds')
show_banner = license_action_needed_seconds is not None and license_action_needed_seconds < LICENSE_WARN_SECONDS
self.license_action_needed_banner.set_revealed(show_banner)
def _handle_state_update_gui(self, state_manager):
self.license_action_needed_banner.set_revealed(state_manager.get_property('license-action-needed') == True)
for child in self.main_content:
self.main_content.remove(child)
if not verify_installation():
self.main_content.append(self.failed_verification)
elif not self.state_manager.get_property('license-present'):
self.main_content.append(self.no_license)
elif not ExtensionsManager.get_instance().is_installed():
self.main_content.append(self.no_extension)
elif state_manager.connected_device_name:
@ -80,4 +83,4 @@ class BreezydesktopWindow(Gtk.ApplicationWindow):
dialog.present()
def _on_window_destroy(self, widget):
self.state_manager.disconnect_by_func(self._handle_device_update)
self.state_manager.disconnect_by_func(self._handle_state_update)