Skip to content

Commit

Permalink
Improved dark theming support
Browse files Browse the repository at this point in the history
  • Loading branch information
Faugus authored Dec 15, 2024
1 parent 9754074 commit afd479b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
37 changes: 16 additions & 21 deletions faugus-launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
gi.require_version('Gdk', '3.0')
gi.require_version('AppIndicator3', '0.1')

from gi.repository import Gtk, Gdk, GdkPixbuf, GLib, AppIndicator3
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib, AppIndicator3, Gio
from PIL import Image

xdg_data_dirs = os.getenv('XDG_DATA_DIRS', '/usr/local/share:/usr/share')
Expand Down Expand Up @@ -596,34 +596,19 @@ def on_button_bye_clicked(self, widget):
menu.show_all()
menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())

def show_confirmation_dialog(self, message):
dialog = Gtk.MessageDialog(
transient_for=self,
flags=0,
title="Faugus Launcher",
message_type=Gtk.MessageType.QUESTION,
buttons=Gtk.ButtonsType.OK_CANCEL,
text=message,
)
response = dialog.run()
dialog.destroy()
return response == Gtk.ResponseType.OK

def on_shutdown(self, widget):
if self.show_confirmation_dialog("Are you sure you want to shut down?"):
subprocess.run(["pkexec", "shutdown", "-h", "now"])
subprocess.run(["pkexec", "shutdown", "-h", "now"])

def on_reboot(self, widget):
if self.show_confirmation_dialog("Are you sure you want to reboot?"):
subprocess.run(["pkexec", "reboot"])
subprocess.run(["pkexec", "reboot"])

def on_logout(self, widget):
if self.show_confirmation_dialog("Are you sure you want to log out?"):
subprocess.run(["loginctl", "terminate-user", os.getlogin()])
subprocess.run(["loginctl", "terminate-user", os.getlogin()])

def on_close(self, widget):
if os.path.exists(lock_file_path):
os.remove(lock_file_path)
os.remove(lock_file_path)

Gtk.main_quit()

def on_item_right_click(self, widget, event):
Expand Down Expand Up @@ -5100,8 +5085,18 @@ def convert_games_txt_to_json(txt_file_path, json_file_path):
old_file_path = txt_file_path.replace(".txt", "-old.txt")
os.rename(txt_file_path, old_file_path)

def apply_dark_theme():
desktop_env = Gio.Settings.new("org.gnome.desktop.interface")
try:
is_dark_theme = desktop_env.get_string("color-scheme") == "prefer-dark"
except Exception:
is_dark_theme = "-dark" in desktop_env.get_string("gtk-theme")
if is_dark_theme:
Gtk.Settings.get_default().set_property("gtk-application-prefer-dark-theme", True)

def main():
convert_games_txt_to_json(games_txt, games_json)
apply_dark_theme()
if len(sys.argv) == 1:
app = Main()
if is_already_running():
Expand Down
12 changes: 11 additions & 1 deletion faugus-proton-manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import shutil

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import Gtk, Gio

GITHUB_API_URL = "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases"
STEAM_COMPATIBILITY_PATH = os.path.expanduser("~/.local/share/Steam/compatibilitytools.d")
Expand Down Expand Up @@ -175,7 +175,17 @@ def on_remove_clicked(self, widget, release):
def update_button(self, button, new_label):
button.set_label(new_label) # Update the button label

def apply_dark_theme():
desktop_env = Gio.Settings.new("org.gnome.desktop.interface")
try:
is_dark_theme = desktop_env.get_string("color-scheme") == "prefer-dark"
except Exception:
is_dark_theme = "-dark" in desktop_env.get_string("gtk-theme")
if is_dark_theme:
Gtk.Settings.get_default().set_property("gtk-application-prefer-dark-theme", True)

# Initialize GTK application
apply_dark_theme()
win = ProtonDownloader()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Expand Down
12 changes: 11 additions & 1 deletion faugus-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, GdkPixbuf
from gi.repository import Gtk, GLib, GdkPixbuf, Gio
from threading import Thread

import atexit
Expand Down Expand Up @@ -435,7 +435,17 @@ def stop_scc_daemon():
except subprocess.CalledProcessError as e:
print(f"Failed to stop scc-daemon: {e}")

def apply_dark_theme():
desktop_env = Gio.Settings.new("org.gnome.desktop.interface")
try:
is_dark_theme = desktop_env.get_string("color-scheme") == "prefer-dark"
except Exception:
is_dark_theme = "-dark" in desktop_env.get_string("gtk-theme")
if is_dark_theme:
Gtk.Settings.get_default().set_property("gtk-application-prefer-dark-theme", True)

def main():
apply_dark_theme()
parser = argparse.ArgumentParser(description="Faugus Run")
parser.add_argument("message", help="The message to be processed")
parser.add_argument("command", nargs='?', default=None, help="The command to be executed (optional)")
Expand Down

0 comments on commit afd479b

Please sign in to comment.