Add build hook to revert the $XDG_CONFIG_HOME variable

Also created the applicationID variable
This commit is contained in:
Rokosun 2023-11-01 19:13:17 +01:00
parent acf400bd54
commit 85b0e75ff6
1 changed files with 22 additions and 3 deletions

View File

@ -1,5 +1,6 @@
from std/osproc import execProcess, ProcessOption, startProcess, waitForExit, close
from std/os import symlinkExists, getConfigDir, putEnv, `/`
from std/envvars import existsEnv, getEnv, delEnv, putEnv
from std/os import symlinkExists, getConfigDir, `/`
from std/strutils import split, endsWith
from std/strformat import fmt
import owlkettle
@ -9,6 +10,7 @@ const
iconsDir = "/usr/share/tromjaro-theme-switcher/icons"
# GTK CSS for overriding the default icon size of buttons
gtkCSS = "button { -gtk-icon-size: 85px; }"
applicationID = "com.tromjaro.ThemeSwitcher"
themeColors = ["Grey", "Pink", "Green", "Orange", "Purple", "Yellow", "Teal"]
themeStyles = ["Light", "Nord", "Dark", "Dark-Nord"]
@ -49,19 +51,36 @@ proc setTheme(themeName: string) =
args=["--channel=xsettings", "--property=/Net/ThemeName", "--create", "--type=string", "--set", themeName])
# Send notification about the theme change
sendNotification("com.tromjaro.ThemeSwitcher", "Theme Switcher", fmt"{themeName} theme{panelNotification} is enabled",
sendNotification(applicationID, "Theme Switcher", fmt"{themeName} theme{panelNotification} is enabled",
icon=fmt"{iconsDir}/{themeName}.svg")
var
oldConfigDir: string
oldConfigDirUnset: bool
configDirChanged: bool
# Prevent loading GTK theme from ~/.config/gtk-4.0 directory when it is a symlink
if symlinkExists(getConfigDir() / "gtk-4.0"):
if existsEnv("XDG_CONFIG_HOME"):
oldConfigDir = getEnv("XDG_CONFIG_HOME")
else:
oldConfigDirUnset = true
putEnv("XDG_CONFIG_HOME", "/dev/null")
configDirChanged = true
# Display the GTK-4 GUI using owlkettle
viewable App:
highlightButton: array[2, string]
hooks:
build:
# Reset the user's XDG_CONFIG_HOME variable back to what it was before
if configDirChanged == true:
if oldConfigDirUnset:
delEnv("XDG_CONFIG_HOME")
else:
putEnv("XDG_CONFIG_HOME", oldConfigDir)
let currentTheme: string = execProcess("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/ThemeName"],
options={})[0 .. ^2]
@ -110,4 +129,4 @@ method view(app: AppState): Widget =
# Highlight this button
app.highlightButton = [themeColor, themeStyle]
brew("com.tromjaro.ThemeSwitcher", gui(App()), icons=[iconsDir], stylesheets=[newStylesheet(gtkCSS)])
brew(applicationID, gui(App()), icons=[iconsDir], stylesheets=[newStylesheet(gtkCSS)])