feat(hooks): added a simple color generation hook

This commit is contained in:
Lemmy
2026-03-15 10:23:13 -04:00
parent 684414773b
commit 1454ef24e1
4 changed files with 41 additions and 1 deletions
+4 -1
View File
@@ -1221,7 +1221,10 @@
},
"hooks": {
"info-command-info-description": "• Commands are executed via shell (sh -lc)<br>• Commands run in background (detached)<br>• Test buttons execute with current values",
"info-parameters-description": "• Wallpaper hook: $1 = wallpaper path, $2 = screen name, $3 = theme (dark/light)<br>• Theme toggle hook: $1 = true/false (Dark Mode state)<br>• Screen lock/unlock hooks: $1 = lock/unlock (screen lock state)<br>• Performance mode hooks: No parameters<br>• Session hook: $1 = action (shutdown/reboot)",
"color-generation-description": "Command to be executed when color generation completes (e.g. after wallpaper-based theming).",
"color-generation-label": "Colors generated",
"color-generation-placeholder": "e.g. notify-send \"Colors\" \"Generated\"",
"info-parameters-description": "• Wallpaper hook: $1 = wallpaper path, $2 = screen name, $3 = theme (dark/light)<br>• Color generation hook: $1 = theme (dark/light)<br>• Theme toggle hook: $1 = true/false (Dark Mode state)<br>• Screen lock/unlock hooks: $1 = lock/unlock (screen lock state)<br>• Performance mode hooks: No parameters<br>• Session hook: $1 = action (shutdown/reboot)",
"info-parameters-label": "Available parameters",
"noctalia-started-description": "Command to execute when Noctalia has finished loading.",
"noctalia-started-label": "Noctalia started",
+1
View File
@@ -738,6 +738,7 @@ Singleton {
property string performanceModeDisabled: ""
property string startup: ""
property string session: ""
property string colorGeneration: ""
}
// plugins
@@ -72,6 +72,20 @@ ColumnLayout {
})
}
// Color Generation Hook
HookRow {
label: I18n.tr("panels.hooks.color-generation-label")
description: I18n.tr("panels.hooks.color-generation-description")
value: Settings.data.hooks.colorGeneration
onEditClicked: openEdit(label, description, I18n.tr("panels.hooks.color-generation-placeholder"), value, newValue => {
Settings.data.hooks.colorGeneration = newValue;
Settings.saveImmediate();
}, val => {
if (val)
Quickshell.execDetached(["sh", "-lc", val.replace("$1", "dark")]);
})
}
// Theme Hook
HookRow {
label: I18n.tr("panels.hooks.theme-changed-label")
+22
View File
@@ -55,6 +55,7 @@ Singleton {
root.pendingWallpaperHook = null;
executeWallpaperHook(hook.path, hook.screenName);
}
executeColorGenerationHook();
}
}
@@ -225,6 +226,27 @@ Singleton {
}
}
// Execute color generation hook
function executeColorGenerationHook() {
if (!Settings.data.hooks?.enabled) {
return;
}
const script = Settings.data.hooks?.colorGeneration;
if (!script || script === "") {
return;
}
try {
const theme = Settings.data.colorSchemes.darkMode ? "dark" : "light";
const command = script.replace(/\$1/g, theme);
Quickshell.execDetached(["sh", "-lc", command]);
Logger.d("HooksService", `Executed color generation hook: ${command}`);
} catch (e) {
Logger.e("HooksService", `Failed to execute color generation hook: ${e}`);
}
}
// Blocking power hook infrastructure
property var pendingPowerCallback: null