Matugen: fix empty config if only theming terminal + autofmt

This commit is contained in:
ItsLemmy
2025-10-06 12:22:32 -04:00
parent 3d2d9a2442
commit e8148a3d0a
2 changed files with 141 additions and 123 deletions
+73 -74
View File
@@ -46,7 +46,7 @@ Singleton {
// Generate colors using current wallpaper and settings
function generateFromWallpaper() {
Logger.log("Matugen", "Generating from wallpaper on screen:", Screen.name)
var wp = WallpaperService.getWallpaper(Screen.name).replace(/'/g, "'\\''")
if (wp === "") {
Logger.error("Matugen", "No wallpaper was found")
@@ -54,6 +54,10 @@ Singleton {
}
var content = MatugenTemplates.buildConfigToml()
if (content === "") {
return
}
var mode = Settings.data.colorSchemes.darkMode ? "dark" : "light"
var pathEsc = dynamicConfigPath.replace(/'/g, "'\\''")
@@ -67,7 +71,7 @@ Singleton {
// --------------------------------
function buildMatugenScript(content, pathEsc, wallpaper, mode) {
var script = "cat > '" + pathEsc + "' << 'EOF'\n" + content + "EOF\n"
// Main matugen command
script += "matugen image '" + wallpaper + "' --config '" + pathEsc + "' --mode " + mode + " --type " + Settings.data.colorSchemes.matugenSchemeType
@@ -88,7 +92,7 @@ Singleton {
script += "if [ -f '" + userConfigPath + "' ]; then\n"
script += " matugen image '" + input + "' --config '" + userConfigPath + "' --mode " + mode + " --type " + Settings.data.colorSchemes.matugenSchemeType + "\n"
script += "fi"
return script
}
@@ -100,17 +104,16 @@ Singleton {
// --------------------------------
function selectVibrantColor(schemeData, mode) {
var colors = []
colors.push(schemeData[mode]["mPrimary"]);
colors.push(schemeData[mode]["mSecondary"]);
colors.push(schemeData[mode]["mTertiary"]);
colors.push(schemeData[mode]["mPrimary"])
colors.push(schemeData[mode]["mSecondary"])
colors.push(schemeData[mode]["mTertiary"])
var bestScore = 0
var bestScoreIndex = -1
for (var i=0; i<colors.length; i++) {
for (var i = 0; i < colors.length; i++) {
var hsl = ColorsConvert.hexToHSL(colors[i])
var score = hsl['s'];
var score = hsl['s']
if (score > bestScore) {
bestScore = score
bestScoreIndex = i
@@ -126,6 +129,10 @@ Singleton {
Logger.log("Matugen", "Generating templates from predefined color scheme")
var content = MatugenTemplates.buildConfigToml()
if (content === "") {
return
}
var mode = Settings.data.colorSchemes.darkMode ? "dark" : "light"
var pathEsc = dynamicConfigPath.replace(/'/g, "'\\''")
const color = selectVibrantColor(schemeData, mode)
@@ -144,10 +151,10 @@ Singleton {
function buildPredefinedSchemeScript(content, pathEsc, color, mode) {
var script = "cat > '" + pathEsc + "' << 'EOF'\n" + content + "EOF\n\n"
script += "matugen color hex '" + color + "' --config '" + pathEsc + "' --mode " + mode + "\n"
// Add user template execution if enabled
script += addUserTemplateExecutionForColor(color, mode)
return script
}
@@ -162,80 +169,72 @@ Singleton {
script += "if [ -f '" + userConfigPath + "' ]; then\n"
script += " matugen color hex '" + color + "' --config '" + userConfigPath + "' --mode " + mode + "\n"
script += "fi"
return script
}
// --------------------------------
function handleTerminalThemes() {
var terminals = {
foot: "~/.config/foot/themes/noctalia",
ghostty: "~/.config/ghostty/themes/noctalia",
kitty: "~/.config/kitty/themes/noctalia.conf",
"foot": "~/.config/foot/themes/noctalia",
"ghostty": "~/.config/ghostty/themes/noctalia",
"kitty": "~/.config/kitty/themes/noctalia.conf"
}
var copyCmd = Object.entries(terminals)
.filter(([terminal, colorsPath]) => Settings.data.templates[terminal])
.map(([terminal, colorsPath]) => {
var colorsPathParent = colorsPath.replace(/[^\/]*$/, "")
var terminalColorsTemplate = getTerminalColorsTemplate(terminal)
return [
`mkdir -p ${colorsPathParent}`,
`cp -f ${terminalColorsTemplate} ${colorsPath}`,
`${colorsApplyScript} ${terminal}`,
]
})
.reduce((arr1, arr2) => arr1.concat(arr2), [])
.join("; ")
var copyCmd = Object.entries(terminals).filter([ => Settings.data.templates[terminal]).map([ => {
var colorsPathParent = colorsPath.replace(/[^\/]*$/, "")
var terminalColorsTemplate = getTerminalColorsTemplate(terminal)
return [`mkdir -p ${colorsPathParent}`, `cp -f ${terminalColorsTemplate} ${colorsPath}`, `${colorsApplyScript} ${terminal}`]
}).reduce((arr1, arr2) => arr1.concat(arr2), []).join("; ")
if (copyCmd !== "") {
copyProcess.command = ["bash", "-lc", copyCmd]
copyProcess.running = true
}
if (copyCmd !== "") {
copyProcess.command = ["bash", "-lc", copyCmd]
copyProcess.running = true
}
}
// --------------------------------
function getTerminalColorsTemplate(terminal) {
var colorScheme = Settings.data.colorSchemes.predefinedScheme
const darkLight = Settings.data.colorSchemes.darkMode ? 'dark' : 'light'
// --------------------------------
function getTerminalColorsTemplate(terminal) {
var colorScheme = Settings.data.colorSchemes.predefinedScheme
const darkLight = Settings.data.colorSchemes.darkMode ? 'dark' : 'light'
// Convert display names back to folder names
var schemeMap = {
"Noctalia (default)": "Noctalia-default",
"Noctalia (legacy)": "Noctalia-legacy",
"Tokyo Night": "Tokyo-Night"
}
colorScheme = schemeMap[colorScheme] || colorScheme
var extension = terminal === 'kitty' ? ".conf" : ""
// Convert display names back to folder names
var schemeMap = {
"Noctalia (default)": "Noctalia-default",
"Noctalia (legacy)": "Noctalia-legacy",
"Tokyo Night": "Tokyo-Night"
}
return `${Quickshell.shellDir}/Assets/ColorScheme/${colorScheme}/terminal/${terminal}/${colorScheme}-${darkLight}${extension}`
colorScheme = schemeMap[colorScheme] || colorScheme
var extension = terminal === 'kitty' ? ".conf" : ""
return `${Quickshell.shellDir}/Assets/ColorScheme/${colorScheme}/terminal/${terminal}/${colorScheme}-${darkLight}${extension}`
}
// --------------------------------
Process {
id: generateProcess
workingDirectory: Quickshell.shellDir
running: false
stderr: StdioCollector {
onStreamFinished: {
if (this.text !== "") {
Logger.warn("MatugenService", "GenerateProcess stderr:", this.text)
}
}
}
}
// --------------------------------
Process {
id: copyProcess
running: false
stderr: StdioCollector {
onStreamFinished: {
if (this.text !== "") {
Logger.warn("MatugenService", "CopyProcess stderr:", this.text)
}
}
}
}
}
// --------------------------------
Process {
id: generateProcess
workingDirectory: Quickshell.shellDir
running: false
stderr: StdioCollector {
onStreamFinished: {
if (this.text !== "") {
Logger.warn("MatugenService", "GenerateProcess stderr:", this.text)
}
}
}
}
// --------------------------------
Process {
id: copyProcess
running: false
stderr: StdioCollector {
onStreamFinished: {
if (this.text !== "") {
Logger.warn("MatugenService", "CopyProcess stderr:", this.text)
}
}
}
}
}
+68 -49
View File
@@ -8,7 +8,6 @@ import qs.Commons
// Users can extend it by dropping additional templates into:
// - Assets/MatugenTemplates/ (built-in templates)
// - ~/.config/matugen/ (user-defined templates when enableUserTemplates is true)
//
// User templates are automatically executed after the main matugen command
// if enableUserTemplates is enabled in settings.
Singleton {
@@ -18,16 +17,19 @@ Singleton {
function buildConfigToml() {
var lines = []
var mode = Settings.data.colorSchemes.darkMode ? "dark" : "light"
lines.push("[config]")
if (Settings.data.colorSchemes.useWallpaperColors) {
addWallpaperBasedTemplates(lines, mode)
}
addApplicationTemplates(lines, mode)
return lines.join("\n") + "\n"
if (lines.length > 0) {
const config = ["[config]"].concat(lines)
return config.join("\n") + "\n"
}
return ""
}
// --------------------------------
@@ -43,13 +45,21 @@ Singleton {
// --------------------------------
function addTerminalTemplates(lines) {
var terminals = [
{ name: "foot", path: "Terminal/foot", output: "~/.config/foot/themes/noctalia" },
{ name: "ghostty", path: "Terminal/ghostty", output: "~/.config/ghostty/themes/noctalia" },
{ name: "kitty", path: "Terminal/kitty.conf", output: "~/.config/kitty/themes/noctalia.conf" }
]
var terminals = [{
"name": "foot",
"path": "Terminal/foot",
"output": "~/.config/foot/themes/noctalia"
}, {
"name": "ghostty",
"path": "Terminal/ghostty",
"output": "~/.config/ghostty/themes/noctalia"
}, {
"name": "kitty",
"path": "Terminal/kitty.conf",
"output": "~/.config/kitty/themes/noctalia.conf"
}]
terminals.forEach(function(terminal) {
terminals.forEach(function (terminal) {
if (Settings.data.templates[terminal.name]) {
lines.push("\n[templates." + terminal.name + "]")
lines.push('input_path = "' + Quickshell.shellDir + '/Assets/MatugenTemplates/' + terminal.path + '"')
@@ -61,46 +71,55 @@ Singleton {
// --------------------------------
function addApplicationTemplates(lines, mode) {
var applications = [
{
name: "gtk",
templates: [
{ version: "gtk3", output: "~/.config/gtk-3.0/gtk.css" },
{ version: "gtk4", output: "~/.config/gtk-4.0/gtk.css" }
],
input: "gtk.css",
postHook: "gsettings set org.gnome.desktop.interface color-scheme prefer-" + mode
},
{
name: "qt",
templates: [
{ version: "qt5", output: "~/.config/qt5ct/colors/noctalia.conf" },
{ version: "qt6", output: "~/.config/qt6ct/colors/noctalia.conf" }
],
input: "qtct.conf"
},
{
name: "fuzzel",
templates: [{ version: "fuzzel", output: "~/.config/fuzzel/themes/noctalia" }],
input: "fuzzel.conf",
postHook: MatugenService.colorsApplyScript + " fuzzel"
},
{
name: "pywalfox",
templates: [{ version: "pywalfox", output: "~/.cache/wal/colors.json" }],
input: "pywalfox.json",
postHook: MatugenService.colorsApplyScript + " pywalfox"
},
{
name: "vesktop",
templates: [{ version: "vesktop", output: "~/.config/vesktop/themes/noctalia.theme.css" }],
input: "vesktop.css"
}
]
var applications = [{
"name": "gtk",
"templates": [{
"version": "gtk3",
"output": "~/.config/gtk-3.0/gtk.css"
}, {
"version": "gtk4",
"output": "~/.config/gtk-4.0/gtk.css"
}],
"input": "gtk.css",
"postHook": "gsettings set org.gnome.desktop.interface color-scheme prefer-" + mode
}, {
"name": "qt",
"templates": [{
"version": "qt5",
"output": "~/.config/qt5ct/colors/noctalia.conf"
}, {
"version": "qt6",
"output": "~/.config/qt6ct/colors/noctalia.conf"
}],
"input": "qtct.conf"
}, {
"name": "fuzzel",
"templates": [{
"version": "fuzzel",
"output": "~/.config/fuzzel/themes/noctalia"
}],
"input": "fuzzel.conf",
"postHook": MatugenService.colorsApplyScript + " fuzzel"
}, {
"name": "pywalfox",
"templates": [{
"version": "pywalfox",
"output": "~/.cache/wal/colors.json"
}],
"input": "pywalfox.json",
"postHook": MatugenService.colorsApplyScript + " pywalfox"
}, {
"name": "vesktop",
"templates": [{
"version": "vesktop",
"output": "~/.config/vesktop/themes/noctalia.theme.css"
}],
"input": "vesktop.css"
}]
applications.forEach(function(app) {
applications.forEach(function (app) {
if (Settings.data.templates[app.name]) {
app.templates.forEach(function(template) {
app.templates.forEach(function (template) {
lines.push("\n[templates." + template.version + "]")
lines.push('input_path = "' + Quickshell.shellDir + '/Assets/MatugenTemplates/' + app.input + '"')
lines.push('output_path = "' + template.output + '"')