pragma Singleton import QtQuick import Quickshell import Quickshell.Io // Game Mode: compositor effects off, performance power profile and Do Not // Disturb while gaming, switched by hand. The helper journals what it changed, // so effects and the profile come back even after a shell crash. Singleton { id: root property string helper: "helpers/gamemode.py" property bool active: false property string error: "" readonly property var options: ConfigService.ready ? ConfigService.data.gameMode : ({ effects: true, doNotDisturb: true, performance: true }) // What is applied right now, and the DND state to put back. property bool applied: false property var restoreDnd: null function toggle() { active = !active; return true; } // Debounced, so quick double clicks settle on the last state. onActiveChanged: sync.restart() Timer { id: sync interval: 250 onTriggered: root.apply() } function apply() { if (root.active === root.applied) return; if (job.running) { sync.restart(); return; } applied = active; job.start({ action: active ? "on" : "off", effects: options.effects, performance: options.performance }); if (active && options.doNotDisturb && NotificationService.active && !NotificationService.dnd) { restoreDnd = false; NotificationService.setDnd(true); } else if (!active && restoreDnd !== null) { NotificationService.setDnd(restoreDnd); restoreDnd = null; } } // A crash while on left effects off: put back what the journal holds. Component.onCompleted: job.start({ action: "off" }) ProviderJob { id: job helper: root.helper onFinished: (request, result) => { root.error = result.ok ? "" : result.error || "Game Mode request failed"; // A change while the request ran is applied now. if (root.active !== root.applied) sync.restart(); } } IpcHandler { target: "gamemode" function toggle(): bool { return root.toggle(); } function status(): string { return JSON.stringify({ active: root.active, applied: root.applied, error: root.error }); } } }