From afd479b9063249816ad40e315e85f397f8db5865 Mon Sep 17 00:00:00 2001 From: Faugus <112667550+Faugus@users.noreply.github.com> Date: Sun, 15 Dec 2024 09:33:04 -0300 Subject: [PATCH] Improved dark theming support --- faugus-launcher.py | 37 ++++++++++++++++--------------------- faugus-proton-manager.py | 12 +++++++++++- faugus-run.py | 12 +++++++++++- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/faugus-launcher.py b/faugus-launcher.py index 22d54eb..ae894a5 100644 --- a/faugus-launcher.py +++ b/faugus-launcher.py @@ -18,7 +18,7 @@ gi.require_version('Gtk', '3.0') 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') @@ -596,34 +596,19 @@ class Main(Gtk.Window): 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): @@ -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(): diff --git a/faugus-proton-manager.py b/faugus-proton-manager.py index 4198835..c95ee41 100644 --- a/faugus-proton-manager.py +++ b/faugus-proton-manager.py @@ -7,7 +7,7 @@ import tarfile 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") @@ -175,7 +175,17 @@ class ProtonDownloader(Gtk.Window): 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() diff --git a/faugus-run.py b/faugus-run.py index b3dffcb..5448093 100644 --- a/faugus-run.py +++ b/faugus-run.py @@ -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 @@ -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)")