Improved dark theming support

This commit is contained in:
Faugus
2024-12-15 09:33:04 -03:00
committed by GitHub
parent 9754074798
commit afd479b906
3 changed files with 38 additions and 23 deletions
+16 -21
View File
@@ -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():
+11 -1
View File
@@ -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()
+11 -1
View File
@@ -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)")