Skip to content

Commit 10b4f26

Browse files
authored
Merge pull request #15 from ruscher/main
verify/install library for working steam module vdf
2 parents ffc6377 + bed4d5c commit 10b4f26

1 file changed

Lines changed: 64 additions & 7 deletions

File tree

usr/share/biglinux/biglinux-settings/usability/gamemode_dialog.py

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ def __init__(self, parent_window, script_path, action="start", on_close_callback
2626
self.set_title(title)
2727

2828
# Main content box
29+
self.toast_overlay = Adw.ToastOverlay()
2930
self.main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
30-
self.set_content(self.main_box)
31+
self.toast_overlay.set_child(self.main_box)
32+
self.set_content(self.toast_overlay)
3133

3234
# Status Page (Initially showing progress)
3335
self.status_page = Adw.StatusPage()
@@ -128,7 +130,7 @@ def add_close_button(self):
128130
def show_report_view(self):
129131
# Clear main box
130132
self.main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
131-
self.set_content(self.main_box)
133+
self.toast_overlay.set_child(self.main_box)
132134

133135
# Header Bar with Icon
134136
header = Adw.HeaderBar()
@@ -309,11 +311,66 @@ def on_steam_config(self, btn):
309311
dlg = SteamGamesDialog(parent=self)
310312
dlg.present()
311313
except Exception as e:
312-
# Handle case where vdf or module is missing or other errors
313-
d = Adw.MessageDialog(heading="Error", body=f"Cannot load Steam configuration tool: {e}")
314-
d.add_response("ok", "OK")
315-
d.set_transient_for(self)
316-
d.present()
314+
if "vdf" in str(e):
315+
self.prompt_install_vdf()
316+
else:
317+
d = Adw.MessageDialog(heading="Error", body=f"Cannot load Steam configuration tool: {e}")
318+
d.add_response("ok", "OK")
319+
d.set_transient_for(self)
320+
d.present()
321+
322+
def prompt_install_vdf(self):
323+
d = Adw.MessageDialog(
324+
heading=_("Missing Dependency"),
325+
body=_("The 'vdf' module is required to configure Steam games. Do you want to install it now?")
326+
)
327+
d.add_response("cancel", _("Cancel"))
328+
d.add_response("install", _("Install"))
329+
d.set_response_appearance("install", Adw.ResponseAppearance.SUGGESTED)
330+
d.set_transient_for(self)
331+
d.connect("response", self.on_install_vdf_response)
332+
d.present()
333+
334+
def on_install_vdf_response(self, dialog, response):
335+
if response == "install":
336+
self.install_vdf()
337+
dialog.close()
338+
339+
def install_vdf(self):
340+
# Show a installing toast or dialog
341+
toast = Adw.Toast(title=_("Installing vdf module..."))
342+
self.toast_overlay.add_toast(toast)
343+
344+
def run_install():
345+
try:
346+
# Try pip install
347+
cmd = ["pip", "install", "vdf", "--break-system-packages"]
348+
subprocess.check_call(cmd)
349+
GLib.idle_add(self.on_install_success)
350+
except subprocess.CalledProcessError:
351+
# If failed, try without break-system-packages or with --user
352+
try:
353+
cmd = ["pip", "install", "--user", "vdf"]
354+
subprocess.check_call(cmd)
355+
GLib.idle_add(self.on_install_success)
356+
except Exception as e:
357+
GLib.idle_add(self.on_install_error, str(e))
358+
except Exception as e:
359+
GLib.idle_add(self.on_install_error, str(e))
360+
361+
threading.Thread(target=run_install, daemon=True).start()
362+
363+
def on_install_success(self):
364+
toast = Adw.Toast(title=_("Module installed successfully!"))
365+
self.toast_overlay.add_toast(toast)
366+
# Retry opening
367+
self.on_steam_config(None)
368+
369+
def on_install_error(self, error_msg):
370+
d = Adw.MessageDialog(heading=_("Installation Failed"), body=f"Could not install vdf: {error_msg}")
371+
d.add_response("ok", "OK")
372+
d.set_transient_for(self)
373+
d.present()
317374

318375
def on_close(self, btn):
319376
self.close()

0 commit comments

Comments
 (0)