Add support for user based templates (~/.config/matugen/config.toml) as

requested in #185
MatugenService: add logic to scan for the matugen config.toml
ColorSchemeTab: add NCheckbox to toggle user based templates
This commit is contained in:
Ly-sec 2025-09-01 14:54:01 +02:00
parent 4193d3c87c
commit 4a4bec5aec
4 changed files with 37 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import qs.Commons
// Central place to define which templates we generate and where they write.
// Users can extend it by dropping additional templates into:
// - Assets/Matugen/templates/
// - ~/.config/matugen/ (when enableUserTemplates is true)
Singleton {
id: root

View file

@ -247,6 +247,7 @@ Singleton {
property bool foot: false
property bool fuzzel: false
property bool vesktop: false
property bool enableUserTemplates: false
}
// night light

View file

@ -465,5 +465,22 @@ ColumnLayout {
MatugenService.generateFromWallpaper()
}
}
NDivider {
Layout.fillWidth: true
Layout.topMargin: Style.marginM * scaling
Layout.bottomMargin: Style.marginM * scaling
}
NCheckbox {
label: "User Templates"
description: "Enable user-defined Matugen config from ~/.config/matugen/config.toml"
checked: Settings.data.matugen.enableUserTemplates
onToggled: checked => {
Settings.data.matugen.enableUserTemplates = checked
if (Settings.data.colorSchemes.useWallpaperColors)
MatugenService.generateFromWallpaper()
}
}
}
}

View file

@ -30,10 +30,22 @@ Singleton {
var pathEsc = dynamicConfigPath.replace(/'/g, "'\\''")
var extraRepo = (Quickshell.shellDir + "/Assets/Matugen/extra").replace(/'/g, "'\\''")
var extraUser = (Settings.configDir + "matugen.d").replace(/'/g, "'\\''")
// Build the main script
var script = "cat > '" + pathEsc + "' << 'EOF'\n" + content + "EOF\n" + "for d in '" + extraRepo + "' '" + extraUser
+ "'; do\n" + " if [ -d \"$d\" ]; then\n"
+ " for f in \"$d\"/*.toml; do\n" + " [ -f \"$f\" ] && { echo; echo \"# extra: $f\"; cat \"$f\"; } >> '"
+ pathEsc + "'\n" + " done\n" + " fi\n" + "done\n" + "matugen image '" + wp + "' --config '" + pathEsc + "' --mode " + mode
// Add user config execution if enabled
if (Settings.data.matugen.enableUserTemplates) {
var userConfigDir = (Quickshell.env("HOME") + "/.config/matugen/").replace(/'/g, "'\\''")
script += "\n# Execute user config if it exists\nif [ -f '" + userConfigDir + "config.toml' ]; then\n"
script += " matugen image '" + wp + "' --config '" + userConfigDir + "config.toml' --mode " + mode + "\n"
script += "fi"
}
script += "\n"
generateProcess.command = ["bash", "-lc", script]
generateProcess.running = true
}
@ -42,12 +54,13 @@ Singleton {
id: generateProcess
workingDirectory: Quickshell.shellDir
running: false
stdout: StdioCollector {
onStreamFinished: Logger.log("Matugen", "Completed colors generation")
}
stderr: StdioCollector {
onStreamFinished: if (this.text !== "")
Logger.error(this.text)
onStreamFinished: {
if (this.text !== "") {
Logger.warn("MatugenService", "Matugen stderr:", this.text)
}
}
}
}