diff --git a/Assets/Translations/de.json b/Assets/Translations/de.json index f53299c2..8f04dee0 100644 --- a/Assets/Translations/de.json +++ b/Assets/Translations/de.json @@ -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": { diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index e8ee372b..3f3b9683 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -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" } } } diff --git a/Assets/Translations/es.json b/Assets/Translations/es.json index 77bd8612..3193fff1 100644 --- a/Assets/Translations/es.json +++ b/Assets/Translations/es.json @@ -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": { diff --git a/Assets/Translations/fr.json b/Assets/Translations/fr.json index f180575a..aee01c11 100644 --- a/Assets/Translations/fr.json +++ b/Assets/Translations/fr.json @@ -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": { diff --git a/Assets/Translations/pt.json b/Assets/Translations/pt.json index 5e2a5658..0db4489b 100644 --- a/Assets/Translations/pt.json +++ b/Assets/Translations/pt.json @@ -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": { diff --git a/Assets/Translations/zh-CN.json b/Assets/Translations/zh-CN.json index 889266c4..ddfd0059 100644 --- a/Assets/Translations/zh-CN.json +++ b/Assets/Translations/zh-CN.json @@ -559,7 +559,7 @@ "description": "其他配置选项。", "user-templates": { "label": "用户模板", - "description": "启用来自 ~/.config/matugen/config.toml 的用户定义 Matugen 配置" + "description": "启用用户定义的 Matugen 配置。首次启用时将在 ~/.config/noctalia/user-templates.toml 创建模板文件" } }, "section": { diff --git a/Modules/Settings/Tabs/ColorSchemeTab.qml b/Modules/Settings/Tabs/ColorSchemeTab.qml index ddf48db1..5909040f 100644 --- a/Modules/Settings/Tabs/ColorSchemeTab.qml +++ b/Modules/Settings/Tabs/ColorSchemeTab.qml @@ -590,6 +590,9 @@ ColumnLayout { checked: Settings.data.templates.enableUserTemplates onToggled: checked => { Settings.data.templates.enableUserTemplates = checked + if (checked) { + MatugenTemplates.writeUserTemplatesToml() + } AppThemeService.generate() } } diff --git a/Services/AppThemeService.qml b/Services/AppThemeService.qml index dd24327a..fc1f01d0 100644 --- a/Services/AppThemeService.qml +++ b/Services/AppThemeService.qml @@ -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, "'\\''") } // -------------------------------------------------------------------------------- diff --git a/Services/MatugenTemplates.qml b/Services/MatugenTemplates.qml index 68ceec44..633f7fea 100644 --- a/Services/MatugenTemplates.qml +++ b/Services/MatugenTemplates.qml @@ -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() + } + } + } }