mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-01 10:05:30 +00:00
Matugen: user defined templates can now use predefined color schemes,
changed path to config (~/.config/noctalia/user-templates.toml)
This commit is contained in:
@@ -559,7 +559,7 @@
|
||||
"description": "Zusätzliche Konfigurationsoptionen.",
|
||||
"user-templates": {
|
||||
"label": "Benutzer-Vorlagen",
|
||||
"description": "Benutzerdefinierte Matugen-Konfiguration aus ~/.config/matugen/config.toml aktivieren"
|
||||
"description": "Benutzerdefinierte Matugen-Konfiguration aktivieren. Eine Vorlagendatei wird beim ersten Aktivieren unter ~/.config/noctalia/user-templates.toml erstellt"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
|
||||
@@ -563,7 +563,7 @@
|
||||
"description": "Additional configuration options.",
|
||||
"user-templates": {
|
||||
"label": "User templates",
|
||||
"description": "Enable user-defined Matugen config from ~/.config/matugen/config.toml"
|
||||
"description": "Enable user-defined Matugen config. A template file will be created at ~/.config/noctalia/user-templates.toml on first enable"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@
|
||||
"description": "Opciones de configuración adicionales.",
|
||||
"user-templates": {
|
||||
"label": "Plantillas de usuario",
|
||||
"description": "Habilitar configuración de Matugen definida por el usuario desde ~/.config/matugen/config.toml"
|
||||
"description": "Habilitar configuración de Matugen definida por el usuario. Se creará un archivo de plantilla en ~/.config/noctalia/user-templates.toml al activar por primera vez"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
|
||||
@@ -559,7 +559,7 @@
|
||||
"description": "Options de configuration supplémentaires.",
|
||||
"user-templates": {
|
||||
"label": "Modèles utilisateur",
|
||||
"description": "Activer la configuration Matugen définie par l'utilisateur depuis ~/.config/matugen/config.toml"
|
||||
"description": "Activer la configuration Matugen définie par l'utilisateur. Un fichier modèle sera créé dans ~/.config/noctalia/user-templates.toml lors de la première activation"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
|
||||
@@ -521,7 +521,7 @@
|
||||
"description": "Opções de configuração adicionais.",
|
||||
"user-templates": {
|
||||
"label": "Modelos do usuário",
|
||||
"description": "Ativa a configuração do Matugen definida pelo usuário em ~/.config/matugen/config.toml"
|
||||
"description": "Ativa a configuração do Matugen definida pelo usuário. Um arquivo de modelo será criado em ~/.config/noctalia/user-templates.toml na primeira ativação"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
|
||||
@@ -559,7 +559,7 @@
|
||||
"description": "其他配置选项。",
|
||||
"user-templates": {
|
||||
"label": "用户模板",
|
||||
"description": "启用来自 ~/.config/matugen/config.toml 的用户定义 Matugen 配置"
|
||||
"description": "启用用户定义的 Matugen 配置。首次启用时将在 ~/.config/noctalia/user-templates.toml 创建模板文件"
|
||||
}
|
||||
},
|
||||
"section": {
|
||||
|
||||
@@ -590,6 +590,9 @@ ColumnLayout {
|
||||
checked: Settings.data.templates.enableUserTemplates
|
||||
onToggled: checked => {
|
||||
Settings.data.templates.enableUserTemplates = checked
|
||||
if (checked) {
|
||||
MatugenTemplates.writeUserTemplatesToml()
|
||||
}
|
||||
AppThemeService.generate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,10 @@ Singleton {
|
||||
const colors = schemeData[mode]
|
||||
|
||||
const matugenColors = generatePalette(colors.mPrimary, colors.mSecondary, colors.mTertiary, colors.mError, colors.mSurface, isDarkMode)
|
||||
const script = processAllTemplates(matugenColors, mode)
|
||||
let script = processAllTemplates(matugenColors, mode)
|
||||
|
||||
// Add user templates if enabled
|
||||
script += buildUserTemplateCommandForPredefined(schemeData, mode)
|
||||
|
||||
generateProcess.command = ["bash", "-lc", script]
|
||||
generateProcess.running = true
|
||||
@@ -335,8 +338,42 @@ Singleton {
|
||||
return script
|
||||
}
|
||||
|
||||
function buildUserTemplateCommandForPredefined(schemeData, mode) {
|
||||
if (!Settings.data.templates.enableUserTemplates) {
|
||||
return ""
|
||||
}
|
||||
|
||||
const userConfigPath = getUserConfigPath()
|
||||
const isDarkMode = Settings.data.colorSchemes.darkMode
|
||||
const colors = schemeData[mode]
|
||||
|
||||
// Generate the matugen palette JSON
|
||||
const matugenColors = generatePalette(colors.mPrimary, colors.mSecondary, colors.mTertiary, colors.mError, colors.mSurface, isDarkMode)
|
||||
|
||||
// Create a temporary JSON file with the color palette
|
||||
const tempJsonPath = Settings.cacheDir + "predefined-colors.json"
|
||||
const homeDir = Quickshell.env("HOME")
|
||||
const tempJsonPathEsc = tempJsonPath.replace(/'/g, "'\\''")
|
||||
|
||||
let script = "\n# Execute user templates with predefined scheme colors\n"
|
||||
script += `if [ -f '${userConfigPath}' ]; then\n`
|
||||
|
||||
// Write the color palette to a temp JSON file
|
||||
script += ` cat > '${tempJsonPathEsc}' << 'EOF'\n`
|
||||
script += JSON.stringify({
|
||||
"colors": matugenColors
|
||||
}, null, 2) + "\n"
|
||||
script += "EOF\n"
|
||||
|
||||
// Use matugen json subcommand with the color palette
|
||||
script += ` matugen json '${tempJsonPathEsc}' --config '${userConfigPath}' --mode ${mode}\n`
|
||||
script += "fi"
|
||||
|
||||
return script
|
||||
}
|
||||
|
||||
function getUserConfigPath() {
|
||||
return (Quickshell.env("HOME") + "/.config/matugen/config.toml").replace(/'/g, "'\\''")
|
||||
return (Settings.configDir + "user-templates.toml").replace(/'/g, "'\\''")
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
@@ -2,6 +2,7 @@ pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import qs.Commons
|
||||
|
||||
// Central place to define which templates we generate and where they write.
|
||||
@@ -32,6 +33,51 @@ Singleton {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Build user templates TOML for ~/.config/noctalia/user-templates.toml
|
||||
function buildUserTemplatesToml() {
|
||||
var lines = []
|
||||
lines.push("[config]")
|
||||
lines.push("")
|
||||
lines.push("# User-defined templates")
|
||||
lines.push("# Add your custom templates below")
|
||||
lines.push("# Example:")
|
||||
lines.push("# [templates.myapp]")
|
||||
lines.push("# input_path = \"~/.config/noctalia/templates/myapp.css\"")
|
||||
lines.push("# output_path = \"~/.config/myapp/theme.css\"")
|
||||
lines.push("# post_hook = \"myapp --reload-theme\"")
|
||||
lines.push("")
|
||||
lines.push("# Remove this section and add your own templates")
|
||||
lines.push("[templates.placeholder]")
|
||||
lines.push("input_path = \"" + Quickshell.shellDir + "/Assets/MatugenTemplates/noctalia.json\"")
|
||||
lines.push("output_path = \"" + Settings.cacheDir + "placeholder.json\"")
|
||||
lines.push("post_hook = \"echo 'User templates enabled - replace this placeholder with your own templates'\"")
|
||||
lines.push("")
|
||||
|
||||
return lines.join("\n") + "\n"
|
||||
}
|
||||
|
||||
// Write user templates TOML to ~/.config/noctalia/user-templates.toml
|
||||
function writeUserTemplatesToml() {
|
||||
var userConfigPath = Settings.configDir + "user-templates.toml"
|
||||
|
||||
// Check if file already exists
|
||||
fileCheckProcess.command = ["test", "-f", userConfigPath]
|
||||
fileCheckProcess.running = true
|
||||
}
|
||||
|
||||
function doWriteUserTemplatesToml() {
|
||||
var userConfigPath = Settings.configDir + "user-templates.toml"
|
||||
var configContent = buildUserTemplatesToml()
|
||||
|
||||
// Ensure directory exists (should already exist but just in case)
|
||||
Quickshell.execDetached(["mkdir", "-p", Settings.configDir])
|
||||
|
||||
// Write the config file
|
||||
Quickshell.execDetached(["sh", "-c", `echo '${configContent.replace(/'/g, "'\\''")}' > '${userConfigPath}'`])
|
||||
|
||||
Logger.i("MatugenTemplates", "User templates config written to:", userConfigPath)
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
function addWallpaperBasedTemplates(lines, mode) {
|
||||
// Noctalia colors
|
||||
@@ -208,4 +254,20 @@ Singleton {
|
||||
}
|
||||
return clients
|
||||
}
|
||||
|
||||
// Process for checking if user templates file exists
|
||||
Process {
|
||||
id: fileCheckProcess
|
||||
running: false
|
||||
|
||||
onExited: function (exitCode) {
|
||||
if (exitCode === 0) {
|
||||
// File exists, skip creation
|
||||
Logger.d("MatugenTemplates", "User templates config already exists, skipping creation")
|
||||
} else {
|
||||
// File doesn't exist, create it
|
||||
doWriteUserTemplatesToml()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user