Created Hook system (let's users run commands after specific actions)

NInputAction: create NTextInput with NButton
HooksService: add dark/light mode hook, add wallpaper change hook
HooksTab: create 1 NInputAction for each hook
Wallpaper: add hook functionallity
This commit is contained in:
Ly-sec 2025-09-04 17:54:58 +02:00
parent d53a404bf1
commit 37eefe3663
9 changed files with 274 additions and 3 deletions

63
Services/HooksService.qml Normal file
View file

@ -0,0 +1,63 @@
pragma Singleton
import QtQuick
import Quickshell
import qs.Commons
import qs.Services
Singleton {
id: root
// Hook connections for automatic script execution
Connections {
target: Settings.data.colorSchemes
function onDarkModeChanged() {
executeDarkModeHook(Settings.data.colorSchemes.darkMode)
}
}
// Execute wallpaper change hook
function executeWallpaperHook(wallpaperPath) {
if (!Settings.data.hooks?.enabled) {
return
}
const script = Settings.data.hooks?.wallpaperChange
if (!script || script === "") {
return
}
try {
const command = script.replace(/\$1/g, wallpaperPath)
Quickshell.execDetached(["sh", "-c", command])
Logger.log("HooksService", `Executed wallpaper hook: ${command}`)
} catch (e) {
Logger.error("HooksService", `Failed to execute wallpaper hook: ${e}`)
}
}
// Execute dark mode change hook
function executeDarkModeHook(isDarkMode) {
if (!Settings.data.hooks?.enabled) {
return
}
const script = Settings.data.hooks?.darkModeChange
if (!script || script === "") {
return
}
try {
const command = script.replace(/\$1/g, isDarkMode ? "true" : "false")
Quickshell.execDetached(["sh", "-c", command])
Logger.log("HooksService", `Executed dark mode hook: ${command}`)
} catch (e) {
Logger.error("HooksService", `Failed to execute dark mode hook: ${e}`)
}
}
// Initialize the service
function init() {
Logger.log("HooksService", "Service initialized")
}
}

View file

@ -256,6 +256,11 @@ Singleton {
// Update cache directly
currentWallpapers[screenName] = path
// Execute wallpaper change hook
if (HooksService) {
HooksService.executeWallpaperHook(path)
}
// Update Settings - still need immutable update for Settings persistence
// The slice() ensures Settings detects the change and saves properly
var monitors = Settings.data.wallpaper.monitors || []