From d8113d2a0289d7fb4b074207d3e08fb22e1b6843 Mon Sep 17 00:00:00 2001 From: purian23 Date: Mon, 5 Oct 2026 03:00:11 -0400 Subject: [PATCH] add(digital wellbeing): ipc targets for tracking status & limits --- quickshell/Common/KeybindActions.js | 8 +++ quickshell/Services/WellbeingService.qml | 64 ++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/quickshell/Common/KeybindActions.js b/quickshell/Common/KeybindActions.js index e1b23d24a..46f9a468b 100644 --- a/quickshell/Common/KeybindActions.js +++ b/quickshell/Common/KeybindActions.js @@ -284,6 +284,10 @@ const DMS_ACTIONS = [ id: "spawn dms ipc call dash open weather", label: "Dashboard: Weather" }, + { + id: "spawn dms ipc call dash open wellbeing", + label: "Dashboard: Digital Wellbeing" + }, { id: "spawn dms ipc call dankdash wallpaper", label: "Wallpaper Browser" @@ -458,6 +462,10 @@ const DMS_ACTIONS = [ id: "spawn dms ipc call night disable", label: "Night Mode: Disable" }, + { + id: "spawn dms ipc call wellbeing toggle", + label: "Screen Time Tracking: Toggle" + }, { id: "spawn dms ipc call bar toggle index 0", label: "Bar: Toggle (Primary)" diff --git a/quickshell/Services/WellbeingService.qml b/quickshell/Services/WellbeingService.qml index 4c2812576..b7a42b35c 100644 --- a/quickshell/Services/WellbeingService.qml +++ b/quickshell/Services/WellbeingService.qml @@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound import QtQuick import Quickshell +import Quickshell.Io import Quickshell.Wayland import qs.Common import qs.Services @@ -188,4 +189,67 @@ Singleton { return I18n.tr("%1m").arg(split.minutes); return I18n.tr("%1h %2m").arg(split.hours).arg(split.minutes); } + + function parseMinutes(value) { + const minutes = Number(value); + return Number.isInteger(minutes) && minutes >= 0 ? minutes : -1; + } + + function formatLimit(minutes) { + return minutes > 0 ? formatDuration(minutes * 60) : "none"; + } + + IpcHandler { + function enable(): string { + SettingsData.set("wellbeingEnabled", true); + return "Screen time tracking enabled"; + } + + function disable(): string { + SettingsData.set("wellbeingEnabled", false); + return "Screen time tracking disabled"; + } + + function toggle(): string { + return SettingsData.wellbeingEnabled ? disable() : enable(); + } + + function status(): string { + if (!root.available) + return "Screen time tracking: unavailable (DMS server without wellbeing support)"; + const lines = ["Screen time tracking: " + (root.enabled ? "enabled" : "disabled")]; + if (root.tracking) + lines.push("Today: " + root.formatDuration(root.today.active ?? 0)); + lines.push("Daily limit: " + root.formatLimit(SettingsData.wellbeingDailyLimit)); + return lines.join("\n"); + } + + function today(): string { + return String(root.tracking ? root.today.active ?? 0 : 0); + } + + function dailyLimit(minutes: string): string { + if (minutes === "") + return root.formatLimit(SettingsData.wellbeingDailyLimit); + const parsed = root.parseMinutes(minutes); + if (parsed < 0) + return "Invalid limit. Use whole minutes, 0 to clear."; + SettingsData.set("wellbeingDailyLimit", parsed); + return "Daily limit: " + root.formatLimit(parsed); + } + + function appLimit(appId: string, minutes: string): string { + if (!appId) + return "Missing app id"; + if (minutes === "") + return root.formatLimit(root.appLimitMinutes(appId)); + const parsed = root.parseMinutes(minutes); + if (parsed < 0) + return "Invalid limit. Use whole minutes, 0 to clear."; + root.setAppLimit(appId, parsed); + return root.appName(appId) + " limit: " + root.formatLimit(parsed); + } + + target: "wellbeing" + } }