about summary refs log tree commit diff stats
path: root/fungus/main_window.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/main_window.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/main_window.py')
-rw-r--r--fungus/main_window.py49
1 files changed, 37 insertions, 12 deletions
diff --git a/fungus/main_window.py b/fungus/main_window.py
index 75cb76b..122473b 100644
--- a/fungus/main_window.py
+++ b/fungus/main_window.py
@@ -6,6 +6,7 @@ import os
 import shutil
 import subprocess
 import sys
+import threading
 
 import gi
 gi.require_version('Gtk', '3.0')
@@ -698,6 +699,7 @@ class Main(Gtk.ApplicationWindow):
 
         if game:
             edit_game_dialog = AddGame(self, file_path, is_editing=True, dispatcher=self.dispatcher)
+            edit_game_dialog._prefix_status_label.set_visible(False)
             edit_game_dialog.connect("response", self.on_edit_dialog_response, edit_game_dialog, game)
 
             model_runner = edit_game_dialog.combobox_runner.get_model()
@@ -854,24 +856,47 @@ class Main(Gtk.ApplicationWindow):
             if prefix:
                 if not os.path.isdir(prefix):
                     os.makedirs(prefix, exist_ok=True)
-                    # Initialize the Wine prefix via UMU
+                    # Initialize the Wine prefix via UMU (background thread)
                     gameid = protonfix if protonfix else title_formatted
                     if gameid and runner:
                         env = os.environ.copy()
                         env["GAMEID"] = gameid
                         env["WINEPREFIX"] = prefix
                         env["PROTONPATH"] = runner
-                        try:
-                            subprocess.run(
-                                [umu_run, "wineprefixcreate", "/usr/bin/true"],
-                                env=env,
-                                check=True,
-                                capture_output=True,
-                            )
-                        except subprocess.CalledProcessError as e:
-                            log.error("Prefix initialization failed for '%s': %s", title, e.stderr.decode())
-                    else:
-                        log.warning("Skipping prefix init for '%s' (GAMEID or runner missing)", title)
+
+                        umu_run_path = umu_run
+                        umu_env = env
+                        umu_title = title
+                        umu_dispatcher = self.dispatcher
+
+                        def _init_prefix():
+                            try:
+                                subprocess.run(
+                                    [umu_run_path, "wineprefixcreate", "/usr/bin/true"],
+                                    env=umu_env,
+                                    check=True,
+                                    capture_output=True,
+                                )
+                                log.info("Prefix initialized for '%s'", umu_title)
+                                umu_dispatcher.submit(
+                                    add_game_dialog._set_prefix_status,
+                                    "Prefix ready",
+                                    True,
+                                )
+                            except subprocess.CalledProcessError as e:
+                                log.error("Prefix initialization failed for '%s': %s", umu_title, e.stderr.decode())
+                                umu_dispatcher.submit(
+                                    add_game_dialog._set_prefix_status,
+                                    "Prefix init failed",
+                                    False,
+                                )
+                            finally:
+                                umu_dispatcher.submit(add_game_dialog._close_after_prefix, response_id)
+
+                        add_game_dialog._set_prefix_status("Creating prefix…", None)
+                        threading.Thread(target=_init_prefix, daemon=True).start()
+                        return True  # defer dialog close
+                log.warning("Skipping prefix init for '%s' (GAMEID or runner missing)", title)
 
             if self.library.exists(title_formatted):
                 self.show_warning_dialog(