noctalia-shell/Services/HooksService.qml
Ly-sec 37eefe3663 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
2025-09-04 17:54:58 +02:00

63 lines
1.5 KiB
QML

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")
}
}