Add installation verification

This commit is contained in:
wheaney 2024-05-23 11:01:59 -07:00
parent 396b031d28
commit 7b80f999fa
9 changed files with 88 additions and 5 deletions

View File

@ -5,6 +5,8 @@
IFS=: read -ra host_data_dirs < <(flatpak-spawn --host sh -c 'echo "$XDG_DATA_DIRS"')
IFS=: read -ra HOST_XDG_STATE_HOME < <(flatpak-spawn --host sh -c 'echo "$XDG_STATE_HOME"')
IFS=: read -ra HOST_XDG_BIN_HOME < <(flatpak-spawn --host sh -c 'echo "$XDG_BIN_HOME"')
IFS=: read -ra HOST_XDG_DATA_HOME < <(flatpak-spawn --host sh -c 'echo "$XDG_DATA_HOME"')
# To avoid potentially muddying up $XDG_DATA_DIRS too much, we link the schema paths
# into a temporary directory.
@ -34,12 +36,26 @@ if [[ ! -z "${HOST_XDG_DATA_DIRS}" ]]; then
XDG_DATA_DIRS="${HOST_XDG_DATA_DIRS:1}:${XDG_DATA_DIRS}"
fi
if [[ ! -z "${HOST_XDG_BIN_HOME}" ]]; then
XDG_BIN_HOME="${HOST_XDG_BIN_HOME}"
else
XDG_BIN_HOME="$(realpath ~)/.local/bin"
fi
if [[ ! -z "${HOST_XDG_STATE_HOME}" ]]; then
XDG_STATE_HOME="${HOST_XDG_STATE_HOME}"
else
XDG_STATE_HOME="${USER_HOME}/.local/state"
XDG_STATE_HOME="$(realpath ~)/.local/state"
fi
if [[ ! -z "${HOST_XDG_DATA_HOME}" ]]; then
XDG_DATA_HOME="${HOST_XDG_DATA_HOME}"
else
XDG_DATA_HOME="$(realpath ~)/.local/share"
fi
export XDG_DATA_DIRS
export XDG_BIN_HOME
export XDG_STATE_HOME
export XDG_DATA_HOME
exec breezydesktop "$@"

@ -1 +1 @@
Subproject commit 0f8022681bc5a3beb5ce0468e348e5f84658662f
Subproject commit b98e0ec9a12f2ec37ebbb06e6b2226246da11107

View File

@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/com/xronlinux/BreezyDesktop">
<file preprocess="xml-stripblanks">gtk/connected-device.ui</file>
<file preprocess="xml-stripblanks">gtk/failed-verification.ui</file>
<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>

View File

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

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="FailedVerification" 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">Breezy Desktop GNOME invalid setup</property>
<property name="description" translatable="true">Your Breezy GNOME setup is invalid or incomplete. Please re-run the setup script. Report this issue if it persists.</property>
<property name="width-request">650</property>
</object>
</child>
</template>
</interface>

View File

@ -17,10 +17,10 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
import gi
import logging
import os
import sys
import gi
from logging.handlers import TimedRotatingFileHandler
@ -29,7 +29,7 @@ gi.require_version('Adw', '1')
gi.require_version('Gio', '2.0')
gi.require_version('GLib', '2.0')
from gi.repository import Adw, Gtk, Gio, GLib
from gi.repository import Adw, Gtk, Gio
from .licensedialog import LicenseDialog
from .statemanager import StateManager
from .window import BreezydesktopWindow

View File

@ -31,6 +31,7 @@ breezydesktop_sources = [
'__init__.py',
'connecteddevice.py',
'extensionsmanager.py',
'failedverification.py',
'licensedialog.py',
'licensefeaturerow.py',
'licensetierrow.py',
@ -41,6 +42,7 @@ breezydesktop_sources = [
'shortcutdialog.py',
'statemanager.py',
'time.py',
'verify.py',
'window.py'
]

35
ui/src/verify.py Normal file
View File

@ -0,0 +1,35 @@
import logging
import os
import subprocess
logger = logging.getLogger('breezy_ui')
user_home = os.path.expanduser('~')
def verify_installation():
xdg_bin_home = os.environ.get('XDG_BIN_HOME')
if not xdg_bin_home or xdg_bin_home.startswith('/app') or xdg_bin_home.startswith(os.path.join(user_home, '.var/app')):
xdg_bin_home = os.path.join(user_home, '.local', 'bin')
verify_installation_path = os.path.join(xdg_bin_home, 'breezy_gnome_verify')
if not os.path.exists(verify_installation_path):
logger.error(f"Could not verify your Breezy GNOME installation. Please ensure that Breezy GNOME is installed.")
exit(1)
env_copy = os.environ.copy()
xdg_data_home = os.environ.get('XDG_DATA_HOME')
if not xdg_data_home or xdg_data_home.startswith('/app') or xdg_data_home.startswith(os.path.join(user_home, '.var/app')):
xdg_data_home = os.path.join(user_home, '.local', 'share')
env_copy["XDG_DATA_HOME"] = xdg_data_home
try:
verify_output = subprocess.check_output([verify_installation_path], stderr=subprocess.STDOUT, env=env_copy).strip()
success = verify_output == b"Verification succeeded"
if not success:
logger.error(f"Could not verify your Breezy GNOME installation. Please ensure that Breezy GNOME is installed.")
logger.error(verify_output)
return success
except subprocess.CalledProcessError as e:
logger.error(f"Could not verify your Breezy GNOME installation. Please ensure that Breezy GNOME is installed.")
logger.error(e.output.decode().strip())
return False

View File

@ -22,8 +22,10 @@ from .extensionsmanager import ExtensionsManager
from .licensedialog import LicenseDialog
from .statemanager import StateManager
from .connecteddevice import ConnectedDevice
from .failedverification import FailedVerification
from .nodevice import NoDevice
from .noextension import NoExtension
from .verify import verify_installation
from .time import LICENSE_WARN_SECONDS
@Gtk.Template(resource_path='/com/xronlinux/BreezyDesktop/gtk/window.ui')
@ -43,6 +45,7 @@ class BreezydesktopWindow(Gtk.ApplicationWindow):
self.connected_device = ConnectedDevice()
self.no_device = NoDevice()
self.no_extension = NoExtension()
self.failed_verification = FailedVerification()
self.license_action_needed_banner.connect('button-clicked', self._on_license_action_needed_button_clicked)
@ -61,7 +64,9 @@ class BreezydesktopWindow(Gtk.ApplicationWindow):
for child in self.main_content:
self.main_content.remove(child)
if not ExtensionsManager.get_instance().is_installed():
if not verify_installation():
self.main_content.append(self.failed_verification)
elif not ExtensionsManager.get_instance().is_installed():
self.main_content.append(self.no_extension)
elif state_manager.connected_device_name:
self.main_content.append(self.connected_device)