1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

Update auto theme logic

This commit is contained in:
purian23
2025-07-28 21:35:52 -04:00
parent 102b248cad
commit d656502342
5 changed files with 227 additions and 50 deletions

View File

@@ -53,6 +53,12 @@ Singleton {
console.log("Light mode changed - updating dynamic colors");
colorUpdateTrigger++;
colorsUpdated();
// If dynamic theme is active, regenerate system themes with new light/dark mode
if (typeof Theme !== "undefined" && Theme.isDynamicTheme) {
console.log("Regenerating system themes for new light/dark mode");
generateSystemThemes();
}
}
}
@@ -283,8 +289,15 @@ palette = 15=${fg_b}`;
console.log("Wallpaper:", wallpaperPath);
console.log("Shell directory:", shellDir);
// Get current theme preferences
const isLight = (typeof Theme !== "undefined" && Theme.isLightMode) ? "true" : "false";
const iconTheme = (typeof Prefs !== "undefined" && Prefs.iconTheme) ? Prefs.iconTheme : "System Default";
console.log("Theme mode:", isLight === "true" ? "light" : "dark");
console.log("Icon theme:", iconTheme);
systemThemeGenerationInProgress = true;
systemThemeGenerator.command = [shellDir + "/generate-themes.sh", wallpaperPath, shellDir];
systemThemeGenerator.command = [shellDir + "/generate-themes.sh", wallpaperPath, shellDir, "generate", isLight, iconTheme];
systemThemeGenerator.running = true;
}
@@ -297,6 +310,26 @@ palette = 15=${fg_b}`;
console.log("Generating Qt themes using matugen templates");
generateSystemThemes();
}
function restoreSystemThemes() {
console.log("Restoring original system themes");
const shellDir = root.shellDir;
if (!shellDir) {
console.warn("Shell directory not available, cannot restore system themes");
return;
}
// Get current theme preferences
const isLight = (typeof Theme !== "undefined" && Theme.isLightMode) ? "true" : "false";
const iconTheme = (typeof Prefs !== "undefined" && Prefs.iconTheme) ? Prefs.iconTheme : "System Default";
console.log("Restoring to theme mode:", isLight === "true" ? "light" : "dark");
console.log("Icon theme:", iconTheme);
systemThemeRestoreProcess.command = [shellDir + "/generate-themes.sh", "", shellDir, "restore", isLight, iconTheme];
systemThemeRestoreProcess.running = true;
}
Process {
id: niriConfigWriter
@@ -366,10 +399,7 @@ palette = 15=${fg_b}`;
console.log("System themes generated successfully");
console.log("stdout:", systemThemeStdout.text);
if (gtkThemingEnabled && typeof Prefs !== "undefined" && Prefs.gtkThemingEnabled) {
console.log("Applying GTK theme...");
gtkThemeApplier.running = true;
}
// GTK theme application is now handled by the simplified generate-themes.sh script
ToastService.showInfo("System themes updated successfully");
} else {
@@ -382,43 +412,36 @@ palette = 15=${fg_b}`;
}
Process {
id: gtkThemeApplier
id: systemThemeRestoreProcess
running: false
stdout: StdioCollector {
id: gtkApplierStdout
id: restoreThemeStdout
}
stderr: StdioCollector {
id: gtkApplierStderr
id: restoreThemeStderr
}
onStarted: {
console.log("System theme restoration process started with command:", command);
}
onExited: (exitCode) => {
console.log("System theme restoration process exited with code:", exitCode);
if (exitCode === 0) {
console.log("GTK theme applied successfully");
ToastService.showInfo("GTK applications themed successfully");
console.log("System themes restored successfully");
console.log("stdout:", restoreThemeStdout.text);
ToastService.showInfo("System themes restored to default");
} else {
console.warn("GTK theme application failed, exit code:", exitCode);
console.warn("stderr:", gtkApplierStderr.text);
ToastService.showWarning("GTK theme application failed");
console.error("System theme restoration failed, exit code:", exitCode);
console.error("stdout:", restoreThemeStdout.text);
console.error("stderr:", restoreThemeStderr.text);
ToastService.showWarning("Failed to restore system themes: " + restoreThemeStderr.text);
}
}
Component.onCompleted: {
command = ["bash", "-c", `
# Reset GTK theme first
gsettings set org.gnome.desktop.interface gtk-theme '' 2>/dev/null || true
# Apply adw-gtk3-dark theme
gsettings set org.gnome.desktop.interface gtk-theme adw-gtk3-dark 2>/dev/null || true
# Import the generated colors
if [ -f ~/.config/gtk-3.0/colors.css ]; then
echo "GTK 3 colors imported"
fi
if [ -f ~/.config/gtk-4.0/colors.css ]; then
echo "GTK 4 colors imported"
fi
`];
}
}
}

