about summary refs log tree commit diff stats
path: root/fungus/add_game_dialog.py
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-07-05 22:18:57 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-07-05 22:18:57 +0300
commit30dff8577cf7b5d2d7f76e1ba465c6c3c7bd4e3e (patch)
treea82e729480232cb9fba500c2861b55c3951c0e65 /fungus/add_game_dialog.py
parentf8205cbfa571e5e4c2e57654580b46bec1b88c48 (diff)
downloadfungus-launcher-dev.tar.gz
fungus-launcher-dev.tar.xz
initialize prefix asynchronously when adding new game as to not block the UI dev
Diffstat (limited to 'fungus/add_game_dialog.py')
-rw-r--r--fungus/add_game_dialog.py53
1 files changed, 52 insertions, 1 deletions
diff --git a/fungus/add_game_dialog.py b/fungus/add_game_dialog.py
index 25e12bf..0cb2597 100644
--- a/fungus/add_game_dialog.py
+++ b/fungus/add_game_dialog.py
@@ -126,7 +126,15 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog):
         self.grid_shortcut_icon.set_margin_start(10)
         self.grid_shortcut_icon.set_margin_end(10)
         self.grid_shortcut_icon.set_margin_top(10)
-        self.grid_shortcut_icon.set_margin_bottom(10)
+        self.grid_shortcut_icon.set_margin_bottom(5)
+
+        # Status label for background prefix initialisation
+        self._prefix_status_label = Gtk.Label(label="")
+        self._prefix_status_label.set_visible(False)
+        self._prefix_status_label.set_halign(Gtk.Align.START)
+        self._prefix_status_label.set_markup("<i>Click OK to create prefix</i>")
+        self._prefix_status_label.set_margin_start(10)
+        self._prefix_status_label.set_margin_bottom(10)
 
         self.grid_protonfix = Gtk.Grid()
         self.grid_protonfix.set_row_spacing(10)
@@ -168,6 +176,12 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog):
         .combobox {
             border: 1px solid red;
         }
+        .prefix-status-ready {
+            color: green;
+        }
+        .prefix-status-error {
+            color: red;
+        }
         """
         css_provider.load_from_data(css.encode('utf-8'))
         Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), css_provider,
@@ -392,6 +406,7 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog):
         page1.add(self.grid_prefix)
         page1.add(self.grid_runner)
         page1.add(self.grid_shortcut_icon)
+        page1.add(self._prefix_status_label)
 
         self.grid_protonfix.attach(self.label_protonfix, 0, 0, 1, 1)
         self.grid_protonfix.attach(self.entry_protonfix, 0, 1, 3, 1)
@@ -933,6 +948,42 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog):
 
         return True
 
+    # ── Background prefix initialisation ─────────────────────────────
+
+    def _set_prefix_status(self, message: str, success: bool | None) -> None:
+        """Update the prefix-status label and the OK button state.
+
+        Parameters
+        ----------
+        message : str
+            Status text to display.
+        success : bool or None
+            ``True`` = ready, ``False`` = failed, ``None`` = in progress.
+        """
+        if not hasattr(self, "_prefix_status_label"):
+            return
+
+        self._prefix_status_label.set_visible(True)
+        self._prefix_status_label.set_text(message)
+        if success is True:
+            self._prefix_status_label.get_style_context().add_class("prefix-status-ready")
+            self._prefix_status_label.get_style_context().remove_class("prefix-status-error")
+            self.button_ok.set_sensitive(True)
+        elif success is False:
+            self._prefix_status_label.get_style_context().add_class("prefix-status-error")
+            self._prefix_status_label.get_style_context().remove_class("prefix-status-ready")
+            self.button_ok.set_sensitive(True)  # allow user to close and retry
+        else:
+            self._prefix_status_label.get_style_context().remove_class("prefix-status-ready")
+            self._prefix_status_label.get_style_context().remove_class("prefix-status-error")
+            self.button_ok.set_sensitive(False)
+
+    def _close_after_prefix(self, response_id: int) -> None:
+        """Close the dialog after prefix initialisation finishes."""
+        if hasattr(self, "blocking_window"):
+            GLib.idle_add(self.blocking_window.destroy)
+        GLib.idle_add(self.response, response_id)
+
     # ── Environment tab handlers ─────────────────────────────────────
 
     def populate_environment_from_game(self, game):