From 4aa0b3d0fcb55212965781a8e6fc851f202cea34 Mon Sep 17 00:00:00 2001 From: bbedward Date: Tue, 21 Oct 2025 10:04:28 -0400 Subject: [PATCH] theme: sync color scheme after matugen finishes --- Common/Theme.qml | 10 +++++++--- scripts/matugen-worker.sh | 34 +++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Common/Theme.qml b/Common/Theme.qml index 69cfa163..2ef74347 100644 --- a/Common/Theme.qml +++ b/Common/Theme.qml @@ -441,7 +441,10 @@ Singleton { if (savePrefs && typeof SessionData !== "undefined" && !isGreeterMode) SessionData.setLightMode(light) if (!isGreeterMode) { - PortalService.setLightMode(light) + // Skip with matugen becuase, our script runner will do it. + if (!matugenAvailable) { + PortalService.setLightMode(light) + } generateSystemThemesFromCurrentTheme() } } @@ -719,15 +722,16 @@ Singleton { Quickshell.execDetached(["sh", "-c", `mkdir -p '${stateDir}' && cat > '${desiredPath}' << 'EOF'\n${json}\nEOF`]) workerRunning = true + const syncModeWithPortal = (typeof SettingsData !== "undefined" && SettingsData.syncModeWithPortal) ? "true" : "false" if (rawWallpaperPath.startsWith("we:")) { console.log("Theme: Starting matugen worker (WE wallpaper)") systemThemeGenerator.command = [ "sh", "-c", - `sleep 1 && ${shellDir}/scripts/matugen-worker.sh '${stateDir}' '${shellDir}' '${configDir}' --run` + `sleep 1 && ${shellDir}/scripts/matugen-worker.sh '${stateDir}' '${shellDir}' '${configDir}' '${syncModeWithPortal}' --run` ] } else { console.log("Theme: Starting matugen worker") - systemThemeGenerator.command = [shellDir + "/scripts/matugen-worker.sh", stateDir, shellDir, configDir, "--run"] + systemThemeGenerator.command = [shellDir + "/scripts/matugen-worker.sh", stateDir, shellDir, configDir, syncModeWithPortal, "--run"] } systemThemeGenerator.running = true } diff --git a/scripts/matugen-worker.sh b/scripts/matugen-worker.sh index 39d44f40..3b0e5d76 100755 --- a/scripts/matugen-worker.sh +++ b/scripts/matugen-worker.sh @@ -1,14 +1,15 @@ #!/usr/bin/env bash set -euo pipefail -if [ $# -lt 4 ]; then - echo "Usage: $0 STATE_DIR SHELL_DIR CONFIG_DIR --run" >&2 +if [ $# -lt 5 ]; then + echo "Usage: $0 STATE_DIR SHELL_DIR CONFIG_DIR SYNC_MODE_WITH_PORTAL --run" >&2 exit 1 fi STATE_DIR="$1" SHELL_DIR="$2" CONFIG_DIR="$3" +SYNC_MODE_WITH_PORTAL="$4" if [ ! -d "$STATE_DIR" ]; then echo "Error: STATE_DIR '$STATE_DIR' does not exist" >&2 @@ -25,10 +26,10 @@ if [ ! -d "$CONFIG_DIR" ]; then exit 1 fi -shift 3 # Remove STATE_DIR, SHELL_DIR, and CONFIG_DIR from arguments +shift 4 if [[ "${1:-}" != "--run" ]]; then - echo "usage: $0 STATE_DIR SHELL_DIR CONFIG_DIR --run" >&2 + echo "usage: $0 STATE_DIR SHELL_DIR CONFIG_DIR SYNC_MODE_WITH_PORTAL --run" >&2 exit 1 fi @@ -62,6 +63,27 @@ key_of() { echo "${kind}|${value}|${mode}|${icon}|${matugen_type}|${surface_base}|${run_user_templates}" | sha256sum | cut -d' ' -f1 } +set_system_color_scheme() { + local mode="$1" + + if [[ "$SYNC_MODE_WITH_PORTAL" != "true" ]]; then + return 0 + fi + + local target_scheme + if [[ "$mode" == "light" ]]; then + target_scheme="default" + else + target_scheme="prefer-dark" + fi + + if command -v gsettings >/dev/null 2>&1; then + gsettings set org.gnome.desktop.interface color-scheme "$target_scheme" >/dev/null 2>&1 || true + elif command -v dconf >/dev/null 2>&1; then + dconf write /org/gnome/desktop/interface/color-scheme "'$target_scheme'" >/dev/null 2>&1 || true + fi +} + build_once() { local json="$1" local kind value mode icon matugen_type surface_base run_user_templates @@ -237,7 +259,7 @@ EOF rm -f "$TMP_CONTENT_CFG" popd >/dev/null - echo "$JSON" | grep -q '"primary"' || { echo "matugen JSON missing primary" >&2; return 2; } + echo "$JSON" | grep -q '"primary"' || { echo "matugen JSON missing primary" >&2; set_system_color_scheme "$mode"; return 2; } printf "%s" "$JSON" > "$LAST_JSON" GTK_CSS="$CONFIG_DIR/gtk-3.0/gtk.css" @@ -289,6 +311,8 @@ EOF mv "$TMP" "$CONFIG_DIR/kitty/dank-theme.conf" fi fi + + set_system_color_scheme "$mode" } if command -v pywalfox >/dev/null 2>&1 && [[ -f "$HOME/.cache/wal/colors.json" ]]; then