From e3aa6e3429a8ea82c4cc4e2dd78f56479aa04e6f Mon Sep 17 00:00:00 2001 From: Aiser <2912778691@qq.com> Date: Mon, 10 Nov 2025 22:30:22 +0800 Subject: [PATCH] Matugen: fix spicetify theme work for predefined colors && fix `hex_stripped` does not work --- Assets/MatugenTemplates/spicetify.ini | 52 +++++++++++++------------- Services/Theming/TemplateProcessor.qml | 18 ++++++--- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/Assets/MatugenTemplates/spicetify.ini b/Assets/MatugenTemplates/spicetify.ini index bff30bf4..55c68652 100644 --- a/Assets/MatugenTemplates/spicetify.ini +++ b/Assets/MatugenTemplates/spicetify.ini @@ -1,27 +1,27 @@ [Comfy] -text = {{ colors.on_surface.default.hex_stripped }} -subtext = {{ colors.on_surface_variant.default.hex_stripped }} -main = {{ colors.surface.default.hex_stripped }} -main-elevated = {{ colors.surface_bright.default.hex_stripped }} -main-transition = {{ colors.surface_container_lowest.default.hex_stripped }} -highlight = {{ colors.surface_container_low.default.hex_stripped }} -highlight-elevated = {{ colors.surface_container_highest.default.hex_stripped }} -sidebar = {{ colors.surface.default.hex_stripped }} -player = {{ colors.scrim.default.hex_stripped }} -card = {{ colors.scrim.default.hex_stripped }} -shadow = {{ colors.scrim.default.hex_stripped }} -selected-row = {{ colors.on_surface.default.hex_stripped }} -button = {{ colors.primary.default.hex_stripped }} -button-active = {{ colors.primary_fixed.default.hex_stripped }} -button-disabled = {{ colors.primary_fixed_dim.default.hex_stripped }} -tab-active = {{ colors.surface.default.hex_stripped }} -notification = {{ colors.tertiary.default.hex_stripped }} -notification-error = {{ colors.error.default.hex_stripped }} -misc = {{ colors.scrim.default.hex_stripped }} -play-button = {{ colors.secondary.default.hex_stripped }} -play-button-active = {{ colors.secondary_fixed.default.hex_stripped }} -progress-fg = {{ colors.primary.default.hex_stripped }} -progress-bg = {{ colors.surface.default.hex_stripped }} -heart = {{ colors.error.default.hex_stripped }} -pagelink-active = {{ colors.on_tertiary_container.default.hex_stripped }} -radio-btn-active = {{ colors.on_tertiary_container.default.hex_stripped }} +text = {{colors.on_surface.default.hex_stripped}} +subtext = {{colors.on_surface_variant.default.hex_stripped}} +main = {{colors.surface.default.hex_stripped}} +main-elevated = {{colors.surface.default.hex_stripped}} +main-transition = {{colors.surface_container_lowest.default.hex_stripped}} +highlight = {{colors.surface_container_low.default.hex_stripped}} +highlight-elevated = {{colors.surface_container_highest.default.hex_stripped}} +sidebar = {{colors.surface.default.hex_stripped}} +player = {{colors.surface.default.hex_stripped}} +card = {{colors.surface.default.hex_stripped}} +shadow = {{colors.surface.default.hex_stripped}} +selected-row = {{colors.on_surface.default.hex_stripped}} +button = {{colors.primary.default.hex_stripped}} +button-active = {{colors.primary.default.hex_stripped}} +button-disabled = {{colors.primary.default.hex_stripped}} +tab-active = {{colors.surface.default.hex_stripped}} +notification = {{colors.tertiary.default.hex_stripped}} +notification-error = {{colors.error.default.hex_stripped}} +misc = {{colors.surface.default.hex_stripped}} +play-button = {{colors.secondary.default.hex_stripped}} +play-button-active = {{colors.secondary.default.hex_stripped}} +progress-fg = {{colors.primary.default.hex_stripped}} +progress-bg = {{colors.surface.default.hex_stripped}} +heart = {{colors.error.default.hex_stripped}} +pagelink-active = {{colors.on_tertiary_container.default.hex_stripped}} +radio-btn-active = {{colors.on_tertiary_container.default.hex_stripped}} diff --git a/Services/Theming/TemplateProcessor.qml b/Services/Theming/TemplateProcessor.qml index 2261e95d..07595d99 100644 --- a/Services/Theming/TemplateProcessor.qml +++ b/Services/Theming/TemplateProcessor.qml @@ -222,14 +222,20 @@ Singleton { } function replaceColorsInFile(filePath, colors) { - // This handles both ".hex" and ".hex_stripped" the EXACT same way. Our predefined color schemes are - // always RRGGBB without alpha so this is fine and keeps compatibility with matugen. let script = "" Object.keys(colors).forEach(colorKey => { - const colorValue = colors[colorKey].default.hex - const escapedColor = colorValue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - script += `sed -i 's/{{colors\\.${colorKey}\\.default\\.hex\\(_stripped\\)\\?}}/${escapedColor}/g' '${filePath}'\n` - }) + const hexValue = colors[colorKey].default.hex + const hexStrippedValue = colors[colorKey].default.hex_stripped + + const escapedHex = hexValue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + const escapedHexStripped = hexStrippedValue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + + // replace hex_stripped + script += `sed -i 's/{{colors\\.${colorKey}\\.default\\.hex_stripped}}/${escapedHexStripped}/g' '${filePath}'\n` + + // replace hex + script += `sed -i 's/{{colors\\.${colorKey}\\.default\\.hex}}/${escapedHex}/g' '${filePath}'\n` + }) return script }