mirror of
https://github.com/aclist/dztui.git
synced 2026-11-05 17:45:10 +01:00
feat: FlatpakOverridePage WIP
This commit is contained in:
1 parent
e286f02342
commit
01b3babdf5
6 files changed
+108
-19
No files matched your search
@@ -12,13 +12,13 @@ from dzgui.const.constants import (
|
||||
APP_NAME,
|
||||
APP_NAME_LOWER,
|
||||
HERO_PATH,
|
||||
FLATPAK_STEAM_PATH,
|
||||
FLATPAK_ROOT_PATH,
|
||||
LEGACY_CONFIG_PATH,
|
||||
)
|
||||
from dzgui.const.boilerplate import config_boilerplate
|
||||
from dzgui.const.endpoints import STEAM_API_SETUP
|
||||
from dzgui.config import freedesktop
|
||||
from dzgui.init.proc import path_to_steam_cmd
|
||||
from dzgui.init.proc import is_sandboxed, path_to_steam_cmd
|
||||
from dzgui.init.migrate import migrate_legacy_conf
|
||||
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
|
||||
from dzgui.strings import wizard
|
||||
@@ -45,7 +45,8 @@ class PageNum(Enum):
|
||||
STEAM_API = 4
|
||||
USER_PREFS = 5
|
||||
SHORTCUTS = 6
|
||||
FINAL = 7
|
||||
FLATPAK = 7
|
||||
FINAL = 8
|
||||
|
||||
|
||||
class OptionalPageMixin:
|
||||
@@ -144,7 +145,7 @@ class NotificationFrame(Gtk.Frame):
|
||||
margin_start=50,
|
||||
margin_end=50,
|
||||
)
|
||||
wrapped = textwrap.fill(label, width=80)
|
||||
wrapped = textwrap.fill(label, width=60)
|
||||
self.label = Gtk.Label(
|
||||
label=wrapped,
|
||||
justify=Gtk.Justification.CENTER,
|
||||
@@ -158,7 +159,7 @@ class NotificationFrame(Gtk.Frame):
|
||||
add_class(self, "error-frame")
|
||||
|
||||
def set_text(self, text: str) -> None:
|
||||
wrapped = textwrap.fill(text, width=80)
|
||||
wrapped = textwrap.fill(text, width=60)
|
||||
self.label.set_markup(wrapped)
|
||||
|
||||
|
||||
@@ -243,12 +244,23 @@ class IntroductionPage(EnumeratedWizardPage):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
enum=PageNum.INTRO,
|
||||
heading=f"Welcome to {APP_NAME}!",
|
||||
heading=wizard.welcome.format(APP_NAME),
|
||||
description=wizard.blurb_intro,
|
||||
)
|
||||
self.page_type = Gtk.AssistantPageType.INTRO
|
||||
self.set_title(wizard.title_intro)
|
||||
|
||||
self.error_box = NotificationFrame(wizard.error_sandbox, error=True)
|
||||
self.add_start(self.error_box)
|
||||
|
||||
self.connect("map", self._on_map)
|
||||
|
||||
def _on_map(self, page: "EnumeratedWizardPage") -> None:
|
||||
self.error_box.hide()
|
||||
if is_sandboxed():
|
||||
self.error_box.show()
|
||||
EMITTER.emit("step_pending")
|
||||
|
||||
|
||||
class Heading(Gtk.Label):
|
||||
def __init__(self, label: str):
|
||||
@@ -405,6 +417,43 @@ class PreferencesPage(EnumeratedWizardPage):
|
||||
EMITTER.emit("step_complete")
|
||||
|
||||
|
||||
class FlatpakOverridePage(EnumeratedWizardPage):
|
||||
def __init__(self, xdg: "Xdg") -> None:
|
||||
# TODO: strings
|
||||
super().__init__(
|
||||
enum=PageNum.FLATPAK,
|
||||
heading="Flatpak overrides",
|
||||
description="Enable overrides",
|
||||
)
|
||||
self.xdg = xdg
|
||||
self.page_type = Gtk.AssistantPageType.INTRO
|
||||
|
||||
# TODO: labels, blurbs
|
||||
# You chose to add a DZGUI shortcut directly to Steam.
|
||||
# Your Steam client selection is Flatpak Steam.
|
||||
# To launch DZGUI from Flatpak's sandbox, you must
|
||||
# grant permission for the sandbox to read from and write to the
|
||||
# following locations.
|
||||
|
||||
# Click below to whitelist these paths and enable Steam to register the DZGUI application.
|
||||
|
||||
# XDG.config, XDG.share, XDG.state, /tmp?
|
||||
|
||||
self.label = Gtk.Label(label="Whitelist")
|
||||
self.authorize_button = Gtk.Button(
|
||||
label="Grant permissions", halign=Gtk.Align.CENTER
|
||||
)
|
||||
self.authorize_button.connect("clicked", self._on_authorize)
|
||||
|
||||
for el in self.label, self.authorize_button:
|
||||
self.add_start(el)
|
||||
|
||||
def _on_authorize(self, button: Gtk.Button) -> None:
|
||||
# TODO: apply flatpak overrides via module
|
||||
print(self.xdg)
|
||||
EMITTER.emit("step_complete")
|
||||
|
||||
|
||||
class CompletionPage(EnumeratedWizardPage):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
@@ -437,6 +486,7 @@ class Assistant(Gtk.Assistant):
|
||||
self.page_api = SteamValidationPage()
|
||||
self.page_prefs = PreferencesPage()
|
||||
self.page_shortcuts = ShortcutCreationPage(XDG.shortcut)
|
||||
self.page_flatpak = FlatpakOverridePage(XDG)
|
||||
self.page_completion = CompletionPage()
|
||||
|
||||
self.set_forward_page_func(self._advance_page)
|
||||
@@ -456,6 +506,7 @@ class Assistant(Gtk.Assistant):
|
||||
self.page_api,
|
||||
self.page_prefs,
|
||||
self.page_shortcuts,
|
||||
self.page_flatpak,
|
||||
self.page_completion,
|
||||
):
|
||||
# NOTE: skip config migration page if no legacy config file
|
||||
@@ -476,7 +527,10 @@ class Assistant(Gtk.Assistant):
|
||||
def write_config(self, config: dict[str, Any]) -> None:
|
||||
write_json(config, self.config_path)
|
||||
|
||||
def get_final_page(self) -> int:
|
||||
def get_completion_page(self) -> int:
|
||||
return self.pages[self.page_completion]
|
||||
|
||||
def get_shortcut_page(self) -> int:
|
||||
return self.pages[self.page_shortcuts]
|
||||
|
||||
def _advance_page(self, index: int) -> int:
|
||||
@@ -489,7 +543,7 @@ class Assistant(Gtk.Assistant):
|
||||
sp = page.migrated_conf["default_steam_path"]
|
||||
self.page_shortcuts.set_steam_path(sp)
|
||||
self.config_values = self.page_migration.migrated_conf
|
||||
return self.get_final_page()
|
||||
return self.get_shortcuts_page()
|
||||
case SteamPathPage():
|
||||
path = page.get_path_from_radio()
|
||||
self.config_values["default_steam_path"] = path
|
||||
@@ -506,10 +560,22 @@ class Assistant(Gtk.Assistant):
|
||||
)
|
||||
case ShortcutCreationPage():
|
||||
page.create_shortcuts()
|
||||
if not self.needs_flatpak_override():
|
||||
return self.get_completion_page()
|
||||
case FlatpakOverridePage():
|
||||
pass
|
||||
case _:
|
||||
raise AttributeError("Trying to advance a non-canonical page")
|
||||
return index + 1
|
||||
|
||||
def needs_flatpak_override(self) -> None:
|
||||
if (
|
||||
self.page_shortcuts.is_steam_checkbox_active()
|
||||
and FLATPAK_ROOT_PATH in self.config_values["default_steam_path"]
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_setup_complete(self) -> bool:
|
||||
return self.setup_complete
|
||||
|
||||
@@ -625,12 +691,6 @@ class ShortcutCreationPage(OptionalPageMixin, EnumeratedWizardPage): # type: ig
|
||||
self.add_start(self.checks_area)
|
||||
self.show_all()
|
||||
self.connect("map", self._on_map)
|
||||
self.connect("map", self._toggle_checkbox)
|
||||
|
||||
def _toggle_checkbox(self, page: "EnumeratedWizardPage") -> None:
|
||||
if FLATPAK_STEAM_PATH in str(self.steam_path):
|
||||
self.steam_checkbox.set_active(False)
|
||||
self.steam_checkbox.set_sensitive(False)
|
||||
|
||||
def _on_start_menu_toggled(self, button: Gtk.CheckButton) -> None:
|
||||
state = button.get_active()
|
||||
@@ -641,6 +701,9 @@ class ShortcutCreationPage(OptionalPageMixin, EnumeratedWizardPage): # type: ig
|
||||
def set_steam_path(self, path: Path) -> None:
|
||||
self.steam_path = path
|
||||
|
||||
def is_steam_checkbox_active(self) -> None:
|
||||
return self.steam_checkbox.get_active()
|
||||
|
||||
def create_shortcuts(self) -> None:
|
||||
# NOTE: best-effort, permissive even on failure (page is already marked as complete)
|
||||
if self.steam_checkbox.get_active():
|
||||
|
||||
Reference in new issue
Block a user