1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 05:55:37 -05:00

Optimize services to reduce load

This commit is contained in:
purian23
2025-07-29 21:56:41 -04:00
parent df147ff9b9
commit 35c6efdcc5
6 changed files with 134 additions and 6 deletions

View File

@@ -67,7 +67,7 @@ Item {
id: fallbackTimer
running: false
interval: 100
interval: 256
repeat: true
onTriggered: {
root.audioLevels = [Math.random() * 40 + 10, Math.random() * 60 + 20, Math.random() * 50 + 15, Math.random() * 35 + 20, Math.random() * 45 + 15, Math.random() * 55 + 25];

60
Services/IdleService.qml Normal file
View File

@@ -0,0 +1,60 @@
pragma Singleton
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Io
Singleton {
id: root
property bool isIdle: false
property int idleThresholdSeconds: 300 // 5 minutes
property int checkInterval: 30000 // Check every 30 seconds
signal idleChanged(bool idle)
function checkIdleState() {
if (idleChecker.running) return
idleChecker.running = true
}
Timer {
id: idleTimer
interval: root.checkInterval
running: true
repeat: true
onTriggered: root.checkIdleState()
}
Process {
id: idleChecker
command: ["bash", "-c", "if command -v xprintidle >/dev/null 2>&1; then echo $(( $(xprintidle) / 1000 )); elif command -v qdbus >/dev/null 2>&1; then qdbus org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver GetSessionIdleTime 2>/dev/null || echo 0; else echo 0; fi"]
running: false
stdout: SplitParser {
splitMarker: "\n"
onRead: (data) => {
const idleSeconds = parseInt(data.trim()) || 0
const wasIdle = root.isIdle
root.isIdle = idleSeconds >= root.idleThresholdSeconds
if (wasIdle !== root.isIdle) {
console.log("IdleService: System idle state changed to:", root.isIdle ? "idle" : "active", "(" + idleSeconds + "s)")
root.idleChanged(root.isIdle)
}
}
}
onExited: (exitCode) => {
if (exitCode !== 0) {
console.warn("IdleService: Failed to check idle state, exit code:", exitCode)
}
}
}
Component.onCompleted: {
console.log("IdleService: Initialized with", root.idleThresholdSeconds + "s threshold")
checkIdleState()
}
}

View File

@@ -9,6 +9,7 @@ import qs.Common
Singleton {
id: root
property int refCount: 0
property string networkStatus: "disconnected" // "ethernet", "wifi", "disconnected"
property string ethernetIP: ""
property string ethernetInterface: ""
@@ -42,6 +43,25 @@ Singleton {
signal networksUpdated()
function addRef() {
refCount++;
console.log("NetworkService: addRef, refCount now:", refCount);
if (refCount === 1) {
// Start monitoring when first consumer appears
networkStatusChecker.running = true;
}
}
function removeRef() {
refCount = Math.max(0, refCount - 1);
console.log("NetworkService: removeRef, refCount now:", refCount);
if (refCount === 0) {
// Stop monitoring when no consumers
networkStatusChecker.running = false;
autoRefreshTimer.running = false;
}
}
// Load saved preference on startup
Component.onCompleted: {
// Load preference from Prefs system
@@ -58,7 +78,7 @@ Singleton {
Process {
id: networkStatusChecker
command: ["sh", "-c", "nmcli -t -f DEVICE,TYPE,STATE device | grep -E '(ethernet|wifi)' && echo '---' && ip link show | grep -E '^[0-9]+:.*ethernet.*state UP'"]
running: true
running: false
stdout: StdioCollector {
onStreamFinished: {
@@ -519,7 +539,7 @@ Singleton {
Timer {
id: autoRefreshTimer
interval: 20000
running: root.autoRefreshEnabled
running: root.autoRefreshEnabled && root.refCount > 0
repeat: true
onTriggered: scanWifi()
}

View File

@@ -4,12 +4,13 @@ pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Services
Singleton {
id: root
property int refCount: 0
property int updateInterval: 8000
property int updateInterval: 30000
property int maxProcesses: 100
property bool isUpdating: false
@@ -360,11 +361,26 @@ Singleton {
Timer {
id: updateTimer
interval: root.updateInterval
running: root.refCount > 0
running: root.refCount > 0 && !IdleService.isIdle
repeat: true
triggeredOnStart: true
onTriggered: root.updateAllStats()
}
Connections {
target: IdleService
function onIdleChanged(idle) {
if (idle) {
console.log("SysMonitorService: System idle, pausing monitoring")
} else {
console.log("SysMonitorService: System active, resuming monitoring")
if (root.refCount > 0) {
// Trigger immediate update when coming back from idle
root.updateAllStats()
}
}
}
}
readonly property string scriptBody: `set -Eeuo pipefail
trap 'echo "ERR at line $LINENO: $BASH_COMMAND (exit $?)" >&2' ERR

View File

@@ -5,6 +5,7 @@ import QtQuick
import Quickshell
import Quickshell.Io
import qs.Common
import qs.Services
Singleton {
id: root
@@ -239,7 +240,7 @@ Singleton {
Timer {
id: updateTimer
interval: root.updateInterval
running: root.refCount > 0
running: root.refCount > 0 && !IdleService.isIdle
repeat: true
triggeredOnStart: true
onTriggered: {
@@ -247,6 +248,21 @@ Singleton {
}
}
Connections {
target: IdleService
function onIdleChanged(idle) {
if (idle) {
console.log("WeatherService: System idle, pausing weather updates")
} else {
console.log("WeatherService: System active, resuming weather updates")
if (root.refCount > 0 && !root.weather.available) {
// Trigger immediate update when coming back from idle if no data
root.fetchWeather()
}
}
}
}
Timer {
id: retryTimer
interval: root.retryDelay

16
Services/qmldir Normal file
View File

@@ -0,0 +1,16 @@
singleton AppSearchService 1.0 AppSearchService.qml
singleton AudioService 1.0 AudioService.qml
singleton BatteryService 1.0 BatteryService.qml
singleton BluetoothService 1.0 BluetoothService.qml
singleton BrightnessService 1.0 BrightnessService.qml
singleton CalendarService 1.0 CalendarService.qml
singleton FocusedWindowService 1.0 FocusedWindowService.qml
singleton IdleService 1.0 IdleService.qml
singleton MprisController 1.0 MprisController.qml
singleton NetworkService 1.0 NetworkService.qml
singleton NiriService 1.0 NiriService.qml
singleton NotificationService 1.0 NotificationService.qml
singleton SysMonitorService 1.0 SysMonitorService.qml
singleton ToastService 1.0 ToastService.qml
singleton UserInfoService 1.0 UserInfoService.qml
singleton WeatherService 1.0 WeatherService.qml