1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
|
#!/usr/bin/python3
import os
import subprocess
import sys
import threading
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, Pango # type: ignore
from fungus.constants import (
fungus_version,
fungus_png,
fungus_proton_manager,
)
from fungus.config_manager import ConfigManager
from fungus.dialogs import show_warning_dialog
from fungus.dispatcher import GtkDispatcher
from fungus.utils import EntryTooltipMixin, pick_folder
from fungus.umu_manager import (
check_and_install_if_needed,
get_installed_umu_version,
get_latest_umu_version,
get_steamrt_last_check,
proton_to_steamrt_variant,
save_steamrt_last_check,
update_steam_runtime,
)
class SettingsDialog(EntryTooltipMixin, Gtk.Dialog):
def __init__(self, parent, dispatcher: GtkDispatcher | None = None):
"""Build the settings UI, load config, and wire up all handlers."""
# Initialize the Settings dialog
super().__init__(title="Settings", transient_for=parent, modal=True) # type: ignore[misc]
self.set_resizable(False)
self.set_icon_from_file(fungus_png)
self.parent = parent
self.dispatcher = dispatcher or GtkDispatcher(lambda _: None)
self.modified = False
css_provider = Gtk.CssProvider()
css = """
.required {
border-color: Red;
}
"""
css_provider.load_from_data(css.encode('utf-8'))
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
# Create checkbox for 'Start maximized' option
self.checkbox_start_maximized = Gtk.CheckButton(label="Start maximized")
self.checkbox_start_maximized.set_active(False)
# Widgets for Game Directories list
self.liststore_game_dirs = Gtk.ListStore(str)
self.treeview_game_dirs = Gtk.TreeView(model=self.liststore_game_dirs)
self.treeview_game_dirs.set_has_tooltip(True)
self.treeview_game_dirs.connect("query-tooltip", self._on_gamedirs_query_tooltip)
self.treeview_game_dirs.connect("button-press-event", self.on_gamedirs_button_press)
renderer_game_dirs = Gtk.CellRendererText()
renderer_game_dirs.set_property("ellipsize", 3)
column_game_dirs = Gtk.TreeViewColumn("", renderer_game_dirs, text=0)
self.treeview_game_dirs.set_headers_visible(False)
self.treeview_game_dirs.append_column(column_game_dirs)
scrolled_window_game_dirs = Gtk.ScrolledWindow()
scrolled_window_game_dirs.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scrolled_window_game_dirs.set_min_content_height(130)
scrolled_window_game_dirs.add(self.treeview_game_dirs)
self.button_add_gamedir = Gtk.Button()
self.button_add_gamedir.set_image(
Gtk.Image.new_from_icon_name("list-add-symbolic", Gtk.IconSize.BUTTON))
self.button_add_gamedir.set_tooltip_text("Add a game directory")
self.button_add_gamedir.connect("clicked", self.on_button_add_gamedir_clicked)
self.box_gamedirs_buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
self.box_gamedirs_buttons.pack_start(self.button_add_gamedir, False, False, 0)
# Popup menu for game directories list
self.gamedirs_context_menu = Gtk.Menu()
self.menu_item_remove_gamedir = Gtk.MenuItem(label="Remove")
self.menu_item_remove_gamedir.connect("activate", self.on_context_menu_remove_gamedir)
self.gamedirs_context_menu.append(self.menu_item_remove_gamedir)
self.gamedirs_context_menu.show_all()
self.grid_game_dirs = Gtk.Grid()
self.grid_game_dirs.set_row_spacing(10)
self.grid_game_dirs.set_column_spacing(10)
self.grid_game_dirs.set_margin_start(10)
self.grid_game_dirs.set_margin_end(10)
self.grid_game_dirs.set_margin_top(10)
self.grid_game_dirs.set_margin_bottom(10)
# Widgets for runner
self.combobox_runner = Gtk.ComboBoxText()
self.button_proton_manager = Gtk.Button(label="Proton Manager")
self.button_proton_manager.set_image(
Gtk.Image.new_from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON))
self.button_proton_manager.set_image_position(Gtk.PositionType.LEFT)
self.button_proton_manager.connect("clicked", self.on_button_proton_manager_clicked)
# ── UMU-Launcher section ────────────────────────────────────────────
self.label_umu = Gtk.Label(label="UMU-Launcher")
self.label_umu.set_halign(Gtk.Align.START)
self.label_umu_installed = Gtk.Label(label="Not installed")
self.label_umu_installed.set_halign(Gtk.Align.START)
self.label_umu_installed.set_margin_start(10)
self.label_umu_installed.set_max_width_chars(12)
self.label_umu_installed.set_ellipsize(Pango.EllipsizeMode.END)
self.label_umu_latest = Gtk.Label(label="N/A")
self.label_umu_latest.set_halign(Gtk.Align.START)
self.label_umu_latest.set_margin_start(10)
self.label_umu_latest.set_max_width_chars(12)
self.label_umu_latest.set_ellipsize(Pango.EllipsizeMode.END)
self.button_umu_check = Gtk.Button(label="Check for Updates")
self.button_umu_check.set_image(
Gtk.Image.new_from_icon_name("view-refresh-symbolic", Gtk.IconSize.BUTTON))
self.button_umu_check.set_image_position(Gtk.PositionType.LEFT)
self.button_umu_check.connect("clicked", self.on_button_umu_check_clicked)
self.button_umu_check.set_size_request(140, -1)
self.button_umu_download = Gtk.Button(label="Download UMU")
self.button_umu_download.set_image(
Gtk.Image.new_from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON))
self.button_umu_download.set_image_position(Gtk.PositionType.LEFT)
self.button_umu_download.connect("clicked", self.on_button_umu_download_clicked)
self.button_umu_download.set_size_request(140, -1)
self.button_umu_download.set_sensitive(False)
self.button_umu_download.hide()
self.progress_umu = Gtk.ProgressBar()
self.progress_umu.set_visible(False)
self.progress_umu.set_hexpand(True)
# ── Steam Runtime section ─────────────────────────────────────────
self.label_steam_runtime = Gtk.Label(label="Steam Runtime")
self.label_steam_runtime.set_halign(Gtk.Align.START)
self.label_steam_runtime_status = Gtk.Label(label="Not checked")
self.label_steam_runtime_status.set_halign(Gtk.Align.START)
self.label_steam_runtime_status.set_margin_start(10)
self.label_steam_runtime_status.set_max_width_chars(20)
self.label_steam_runtime_status.set_ellipsize(Pango.EllipsizeMode.END)
self.label_steam_runtime_variant = Gtk.Label(label="Expected: steamrt3")
self.label_steam_runtime_variant.set_halign(Gtk.Align.START)
self.label_steam_runtime_variant.set_margin_start(10)
self.label_steam_runtime_variant.set_max_width_chars(20)
self.label_steam_runtime_variant.set_ellipsize(Pango.EllipsizeMode.END)
self.label_steam_runtime_variant.set_sensitive(False) # greyed out until runner selected
self.button_steam_runtime = Gtk.Button(label="Update Runtime")
self.button_steam_runtime.set_image(
Gtk.Image.new_from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON))
self.button_steam_runtime.set_image_position(Gtk.PositionType.LEFT)
self.button_steam_runtime.connect("clicked", self.on_button_steam_runtime_clicked)
self.button_steam_runtime.set_size_request(140, -1)
self.progress_steam_runtime = Gtk.ProgressBar()
self.progress_steam_runtime.set_visible(False)
self.progress_steam_runtime.set_hexpand(True)
self.label_miscellaneous = Gtk.Label(label="Miscellaneous")
self.label_miscellaneous.set_halign(Gtk.Align.START)
self.label_miscellaneous.set_margin_start(10)
self.label_miscellaneous.set_margin_end(10)
#self.label_miscellaneous.set_margin_top(10)
# Create checkbox for 'Use discrete GPU' option
self.checkbox_discrete_gpu = Gtk.CheckButton(label="Use discrete GPU")
self.checkbox_discrete_gpu.set_active(False)
self.checkbox_show_hidden = Gtk.CheckButton(label="Show hidden games")
self.checkbox_show_hidden.set_active(False)
self.checkbox_show_hidden.set_tooltip_text("Press Ctrl+H to show/hide games.")
# Checkboxes for optional features
# Button Cancel
self.button_cancel = Gtk.Button(label="Cancel")
self.button_cancel.set_image(
Gtk.Image.new_from_icon_name("process-stop-symbolic", Gtk.IconSize.BUTTON))
self.button_cancel.set_image_position(Gtk.PositionType.LEFT)
self.button_cancel.connect("clicked", lambda widget: self.response(Gtk.ResponseType.CANCEL))
self.button_cancel.set_size_request(150, -1)
# Button Ok
self.button_ok = Gtk.Button(label="Ok")
self.button_ok.set_image(
Gtk.Image.new_from_icon_name("dialog-ok-symbolic", Gtk.IconSize.BUTTON))
self.button_ok.set_image_position(Gtk.PositionType.LEFT)
self.button_ok.connect("clicked", lambda widget: self.response(Gtk.ResponseType.OK))
self.button_ok.set_size_request(150, -1)
self.liststore = Gtk.ListStore(str)
self.liststore.append([""])
treeview = Gtk.TreeView(model=self.liststore)
treeview.set_has_tooltip(True)
treeview.connect("query-tooltip", self._on_env_query_tooltip)
treeview.connect("key-press-event", self.on_envar_key_press)
renderer = Gtk.CellRendererText()
renderer.set_property("editable", True)
renderer.set_property("ellipsize", 3)
renderer.connect("edited", self.on_cell_edited, 0)
column = Gtk.TreeViewColumn("", renderer, text=0)
treeview.set_headers_visible(False)
treeview.append_column(column)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scrolled_window.set_min_content_height(130)
scrolled_window.add(treeview)
self.box = self.get_content_area()
self.box.set_margin_start(0)
self.box.set_margin_end(0)
self.box.set_margin_top(0)
self.box.set_margin_bottom(0)
self.box.set_halign(Gtk.Align.CENTER)
self.box.set_valign(Gtk.Align.CENTER)
self.box.set_vexpand(True)
self.box.set_hexpand(True)
label_version = Gtk.Label()
label_version.set_text(fungus_version)
frame = Gtk.Frame()
frame.set_label_widget(label_version)
frame.set_label_align(0.99, 0.5)
frame.set_margin_start(10)
frame.set_margin_end(10)
frame.set_margin_bottom(10)
frame.set_margin_top(10)
box_main = Gtk.Grid()
box_main.set_column_homogeneous(True)
box_main.set_column_spacing(10)
box_left = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
grid_runner = Gtk.Grid()
grid_runner.set_row_spacing(10)
grid_runner.set_column_spacing(10)
grid_runner.set_margin_start(10)
grid_runner.set_margin_end(10)
grid_runner.set_margin_top(10)
grid_runner.set_margin_bottom(10)
grid_umu = Gtk.Grid()
grid_umu.set_row_spacing(6)
grid_umu.set_column_spacing(10)
grid_umu.set_margin_start(10)
grid_umu.set_margin_end(10)
grid_umu.set_margin_top(10)
grid_umu.set_margin_bottom(10)
grid_miscellaneous = Gtk.Grid()
grid_miscellaneous.set_row_spacing(10)
grid_miscellaneous.set_column_spacing(10)
grid_miscellaneous.set_margin_start(10)
grid_miscellaneous.set_margin_end(10)
grid_miscellaneous.set_margin_top(10)
grid_miscellaneous.set_margin_bottom(10)
grid_envar = Gtk.Grid()
grid_envar.set_row_spacing(10)
grid_envar.set_column_spacing(10)
grid_envar.set_margin_start(10)
grid_envar.set_margin_end(10)
grid_envar.set_margin_top(10)
grid_envar.set_margin_bottom(10)
grid_support = Gtk.Grid()
grid_support.set_column_homogeneous(True)
grid_support.set_row_spacing(10)
grid_support.set_column_spacing(10)
grid_support.set_margin_start(10)
grid_support.set_margin_end(10)
grid_support.set_margin_top(10)
grid_support.set_margin_bottom(10)
self.grid_game_dirs.attach(scrolled_window_game_dirs, 0, 1, 1, 1)
scrolled_window_game_dirs.set_hexpand(True)
self.grid_game_dirs.attach(self.box_gamedirs_buttons, 0, 2, 1, 1)
grid_runner.attach(self.combobox_runner, 0, 7, 1, 1)
grid_runner.attach(self.button_proton_manager, 0, 8, 1, 1)
self.combobox_runner.set_hexpand(True)
self.button_proton_manager.set_hexpand(True)
# UMU section
grid_umu.attach(self.label_umu, 0, 0, 1, 1)
grid_umu.attach(self.label_umu_installed, 0, 1, 1, 1)
grid_umu.attach(self.label_umu_latest, 0, 2, 1, 1)
grid_umu.attach(self.button_umu_check, 0, 3, 1, 1)
grid_umu.attach(self.button_umu_download, 1, 3, 1, 1)
grid_umu.attach(self.progress_umu, 0, 4, 2, 1)
# Steam Runtime section
self.label_steam_runtime_last = Gtk.Label(label="Last checked: -")
self.label_steam_runtime_last.set_halign(Gtk.Align.START)
self.label_steam_runtime_last.set_margin_start(10)
self.label_steam_runtime_last.set_max_width_chars(30)
self.label_steam_runtime_last.set_ellipsize(Pango.EllipsizeMode.END)
grid_umu.attach(self.label_steam_runtime, 0, 5, 1, 1)
grid_umu.attach(self.label_steam_runtime_variant, 0, 6, 1, 1)
grid_umu.attach(self.label_steam_runtime_status, 0, 7, 1, 1)
grid_umu.attach(self.label_steam_runtime_last, 0, 8, 1, 1)
grid_umu.attach(self.button_steam_runtime, 0, 9, 1, 1)
grid_umu.attach(self.progress_steam_runtime, 0, 10, 2, 1)
grid_miscellaneous.attach(self.checkbox_discrete_gpu, 0, 2, 1, 1)
grid_miscellaneous.attach(self.checkbox_show_hidden, 0, 3, 1, 1)
grid_envar.attach(scrolled_window, 0, 1, 1, 1)
scrolled_window.set_hexpand(True)
# Wrap each logical section in a Gtk.Frame for visual grouping
frame_game_dirs = Gtk.Frame(label="Game Directories")
frame_game_dirs.set_label_align(0.0, 0.5)
frame_game_dirs.set_shadow_type(Gtk.ShadowType.IN)
frame_game_dirs.add(self.grid_game_dirs)
frame_game_dirs.set_border_width(5)
frame_runner = Gtk.Frame(label="Default Proton")
frame_runner.set_label_align(0.0, 0.5)
frame_runner.set_shadow_type(Gtk.ShadowType.IN)
frame_runner.add(grid_runner)
frame_runner.set_border_width(5)
frame_umu = Gtk.Frame(label="UMU-Launcher & Steam Runtime")
frame_umu.set_label_align(0.0, 0.5)
frame_umu.set_shadow_type(Gtk.ShadowType.IN)
frame_umu.add(grid_umu)
frame_umu.set_border_width(5)
frame_envar = Gtk.Frame(label="Global Environment Variables")
frame_envar.set_label_align(0.0, 0.5)
frame_envar.set_shadow_type(Gtk.ShadowType.IN)
frame_envar.add(grid_envar)
frame_envar.set_border_width(5)
frame_miscellaneous = Gtk.Frame(label="Miscellaneous")
frame_miscellaneous.set_label_align(0.0, 0.5)
frame_miscellaneous.set_shadow_type(Gtk.ShadowType.IN)
frame_miscellaneous.add(grid_miscellaneous)
frame_miscellaneous.set_border_width(5)
box_left.pack_start(frame_game_dirs, False, False, 0)
box_left.pack_start(frame_runner, False, False, 0)
box_left.pack_start(frame_miscellaneous, False, False, 0)
box_right.pack_start(frame_envar, False, False, 0)
box_right.pack_start(frame_umu, False, False, 0)
box_main.attach(box_left, 0, 0, 1, 1)
box_main.attach(box_right, 1, 0, 1, 1)
box_left.set_hexpand(True)
frame.add(box_main)
box_bottom = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
box_bottom.set_margin_start(10)
box_bottom.set_margin_end(10)
box_bottom.set_margin_bottom(10)
self.button_cancel.set_hexpand(True)
self.button_ok.set_hexpand(True)
box_bottom.pack_start(self.button_cancel, True, True, 0)
box_bottom.pack_start(self.button_ok, True, True, 0)
self.box.add(frame)
self.box.add(box_bottom)
self.populate_combobox_with_runners()
self.combobox_runner.connect("changed", self._on_runner_changed)
self.load_config()
self._update_runtime_variant()
self.show_all()
self.progress_umu.set_visible(False)
self.progress_steam_runtime.set_visible(False)
self.track_modifications(self.box)
def on_envar_key_press(self, widget, event):
"""Allow deleting environment variable rows via the Delete key (but not the last empty row)."""
if event.keyval == Gdk.KEY_Delete:
selection = widget.get_selection()
model, treeiter = selection.get_selected()
if not treeiter:
return False
path = model.get_path(treeiter)
index = path.get_indices()[0]
if index == len(model) - 1:
return True
model.remove(treeiter)
return True
return False
def on_gamedirs_button_press(self, widget, event):
"""Show the context menu on right-click within the game directories treeview."""
if event.button == 3: # right-click
selection = widget.get_selection()
_, treeiter = selection.get_selected()
if treeiter:
self.gamedirs_context_menu.popup_at_pointer(event)
return True
return False
def on_context_menu_remove_gamedir(self, widget):
"""Remove the selected game directory from the liststore."""
selection = self.treeview_game_dirs.get_selection()
model, treeiter = selection.get_selected()
if treeiter:
model.remove(treeiter)
def get_dir_size(self, path):
"""Calculate and format the total size of *path* (e.g. '2.5 GB')."""
total = 0
for dirpath, _, filenames in os.walk(path):
for f in filenames:
fp = os.path.join(dirpath, f)
if os.path.isfile(fp):
total += os.path.getsize(fp)
for unit in ['B', 'KB', 'MB', 'GB']:
if total < 1024.0:
return f"{total:.1f} {unit}"
total /= 1024.0
return f"{total:.1f} TB"
def _on_env_query_tooltip(self, widget, x, y, keyboard_mode, tooltip):
"""Tooltip handler for the environment variable treeview."""
return self.on_list_query_tooltip(widget, x, y, keyboard_mode, tooltip, self.liststore)
def _on_gamedirs_query_tooltip(self, widget, x, y, keyboard_mode, tooltip):
"""Tooltip handler for the game directories treeview."""
return self.on_list_query_tooltip(widget, x, y, keyboard_mode, tooltip, self.liststore_game_dirs)
def on_cell_edited(self, widget, path, text, column_index):
"""Update the liststore cell and normalize empty rows."""
self.liststore[path][column_index] = text
self.adjust_rows()
def adjust_rows(self):
"""Remove empty rows from the liststore and ensure a trailing empty row."""
filled_rows = [row[0] for row in self.liststore if row[0].strip() != ""]
self.liststore.clear()
for value in filled_rows:
self.liststore.append([value])
self.liststore.append([""])
def on_button_add_gamedir_clicked(self, widget):
"""Open a folder chooser and append the selected directory to the game directories list."""
folder = pick_folder("Select a game directory", self)
if folder and not any(row[0] == folder for row in self.liststore_game_dirs):
self.liststore_game_dirs.append([folder])
def populate_combobox_with_runners(self):
"""Fill the Proton runner combobox with available runners."""
from fungus.utils import populate_combobox_with_runners as _pop
_pop(self.combobox_runner)
def _on_runner_changed(self, combobox):
"""Handle runner selection change: update runtime variant display."""
self._update_runtime_variant()
def _update_runtime_variant(self):
"""Update the runtime variant label based on the selected Proton runner."""
runner = self.combobox_runner.get_active_text()
if runner:
variant = proton_to_steamrt_variant(runner)
self.label_steam_runtime_variant.set_text(f"Expected: {variant}")
self.label_steam_runtime_variant.set_sensitive(True)
else:
self.label_steam_runtime_variant.set_text("Expected: steamrt3")
self.label_steam_runtime_variant.set_sensitive(False)
def on_entry_changed(self, widget, entry):
"""Remove the 'required' CSS class once the entry has text."""
if entry.get_text():
entry.get_style_context().remove_class("required")
def update_config_file(self):
"""Persist all settings (runner, GPU, hidden, game dirs) to the config file."""
combobox_default_runner = self.get_default_runner()
checkbox_discrete_gpu_state = self.checkbox_discrete_gpu.get_active()
checkbox_show_hidden = self.checkbox_show_hidden.get_active()
config = ConfigManager()
config.set("default-runner", combobox_default_runner)
config.set("discrete-gpu", str(checkbox_discrete_gpu_state))
config.set("show-hidden", str(checkbox_show_hidden))
# Save game directories liststore to config
gamedirs = [row[0].strip() for row in self.liststore_game_dirs if row[0].strip() != ""]
config.set("game-directories", ','.join(gamedirs))
config.save()
self.set_sensitive(False)
def get_default_runner(self):
"""Return the currently selected runner text from the combobox."""
return self.combobox_runner.get_active_text()
def update_envar_file(self):
"""Write all non-empty environment variable rows to config.ini."""
if hasattr(self, "liststore"):
values = [row[0] for row in self.liststore if row[0].strip() != ""]
cfg = ConfigManager()
cfg.set_envars(values)
cfg.save()
def on_button_proton_manager_clicked(self, widget):
"""Launch the Proton Manager dialog as a blocking child window."""
proton_manager = fungus_proton_manager
current_runner = self.combobox_runner.get_active_text()
def run_command():
process = subprocess.Popen([sys.executable, proton_manager])
process.wait()
self.dispatcher.submit(self.set_sensitive, True)
self.dispatcher.submit(self.parent.set_sensitive, True)
self.dispatcher.submit(self.blocking_window.destroy)
self.dispatcher.submit(self.combobox_runner.remove_all)
self.dispatcher.submit(self.populate_combobox_with_runners)
def restore_selection():
if current_runner:
for i, text in enumerate(self.combobox_runner.get_model()):
if text[0] == current_runner:
self.combobox_runner.set_active(i)
break
self.dispatcher.submit(restore_selection)
self.blocking_window = Gtk.Window()
self.blocking_window.set_transient_for(self.parent)
self.blocking_window.set_decorated(False)
self.blocking_window.set_modal(True)
command_thread = threading.Thread(target=run_command)
command_thread.start()
# ── UMU-Launcher handlers ───────────────────────────────────────────
def on_button_umu_check_clicked(self, widget):
"""Check for the latest UMU-Launcher version."""
widget.set_sensitive(False)
self.label_umu_latest.set_text("Checking…")
self.progress_umu.set_visible(True)
self.progress_umu.set_fraction(0.0)
self.progress_umu.set_text("Checking…")
def check_thread():
latest = get_latest_umu_version()
self.dispatcher.submit(self._on_umu_version_checked, latest, widget)
threading.Thread(target=check_thread, daemon=True).start()
def _on_umu_version_checked(self, latest, widget):
"""Callback after version check completes."""
widget.set_sensitive(True)
self.progress_umu.set_visible(False)
if latest is None:
self.label_umu_latest.set_text("Could not check")
return
installed = get_installed_umu_version()
self.label_umu_latest.set_text(latest)
if installed and latest != installed:
self.button_umu_download.set_label("Update UMU")
self.button_umu_download.set_sensitive(True)
self.button_umu_download.show()
elif not installed:
self.button_umu_download.set_label("Download UMU")
self.button_umu_download.set_sensitive(True)
self.button_umu_download.show()
else:
self.button_umu_download.set_sensitive(False)
self.button_umu_download.show()
def on_button_umu_download_clicked(self, widget):
"""Download UMU-Launcher in a background thread."""
widget.set_sensitive(False)
self.progress_umu.set_visible(True)
self.progress_umu.set_fraction(0.0)
self.progress_umu.set_text("0%")
def download_thread():
def progress_cb(percent):
self.dispatcher.submit(self.progress_umu.set_fraction, percent / 100.0)
self.dispatcher.submit(self.progress_umu.set_text, f"{percent}%")
success, status = check_and_install_if_needed(progress_callback=progress_cb)
self.dispatcher.submit(self.progress_umu.set_visible, False)
self.dispatcher.submit(self._on_umu_download_done, success, status)
threading.Thread(target=download_thread, daemon=True).start()
def _on_umu_download_done(self, success, status):
"""Callback after UMU download completes."""
self.button_umu_check.set_sensitive(True)
self.button_umu_download.set_sensitive(False)
if success:
installed = get_installed_umu_version()
self.label_umu_installed.set_text(installed)
self.button_umu_download.hide()
if status == "up_to_date":
info_dialog = Gtk.MessageDialog(
parent=self.parent,
flags=Gtk.DialogFlags.MODAL,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text="UMU-Launcher is up to date",
)
info_dialog.format_secondary_text(
"The UMU-Launcher is already at the latest version.",
)
info_dialog.run()
info_dialog.destroy()
elif status == "updated":
info_dialog = Gtk.MessageDialog(
parent=self.parent,
flags=Gtk.DialogFlags.MODAL,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text="UMU-Launcher updated",
)
info_dialog.format_secondary_text(
"The UMU-Launcher has been updated successfully.",
)
info_dialog.run()
info_dialog.destroy()
elif status == "installed":
info_dialog = Gtk.MessageDialog(
parent=self.parent,
flags=Gtk.DialogFlags.MODAL,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text="UMU-Launcher installed",
)
info_dialog.format_secondary_text(
"The UMU-Launcher has been installed successfully.",
)
info_dialog.run()
info_dialog.destroy()
else:
error_dialog = Gtk.MessageDialog(
parent=self.parent,
flags=Gtk.DialogFlags.MODAL,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.OK,
text="Download failed",
)
error_dialog.format_secondary_text(
"Could not download UMU-Launcher. "
"Please check your internet connection and try again.")
error_dialog.run()
error_dialog.destroy()
def on_button_steam_runtime_clicked(self, widget):
"""Trigger Steam Runtime download/update in a background thread."""
widget.set_sensitive(False)
self.progress_steam_runtime.set_visible(True)
self.progress_steam_runtime.set_fraction(0.0)
self.progress_steam_runtime.set_text("0%")
self.label_steam_runtime_status.set_text("Updating…")
def runtime_thread():
runner = self.get_default_runner()
if not runner:
self.dispatcher.submit(self._on_runtime_done, False, "No Proton selected")
return
def update_progress(line):
self.dispatcher.submit(self.progress_steam_runtime.set_text, line.strip())
def progress_cb(percent):
self.dispatcher.submit(self.progress_steam_runtime.set_fraction, percent / 100.0)
self.dispatcher.submit(update_progress, "Updating…")
def on_success():
save_steamrt_last_check()
success, message = update_steam_runtime(
runner, progress_callback=progress_cb, on_success=on_success
)
self.dispatcher.submit(self._on_runtime_done, success, message)
threading.Thread(target=runtime_thread, daemon=True).start()
def _on_runtime_done(self, success: bool, message: str) -> bool:
"""Callback after Steam Runtime update completes."""
self.button_steam_runtime.set_sensitive(True)
self.progress_steam_runtime.set_visible(False)
self.label_steam_runtime_status.set_text(message)
if success:
self.progress_steam_runtime.set_fraction(1.0)
else:
error_dialog = Gtk.MessageDialog(
parent=self.parent,
flags=Gtk.DialogFlags.MODAL,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.OK,
text="Runtime update failed",
)
error_dialog.format_secondary_text(message)
error_dialog.run()
error_dialog.destroy()
return False
def track_modifications(self, container):
"""Recursively connect 'changed' / 'toggled' / 'modified' callbacks to detect unsaved changes."""
for child in container.get_children():
if isinstance(child, Gtk.Entry):
child.connect("changed", lambda w: setattr(self, "modified", True))
elif isinstance(child, Gtk.CheckButton):
child.connect("toggled", lambda w: setattr(self, "modified", True))
elif isinstance(child, Gtk.ComboBox):
child.connect("changed", lambda w: setattr(self, "modified", True))
elif isinstance(child, Gtk.TreeView):
selection = child.get_selection()
selection.connect("changed", lambda sel: setattr(self, "modified", True))
elif isinstance(child, Gtk.Container):
self.track_modifications(child)
def check_modified(self):
"""Prompt the user to save unsaved changes before closing the dialog."""
self.track_modifications(self.box)
if self.modified:
proceed = self.show_warning_dialog2(self.parent, "Do you want to save the changes?")
if proceed:
self.update_envar_file()
self.update_config_file()
self.modified = False
else:
self.load_config()
self.modified = False
def show_warning_dialog(self, parent, title):
"""Delegate to the shared warning-dialog utility."""
return show_warning_dialog(parent, title)
def show_warning_dialog2(self, parent, title):
"""Show a confirmation dialog (yes/no) via the shared utility."""
return show_warning_dialog(parent, title, confirm=True)
def load_config(self):
"""Load all settings from the config file and populate the UI controls."""
cfg = ConfigManager()
self.default_runner = cfg.get('default-runner', '')
discrete_gpu = cfg.get_bool('discrete-gpu', False)
start_maximized = cfg.get_bool('start-maximized', False)
show_hidden = cfg.get_bool('show-hidden', False)
game_dirs_str = cfg.get('game-directories', '').strip()
model_runner = self.combobox_runner.get_model()
index_runner = 0
for i, row in enumerate(model_runner):
if row[0] == self.default_runner:
index_runner = i
break
self.combobox_runner.set_active(index_runner)
self.checkbox_discrete_gpu.set_active(discrete_gpu)
self.checkbox_start_maximized.set_active(start_maximized)
self.checkbox_show_hidden.set_active(show_hidden)
# Populate game directories liststore
if game_dirs_str:
paths = [p.strip() for p in game_dirs_str.split(',') if p.strip()]
self.liststore_game_dirs.clear()
for path in paths:
self.liststore_game_dirs.append([path])
self._load_liststore_from_config()
# Load UMU-Launcher version info
installed = get_installed_umu_version()
if installed:
self.label_umu_installed.set_text(installed)
else:
self.label_umu_installed.set_text("Not installed")
# Load Steam Runtime last-check time
last_check = get_steamrt_last_check()
if last_check:
self.label_steam_runtime_last.set_text(f"Last checked: {last_check}")
else:
self.label_steam_runtime_last.set_text("Last checked: -")
def _load_liststore_from_config(self):
"""Read global environment variable lines from config.ini and populate the liststore."""
self.liststore.clear()
cfg = ConfigManager()
lines = cfg.get_envars()
for line in lines:
self.liststore.append([line])
self.liststore.append([""])
|