2022-09-01 15:37:21 +00:00
|
|
|
# flatpak_overrides.py
|
|
|
|
#
|
|
|
|
# Change the look of Adwaita, with ease
|
|
|
|
# Copyright (C) 2022 Gradience Team
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from gi.repository import GLib, Gio, Adw
|
|
|
|
|
2022-10-10 19:45:47 +00:00
|
|
|
from gradience.utils.utils import buglog
|
2022-09-01 15:37:21 +00:00
|
|
|
|
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
""" Custom exception class """
|
|
|
|
|
|
|
|
|
2022-09-01 15:53:59 +00:00
|
|
|
class InvalidGTKVersion(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
""" Internal helper functions (shouldn't be used outside this file) """
|
|
|
|
|
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
def get_system_flatpak_path():
|
|
|
|
systemPath = GLib.getenv("FLATPAK_SYSTEM_DIR")
|
|
|
|
buglog(f"systemPath: {systemPath}")
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
if systemPath:
|
|
|
|
return systemPath
|
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
systemDataDir = GLib.build_filenamev([GLib.DIR_SEPARATOR_S, "var", "lib"])
|
2022-09-01 15:37:21 +00:00
|
|
|
|
|
|
|
return GLib.build_filenamev([systemDataDir, "flatpak"])
|
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
def get_user_flatpak_path():
|
|
|
|
userPath = GLib.getenv("FLATPAK_USER_DIR")
|
|
|
|
buglog(f"userPath: {userPath}")
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
if userPath:
|
|
|
|
return userPath
|
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
userDataDir = GLib.build_filenamev(
|
|
|
|
[GLib.get_home_dir(), ".local", "share"])
|
2022-09-01 15:37:21 +00:00
|
|
|
|
|
|
|
return GLib.build_filenamev([userDataDir, "flatpak"])
|
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-09-23 11:14:21 +00:00
|
|
|
def user_save_keyfile(toast_overlay, settings, user_keyfile, filename, gtk_ver):
|
2022-09-01 15:37:21 +00:00
|
|
|
try:
|
|
|
|
user_keyfile.save_to_file(filename)
|
2022-09-22 17:53:05 +00:00
|
|
|
except GLib.GError as e:
|
2022-09-01 15:37:21 +00:00
|
|
|
toast_overlay.add_toast(Adw.Toast(title=_("Failed to save override")))
|
|
|
|
buglog(f"Failed to save keyfile structure to override. Exc: {e}")
|
|
|
|
else:
|
2022-09-03 20:47:45 +00:00
|
|
|
if gtk_ver == "gtk4":
|
|
|
|
settings.set_boolean("user-flatpak-theming-gtk4", True)
|
|
|
|
buglog(
|
2022-09-07 15:51:36 +00:00
|
|
|
f"user-flatpak-theming-gtk4: {settings.get_boolean('user-flatpak-theming-gtk4')}"
|
|
|
|
)
|
2022-09-03 20:47:45 +00:00
|
|
|
elif gtk_ver == "gtk3":
|
|
|
|
settings.set_boolean("user-flatpak-theming-gtk3", True)
|
|
|
|
buglog(
|
2022-09-07 15:51:36 +00:00
|
|
|
f"user-flatpak-theming-gtk3: {settings.get_boolean('user-flatpak-theming-gtk3')}"
|
|
|
|
)
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
|
2022-09-23 11:14:21 +00:00
|
|
|
def global_save_keyfile(toast_overlay, settings, global_keyfile, filename, gtk_ver):
|
2022-09-01 15:37:21 +00:00
|
|
|
try:
|
|
|
|
global_keyfile.save_to_file(filename)
|
2022-09-22 17:53:05 +00:00
|
|
|
except GLib.GError as e:
|
2022-09-01 15:37:21 +00:00
|
|
|
toast_overlay.add_toast(Adw.Toast(title=_("Failed to save override")))
|
|
|
|
buglog(f"Failed to save keyfile structure to override. Exc: {e}")
|
|
|
|
else:
|
2022-09-03 20:47:45 +00:00
|
|
|
if gtk_ver == "gtk4":
|
|
|
|
settings.set_boolean("global-flatpak-theming-gtk4", True)
|
|
|
|
buglog(
|
2022-09-07 15:51:36 +00:00
|
|
|
f"global-flatpak-theming-gtk4: {settings.get_boolean('global-flatpak-theming-gtk4')}"
|
|
|
|
)
|
2022-09-03 20:47:45 +00:00
|
|
|
elif gtk_ver == "gtk3":
|
|
|
|
settings.set_boolean("global-flatpak-theming-gtk3", True)
|
|
|
|
buglog(
|
2022-09-07 15:51:36 +00:00
|
|
|
f"global-flatpak-theming-gtk3: {settings.get_boolean('global-flatpak-theming-gtk3')}"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
""" Main functions """
|
2022-09-01 15:37:21 +00:00
|
|
|
|
|
|
|
|
2022-09-03 20:47:45 +00:00
|
|
|
def create_gtk_user_override(toast_overlay, settings, gtk_ver):
|
2022-09-07 15:51:36 +00:00
|
|
|
override_dir = GLib.build_filenamev([get_user_flatpak_path(), "overrides"])
|
2022-09-24 18:53:53 +00:00
|
|
|
buglog(f"override_dir: {override_dir}")
|
2022-09-01 15:37:21 +00:00
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
filename = GLib.build_filenamev([override_dir, "global"])
|
2022-09-01 15:37:21 +00:00
|
|
|
|
|
|
|
user_keyfile = GLib.KeyFile.new()
|
|
|
|
|
2022-09-03 20:47:45 +00:00
|
|
|
is_gtk4 = gtk_ver == "gtk4"
|
|
|
|
is_gtk3 = gtk_ver == "gtk3"
|
|
|
|
if is_gtk4:
|
2022-09-01 15:53:59 +00:00
|
|
|
gtk_path = "xdg-config/gtk-4.0"
|
2022-09-03 20:47:45 +00:00
|
|
|
elif is_gtk3:
|
2022-09-01 15:53:59 +00:00
|
|
|
gtk_path = "xdg-config/gtk-3.0"
|
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
raise InvalidGTKVersion(
|
2022-09-07 15:51:36 +00:00
|
|
|
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3"
|
|
|
|
)
|
2022-09-01 15:53:59 +00:00
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
try:
|
|
|
|
user_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
|
|
|
except GLib.GError as e:
|
|
|
|
if e.code == 4:
|
|
|
|
buglog("File doesn't exist. Attempting to create one")
|
|
|
|
if not os.path.exists(override_dir):
|
|
|
|
try:
|
|
|
|
dirs = Gio.File.new_for_path(override_dir)
|
|
|
|
dirs.make_directory_with_parents(None)
|
|
|
|
except GLib.GError as e:
|
|
|
|
buglog(f"Unable to create directories. Exc: {e}")
|
2022-09-04 12:30:01 +00:00
|
|
|
if is_gtk4:
|
2022-09-05 16:40:09 +00:00
|
|
|
settings.set_boolean(
|
|
|
|
"user-flatpak-theming-gtk4", False)
|
2022-09-04 12:30:01 +00:00
|
|
|
elif is_gtk3:
|
2022-09-05 16:40:09 +00:00
|
|
|
settings.set_boolean(
|
|
|
|
"user-flatpak-theming-gtk3", False)
|
2022-09-04 12:30:01 +00:00
|
|
|
return
|
2022-09-01 15:37:21 +00:00
|
|
|
else:
|
|
|
|
buglog("Directories created.")
|
|
|
|
|
|
|
|
file = Gio.File.new_for_path(filename)
|
|
|
|
file.create(Gio.FileCreateFlags.NONE, None)
|
|
|
|
|
|
|
|
user_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
2022-09-01 16:19:45 +00:00
|
|
|
user_keyfile.set_string("Context", "filesystems", gtk_path)
|
2022-09-01 15:37:21 +00:00
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
user_save_keyfile(toast_overlay, settings,
|
|
|
|
user_keyfile, filename, gtk_ver)
|
2022-09-01 15:37:21 +00:00
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
toast_overlay.add_toast(
|
2022-09-07 15:51:36 +00:00
|
|
|
Adw.Toast(title=_("Unexpected file error occurred"))
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog(f"Unhandled GLib.FileError error code. Exc: {e}")
|
|
|
|
else:
|
|
|
|
try:
|
2022-09-01 16:19:45 +00:00
|
|
|
filesys_list = user_keyfile.get_string_list(
|
|
|
|
"Context", "filesystems")
|
2022-09-01 15:37:21 +00:00
|
|
|
except GLib.GError:
|
2022-09-01 15:53:59 +00:00
|
|
|
user_keyfile.set_string("Context", "filesystems", gtk_path)
|
2022-09-07 15:51:36 +00:00
|
|
|
user_save_keyfile(toast_overlay, settings,
|
|
|
|
user_keyfile, filename, gtk_ver)
|
2022-09-01 15:37:21 +00:00
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
if gtk_path not in filesys_list:
|
|
|
|
user_keyfile.set_string_list(
|
2022-09-07 15:51:36 +00:00
|
|
|
"Context", "filesystems", filesys_list + [gtk_path]
|
|
|
|
)
|
2022-09-01 16:19:45 +00:00
|
|
|
user_save_keyfile(
|
2022-09-07 15:51:36 +00:00
|
|
|
toast_overlay, settings, user_keyfile, filename, gtk_ver
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
else:
|
2022-09-03 20:47:45 +00:00
|
|
|
if is_gtk4:
|
|
|
|
settings.set_boolean("user-flatpak-theming-gtk4", True)
|
|
|
|
elif is_gtk3:
|
|
|
|
settings.set_boolean("user-flatpak-theming-gtk3", True)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("Value already exists.")
|
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-09-03 20:47:45 +00:00
|
|
|
def remove_gtk_user_override(toast_overlay, settings, gtk_ver):
|
2022-09-07 15:51:36 +00:00
|
|
|
override_dir = GLib.build_filenamev([get_user_flatpak_path(), "overrides"])
|
2022-09-24 18:53:53 +00:00
|
|
|
buglog(f"override_dir: {override_dir}")
|
2022-09-01 15:37:21 +00:00
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
filename = GLib.build_filenamev([override_dir, "global"])
|
2022-09-01 15:37:21 +00:00
|
|
|
|
|
|
|
user_keyfile = GLib.KeyFile.new()
|
|
|
|
|
2022-09-03 20:47:45 +00:00
|
|
|
is_gtk4 = gtk_ver == "gtk4"
|
|
|
|
is_gtk3 = gtk_ver == "gtk3"
|
|
|
|
if is_gtk4:
|
2022-09-01 15:53:59 +00:00
|
|
|
gtk_path = "xdg-config/gtk-4.0"
|
2022-09-03 20:47:45 +00:00
|
|
|
elif is_gtk3:
|
2022-09-01 15:53:59 +00:00
|
|
|
gtk_path = "xdg-config/gtk-3.0"
|
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
raise InvalidGTKVersion(
|
2022-09-07 15:51:36 +00:00
|
|
|
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3"
|
|
|
|
)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
|
|
|
def set_theming():
|
|
|
|
if is_gtk4:
|
|
|
|
settings.set_boolean("user-flatpak-theming-gtk4", False)
|
|
|
|
elif is_gtk3:
|
|
|
|
settings.set_boolean("user-flatpak-theming-gtk3", False)
|
2022-09-01 15:53:59 +00:00
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
try:
|
|
|
|
user_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
|
|
|
except GLib.GError as e:
|
|
|
|
if e.code == 4:
|
2022-09-03 20:47:45 +00:00
|
|
|
set_theming()
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("remove override: File doesn't exist")
|
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
toast_overlay.add_toast(
|
2022-09-07 15:51:36 +00:00
|
|
|
Adw.Toast(title=_("Unexpected file error occurred"))
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog(f"Unhandled GLib.FileError error code. Exc: {e}")
|
|
|
|
else:
|
|
|
|
try:
|
2022-09-01 16:19:45 +00:00
|
|
|
filesys_list = user_keyfile.get_string_list(
|
|
|
|
"Context", "filesystems")
|
2022-09-01 15:37:21 +00:00
|
|
|
except GLib.GError:
|
2022-09-03 20:47:45 +00:00
|
|
|
set_theming()
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("remove override: Group/key not found.")
|
|
|
|
else:
|
2022-09-01 15:53:59 +00:00
|
|
|
if gtk_path in filesys_list:
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog(f"before: {filesys_list}")
|
2022-09-01 15:53:59 +00:00
|
|
|
filesys_list.remove(gtk_path)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog(f"after: {filesys_list}")
|
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
user_keyfile.set_string_list(
|
|
|
|
"Context", "filesystems", filesys_list)
|
|
|
|
user_save_keyfile(
|
2022-09-07 15:51:36 +00:00
|
|
|
toast_overlay, settings, user_keyfile, filename, gtk_ver
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("remove override: Value removed.")
|
|
|
|
else:
|
2022-09-03 20:47:45 +00:00
|
|
|
set_theming()
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("remove override: Value not found.")
|
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
""" Do not use this functions for now, as they are lacking authentication"""
|
2022-09-01 15:37:21 +00:00
|
|
|
# TODO: Implement user authentication using Polkit
|
2022-09-07 15:51:36 +00:00
|
|
|
|
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
2022-09-07 15:51:36 +00:00
|
|
|
override_dir = GLib.build_filenamev(
|
|
|
|
[get_system_flatpak_path(), "overrides"])
|
2022-09-24 18:53:53 +00:00
|
|
|
buglog(f"override_dir: {override_dir}")
|
2022-09-01 15:37:21 +00:00
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
filename = GLib.build_filenamev([override_dir, "global"])
|
2022-09-01 15:37:21 +00:00
|
|
|
|
|
|
|
global_keyfile = GLib.KeyFile.new()
|
|
|
|
|
2022-09-03 20:47:45 +00:00
|
|
|
is_gtk4 = gtk_ver == "gtk4"
|
|
|
|
is_gtk3 = gtk_ver == "gtk3"
|
|
|
|
if is_gtk4:
|
2022-09-01 15:53:59 +00:00
|
|
|
gtk_path = "xdg-config/gtk-4.0"
|
2022-09-03 20:47:45 +00:00
|
|
|
elif is_gtk3:
|
2022-09-01 15:53:59 +00:00
|
|
|
gtk_path = "xdg-config/gtk-3.0"
|
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
raise InvalidGTKVersion(
|
2022-09-07 15:51:36 +00:00
|
|
|
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3"
|
|
|
|
)
|
2022-09-01 15:53:59 +00:00
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
try:
|
|
|
|
global_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
|
|
|
except GLib.GError as e:
|
|
|
|
if e.code == 4:
|
|
|
|
buglog("File doesn't exist. Attempting to create one")
|
|
|
|
if not os.path.exists(override_dir):
|
|
|
|
try:
|
|
|
|
dirs = Gio.File.new_for_path(override_dir)
|
|
|
|
dirs.make_directory_with_parents(None)
|
|
|
|
except GLib.GError as e:
|
|
|
|
buglog(f"Unable to create directories. Exc: {e}")
|
2022-09-04 12:30:01 +00:00
|
|
|
if is_gtk4:
|
2022-09-05 16:40:09 +00:00
|
|
|
settings.set_boolean(
|
|
|
|
"global-flatpak-theming-gtk4", False)
|
2022-09-04 12:30:01 +00:00
|
|
|
elif is_gtk3:
|
2022-09-05 16:40:09 +00:00
|
|
|
settings.set_boolean(
|
|
|
|
"global-flatpak-theming-gtk3", False)
|
2022-09-04 12:30:01 +00:00
|
|
|
return
|
2022-09-01 15:37:21 +00:00
|
|
|
else:
|
|
|
|
buglog("Directories created.")
|
|
|
|
|
|
|
|
file = Gio.File.new_for_path(filename)
|
|
|
|
file.create(Gio.FileCreateFlags.NONE, None)
|
|
|
|
|
|
|
|
global_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
2022-09-01 16:19:45 +00:00
|
|
|
global_keyfile.set_string("Context", "filesystems", gtk_path)
|
2022-09-01 15:37:21 +00:00
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
global_save_keyfile(
|
2022-09-07 15:51:36 +00:00
|
|
|
toast_overlay, settings, global_keyfile, filename, gtk_ver
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
toast_overlay.add_toast(
|
2022-09-07 15:51:36 +00:00
|
|
|
Adw.Toast(title=_("Unexpected file error occurred"))
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog(f"Unhandled GLib.FileError error code. Exc: {e}")
|
|
|
|
else:
|
|
|
|
try:
|
2022-09-01 16:19:45 +00:00
|
|
|
filesys_list = global_keyfile.get_string_list(
|
|
|
|
"Context", "filesystems")
|
2022-09-01 15:37:21 +00:00
|
|
|
except GLib.GError:
|
2022-09-01 15:53:59 +00:00
|
|
|
global_keyfile.set_string("Context", "filesystems", gtk_path)
|
2022-09-01 16:19:45 +00:00
|
|
|
global_save_keyfile(
|
2022-09-07 15:51:36 +00:00
|
|
|
toast_overlay, settings, global_keyfile, filename, gtk_ver
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
if gtk_path not in filesys_list:
|
|
|
|
global_keyfile.set_string_list(
|
2022-09-07 15:51:36 +00:00
|
|
|
"Context", "filesystems", filesys_list + [gtk_path]
|
|
|
|
)
|
2022-09-01 16:19:45 +00:00
|
|
|
global_save_keyfile(
|
2022-09-07 15:51:36 +00:00
|
|
|
toast_overlay, settings, global_keyfile, filename, gtk_ver
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
else:
|
2022-09-03 20:47:45 +00:00
|
|
|
if is_gtk4:
|
|
|
|
settings.set_boolean("global-flatpak-theming-gtk4", True)
|
|
|
|
elif is_gtk3:
|
|
|
|
settings.set_boolean("global-flatpak-theming-gtk3", True)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("Value already exists.")
|
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
|
|
|
|
def remove_gtk_global_override(toast_overlay, settings, gtk_ver):
|
2022-09-07 15:51:36 +00:00
|
|
|
override_dir = GLib.build_filenamev(
|
|
|
|
[get_system_flatpak_path(), "overrides"])
|
2022-09-24 18:53:53 +00:00
|
|
|
buglog(f"override_dir: {override_dir}")
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-09-07 15:51:36 +00:00
|
|
|
filename = GLib.build_filenamev([override_dir, "global"])
|
2022-09-01 15:37:21 +00:00
|
|
|
|
|
|
|
global_keyfile = GLib.KeyFile.new()
|
|
|
|
|
2022-09-03 20:47:45 +00:00
|
|
|
is_gtk4 = gtk_ver == "gtk4"
|
|
|
|
is_gtk3 = gtk_ver == "gtk3"
|
|
|
|
if is_gtk4:
|
2022-09-01 15:53:59 +00:00
|
|
|
gtk_path = "xdg-config/gtk-4.0"
|
2022-09-03 20:47:45 +00:00
|
|
|
elif is_gtk3:
|
2022-09-01 15:53:59 +00:00
|
|
|
gtk_path = "xdg-config/gtk-3.0"
|
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
raise InvalidGTKVersion(
|
2022-09-07 15:51:36 +00:00
|
|
|
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3"
|
|
|
|
)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
|
|
|
def set_theming():
|
|
|
|
if is_gtk4:
|
|
|
|
settings.set_boolean("user-flatpak-theming-gtk4", False)
|
|
|
|
elif is_gtk3:
|
|
|
|
settings.set_boolean("user-flatpak-theming-gtk3", False)
|
2022-09-01 15:53:59 +00:00
|
|
|
|
2022-09-01 15:37:21 +00:00
|
|
|
try:
|
|
|
|
global_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
|
|
|
except GLib.GError as e:
|
|
|
|
if e.code == 4:
|
2022-09-03 20:47:45 +00:00
|
|
|
set_theming()
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("remove override: File doesn't exist")
|
|
|
|
else:
|
2022-09-01 16:19:45 +00:00
|
|
|
toast_overlay.add_toast(
|
2022-09-07 15:51:36 +00:00
|
|
|
Adw.Toast(title=_("Unexpected file error occurred"))
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog(f"Unhandled GLib.FileError error code. Exc: {e}")
|
|
|
|
else:
|
|
|
|
try:
|
2022-09-01 16:19:45 +00:00
|
|
|
filesys_list = global_keyfile.get_string_list(
|
|
|
|
"Context", "filesystems")
|
2022-09-01 15:37:21 +00:00
|
|
|
except GLib.GError:
|
2022-09-03 20:47:45 +00:00
|
|
|
set_theming()
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("remove override: Group/key not found.")
|
|
|
|
else:
|
2022-09-01 15:53:59 +00:00
|
|
|
if gtk_path in filesys_list:
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog(f"before: {filesys_list}")
|
2022-09-01 15:53:59 +00:00
|
|
|
filesys_list.remove(gtk_path)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog(f"after: {filesys_list}")
|
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
global_keyfile.set_string_list(
|
|
|
|
"Context", "filesystems", filesys_list)
|
|
|
|
global_save_keyfile(
|
2022-09-07 15:51:36 +00:00
|
|
|
toast_overlay, settings, global_keyfile, filename, gtk_ver
|
|
|
|
)
|
2022-09-01 15:37:21 +00:00
|
|
|
buglog("remove override: Value removed.")
|
|
|
|
else:
|
2022-09-03 20:47:45 +00:00
|
|
|
set_theming()
|
2022-09-01 16:19:45 +00:00
|
|
|
buglog("remove override: Value not found.")
|