mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-28 07:22:50 -05:00
Update auto theme logic
This commit is contained in:
@@ -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
|
||||
`];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user