Use the Option type for oldConfigDir variable

This commit is contained in:
Rokosun 2023-11-03 13:34:30 +01:00
parent 85b0e75ff6
commit 11a1a7dc91

View File

@ -1,6 +1,7 @@
from std/osproc import execProcess, ProcessOption, startProcess, waitForExit, close from std/osproc import execProcess, ProcessOption, startProcess, waitForExit, close
from std/envvars import existsEnv, getEnv, delEnv, putEnv from std/envvars import existsEnv, getEnv, delEnv, putEnv
from std/os import symlinkExists, getConfigDir, `/` from std/os import symlinkExists, getConfigDir, `/`
from std/options import Option, some, get, isNone
from std/strutils import split, endsWith from std/strutils import split, endsWith
from std/strformat import fmt from std/strformat import fmt
import owlkettle import owlkettle
@ -56,16 +57,13 @@ proc setTheme(themeName: string) =
var var
oldConfigDir: string oldConfigDir: Option[string]
oldConfigDirUnset: bool
configDirChanged: bool configDirChanged: bool
# Prevent loading GTK theme from ~/.config/gtk-4.0 directory when it is a symlink # Prevent loading GTK theme from ~/.config/gtk-4.0 directory when it is a symlink
if symlinkExists(getConfigDir() / "gtk-4.0"): if symlinkExists(getConfigDir() / "gtk-4.0"):
if existsEnv("XDG_CONFIG_HOME"): if existsEnv("XDG_CONFIG_HOME"):
oldConfigDir = getEnv("XDG_CONFIG_HOME") oldConfigDir = some(getEnv("XDG_CONFIG_HOME"))
else:
oldConfigDirUnset = true
putEnv("XDG_CONFIG_HOME", "/dev/null") putEnv("XDG_CONFIG_HOME", "/dev/null")
configDirChanged = true configDirChanged = true
@ -76,10 +74,10 @@ viewable App:
build: build:
# Reset the user's XDG_CONFIG_HOME variable back to what it was before # Reset the user's XDG_CONFIG_HOME variable back to what it was before
if configDirChanged == true: if configDirChanged == true:
if oldConfigDirUnset: if oldConfigDir.isNone():
delEnv("XDG_CONFIG_HOME") delEnv("XDG_CONFIG_HOME")
else: else:
putEnv("XDG_CONFIG_HOME", oldConfigDir) putEnv("XDG_CONFIG_HOME", get(oldConfigDir))
let currentTheme: string = execProcess("/usr/bin/xfconf-query", let currentTheme: string = execProcess("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/ThemeName"], args=["--channel=xsettings", "--property=/Net/ThemeName"],