View File

@@ -37,7 +37,7 @@ Singleton {
property string networkPreference: "auto"
property string iconTheme: "System Default"
property var availableIconThemes: ["System Default"]
property string systemDefaultIconTheme: "Adwaita"
property string systemDefaultIconTheme: ""
property bool qt5ctAvailable: false
property bool qt6ctAvailable: false
property bool useOSLogo: false
@@ -408,27 +408,40 @@ Singleton {
updateGtkIconTheme(themeName);
updateQtIconTheme(themeName);
saveSettings();
// If dynamic theme is active, regenerate system themes with new icon theme
if (typeof Theme !== "undefined" && Theme.isDynamicTheme && typeof Colors !== "undefined") {
console.log("Icon theme changed during dynamic theming - regenerating system themes");
Colors.generateSystemThemes();
}
}
function updateGtkIconTheme(themeName) {
console.log("Updating GTK icon theme to:", themeName);
var gtkThemeName = (themeName === "System Default") ? systemDefaultIconTheme : themeName;
var preferDark = (!isLightMode) ? "true" : "false";
var gtkSettings =
"[Settings]\n" +
"gtk-icon-theme-name=" + gtkThemeName + "\n" +
"gtk-theme-name=" + (isLightMode ? "Adwaita" : "Adwaita-dark") + "\n" +
"gtk-application-prefer-dark-theme=" + preferDark + "\n";
// Update icon theme via dconf/gsettings AND settings.ini files
if (gtkThemeName !== "System Default" && gtkThemeName !== "") {
var script =
"# Update dconf/gsettings\n" +
"if command -v dconf >/dev/null 2>&1; then\n" +
" dconf write /org/gnome/desktop/interface/icon-theme \\\"" + gtkThemeName + "\\\"\n" +
"elif command -v gsettings >/dev/null 2>&1; then\n" +
" gsettings set org.gnome.desktop.interface icon-theme '" + gtkThemeName + "'\n" +
"fi\n" +
"\n" +
"# Update settings.ini files (keep existing gtk-theme-name)\n" +
"for config_dir in ~/.config/gtk-3.0 ~/.config/gtk-4.0; do\n" +
" if [ -f \"$config_dir/settings.ini\" ]; then\n" +
" sed -i 's/^gtk-icon-theme-name=.*/gtk-icon-theme-name=" + gtkThemeName + "/' \"$config_dir/settings.ini\"\n" +
" fi\n" +
"done\n" +
"\n" +
"# Clear icon cache\n" +
"rm -rf ~/.cache/icon-cache ~/.cache/thumbnails 2>/dev/null || true\n";
var home = _shq(root._homeUrl.replace("file://", ""));
var script =
"mkdir -p " + home + "/.config/gtk-3.0 " + home + "/.config/gtk-4.0 2>/dev/null || true\n" +
"printf %s " + _shq(gtkSettings) + " > " + home + "/.config/gtk-3.0/settings.ini\n" +
"printf %s " + _shq(gtkSettings) + " > " + home + "/.config/gtk-4.0/settings.ini\n" +
"rm -rf " + home + "/.cache/icon-cache " + home + "/.cache/thumbnails 2>/dev/null || true\n";
Quickshell.execDetached(["sh", "-lc", script]);
Quickshell.execDetached(["sh", "-lc", script]);
}
}
function updateQtIconTheme(themeName) {
@@ -676,13 +689,13 @@ Singleton {
Process {
id: systemDefaultDetectionProcess
command: ["sh", "-c", "gsettings get org.gnome.desktop.interface icon-theme 2>/dev/null | sed \"s/'//g\" || echo 'Adwaita'"]
command: ["sh", "-c", "gsettings get org.gnome.desktop.interface icon-theme 2>/dev/null | sed \"s/'//g\" || echo ''"]
running: false
onExited: (exitCode) => {
if (exitCode === 0 && stdout && stdout.length > 0) {
systemDefaultIconTheme = stdout.trim();
} else {
systemDefaultIconTheme = "Adwaita";
systemDefaultIconTheme = "";
}
iconThemeDetectionProcess.running = true;
}

View File

@@ -466,6 +466,11 @@ Singleton {
console.error("Colors singleton not available");
}
} else if (themeIndex >= 0 && themeIndex < themes.length) {
// If switching away from dynamic theme, restore system themes
if (isDynamicTheme && typeof Colors !== "undefined") {
console.log("Switching away from dynamic theme, restoring system themes");
Colors.restoreSystemThemes();
}
currentThemeIndex = themeIndex;
isDynamicTheme = false;
}

69
check-theme-status.sh Executable file
View File

@@ -0,0 +1,69 @@
#!/bin/bash
# Theme verification script
echo "=== Theme Status Check ==="
# Check dconf/gsettings values
echo ""
echo "Current theme settings:"
if command -v dconf >/dev/null 2>&1; then
echo " color-scheme (dconf): $(dconf read /org/gnome/desktop/interface/color-scheme 2>/dev/null || echo 'not set')"
echo " gtk-theme (dconf): $(dconf read /org/gnome/desktop/interface/gtk-theme 2>/dev/null || echo 'not set')"
echo " icon-theme (dconf): $(dconf read /org/gnome/desktop/interface/icon-theme 2>/dev/null || echo 'not set')"
fi
if command -v gsettings >/dev/null 2>&1; then
echo " color-scheme (gsettings): $(gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null || echo 'not available')"
echo " gtk-theme (gsettings): $(gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null || echo 'not available')"
echo " icon-theme (gsettings): $(gsettings get org.gnome.desktop.interface icon-theme 2>/dev/null || echo 'not available')"
fi
# Check settings.ini files
echo ""
echo "GTK settings.ini files:"
for gtk_dir in ~/.config/gtk-3.0 ~/.config/gtk-4.0; do
if [ -f "$gtk_dir/settings.ini" ]; then
echo " $gtk_dir/settings.ini:"
grep -E "(gtk-theme-name|gtk-icon-theme-name|gtk-application-prefer-dark-theme)" "$gtk_dir/settings.ini" | sed 's/^/ /'
else
echo " $gtk_dir/settings.ini: not found"
fi
done
# Check for generated color files
echo ""
echo "Generated color files:"
for color_file in ~/.config/gtk-3.0/colors.css ~/.config/gtk-4.0/colors.css; do
if [ -f "$color_file" ]; then
echo " $color_file: exists ($(stat -c%y "$color_file" | cut -d' ' -f1,2))"
# Show first few lines to verify it has content
echo " Preview: $(head -3 "$color_file" | tr '\n' ' ')"
else
echo " $color_file: not found"
fi
done
# Check for Qt color schemes
echo ""
echo "Qt color schemes:"
if [ -f ~/.local/share/color-schemes/Matugen.colors ]; then
echo " Matugen.colors: exists ($(stat -c%y ~/.local/share/color-schemes/Matugen.colors | cut -d' ' -f1,2))"
else
echo " Matugen.colors: not found"
fi
# Test immediate effect
echo ""
echo "Testing immediate color-scheme change:"
if command -v dconf >/dev/null 2>&1; then
current_scheme=$(dconf read /org/gnome/desktop/interface/color-scheme 2>/dev/null)
echo " Current: $current_scheme"
echo " You can test by running:"
if [[ "$current_scheme" == *"dark"* ]]; then
echo " dconf write /org/gnome/desktop/interface/color-scheme '\"prefer-light\"'"
echo " (then switch back with: dconf write /org/gnome/desktop/interface/color-scheme '\"prefer-dark\"')"
else
echo " dconf write /org/gnome/desktop/interface/color-scheme '\"prefer-dark\"'"
echo " (then switch back with: dconf write /org/gnome/desktop/interface/color-scheme '\"prefer-light\"')"
fi
fi

View File

@@ -5,12 +5,67 @@
WALLPAPER_PATH="$1"
SHELL_DIR="$2"
MODE="$3" # "generate" or "restore"
IS_LIGHT="$4" # "true" for light mode, "false" for dark mode
ICON_THEME="$5" # Icon theme name
if [ -z "$WALLPAPER_PATH" ] || [ -z "$SHELL_DIR" ]; then
echo "Usage: $0 <wallpaper_path> <shell_dir>" >&2
if [ -z "$SHELL_DIR" ]; then
echo "Usage: $0 <wallpaper_path> <shell_dir> [mode] [is_light] [icon_theme]" >&2
echo " For restore mode, wallpaper_path can be empty" >&2
exit 1
fi
# Default values
MODE=${MODE:-"generate"}
IS_LIGHT=${IS_LIGHT:-"false"}
ICON_THEME=${ICON_THEME:-"System Default"}
update_theme_settings() {
local color_scheme="$1"
local icon_theme="$2"
echo "Updating theme settings..."
if command -v dconf >/dev/null 2>&1; then
dconf write /org/gnome/desktop/interface/color-scheme "\"$color_scheme\""
echo "Set color-scheme to: $color_scheme"
# Update icon theme if specified and not System Default
if [ "$icon_theme" != "System Default" ] && [ -n "$icon_theme" ]; then
dconf write /org/gnome/desktop/interface/icon-theme "\"$icon_theme\""
echo "Set icon-theme to: $icon_theme"
fi
elif command -v gsettings >/dev/null 2>&1; then
# Fallback to gsettings
gsettings set org.gnome.desktop.interface color-scheme "$color_scheme"
echo "Set color-scheme to: $color_scheme"
if [ "$icon_theme" != "System Default" ] && [ -n "$icon_theme" ]; then
gsettings set org.gnome.desktop.interface icon-theme "$icon_theme"
echo "Set icon-theme to: $icon_theme"
fi
else
echo "Warning: Neither dconf nor gsettings available"
fi
}
# Handle restore mode
if [ "$MODE" = "restore" ]; then
echo "Restoring default theme settings..."
color_scheme=""
if [ "$IS_LIGHT" = "true" ]; then
color_scheme="prefer-light"
else
color_scheme="prefer-dark"
fi
update_theme_settings "$color_scheme" "$ICON_THEME"
echo "Theme settings restored"
exit 0
fi
# Continue with generation mode
if [ ! -f "$WALLPAPER_PATH" ]; then
echo "Wallpaper file not found: $WALLPAPER_PATH" >&2
exit 1
@@ -27,7 +82,6 @@ mkdir -p ~/.config/gtk-3.0 ~/.config/gtk-4.0 ~/.config/qt5ct/colors ~/.config/qt
# Change to shell directory where matugen-config.toml is located
cd "$SHELL_DIR" || exit 1
# Verify config file exists
if [ ! -f "matugen-config.toml" ]; then
echo "Config file not found: $SHELL_DIR/matugen-config.toml" >&2
exit 1
@@ -42,4 +96,17 @@ if ! matugen -v -c matugen-config.toml image "$WALLPAPER_PATH"; then
exit 1
fi
echo "System theme files generated successfully"
# Set color scheme and icon theme based on light/dark mode
echo "Updating system theme preferences..."
color_scheme=""
if [ "$IS_LIGHT" = "true" ]; then
color_scheme="prefer-light"
else
color_scheme="prefer-dark"
fi
update_theme_settings "$color_scheme" "$ICON_THEME"
echo "System theme files generated successfully"
echo "Colors.css files should be available in ~/.config/gtk-3.0/ and ~/.config/gtk-4.0/"