From 4b2e8b6ef04de014dd0191263fa106d86455807c Mon Sep 17 00:00:00 2001 From: Sighthesia Date: Fri, 14 Nov 2025 17:18:23 +0800 Subject: [PATCH] SystemMonitor: transfer system monitor threshold settings to gloabal setting tab --- Assets/settings-default.json | 10 + Commons/Settings.qml | 12 + Modules/Bar/Widgets/SystemMonitor.qml | 18 +- .../WidgetSettings/SystemMonitorSettings.qml | 241 ------------------ Modules/Panels/Settings/SettingsPanel.qml | 13 +- .../Panels/Settings/Tabs/SystemMonitorTab.qml | 230 ++++++++++++++++- Services/UI/BarWidgetRegistry.qml | 10 +- 7 files changed, 264 insertions(+), 270 deletions(-) diff --git a/Assets/settings-default.json b/Assets/settings-default.json index 320adebc..a18fd1de 100644 --- a/Assets/settings-default.json +++ b/Assets/settings-default.json @@ -107,6 +107,16 @@ "audioSource": "default_output", "videoSource": "portal" }, + "systemMonitor": { + "cpuWarningThreshold": 80, + "cpuCriticalThreshold": 90, + "tempWarningThreshold": 80, + "tempCriticalThreshold": 90, + "memWarningThreshold": 80, + "memCriticalThreshold": 90, + "diskWarningThreshold": 80, + "diskCriticalThreshold": 90 + }, "wallpaper": { "enabled": true, "overviewEnabled": false, diff --git a/Commons/Settings.qml b/Commons/Settings.qml index 43e04798..c5be9107 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -321,6 +321,18 @@ Singleton { }] } + // system monitor + property JsonObject systemMonitor: JsonObject { + property int cpuWarningThreshold: 80 + property int cpuCriticalThreshold: 90 + property int tempWarningThreshold: 80 + property int tempCriticalThreshold: 90 + property int memWarningThreshold: 80 + property int memCriticalThreshold: 90 + property int diskWarningThreshold: 80 + property int diskCriticalThreshold: 90 + } + // dock property JsonObject dock: JsonObject { property bool enabled: true diff --git a/Modules/Bar/Widgets/SystemMonitor.qml b/Modules/Bar/Widgets/SystemMonitor.qml index f1d512dd..8bf78ba3 100644 --- a/Modules/Bar/Widgets/SystemMonitor.qml +++ b/Modules/Bar/Widgets/SystemMonitor.qml @@ -60,15 +60,15 @@ Rectangle { readonly property int memTextWidth: Math.ceil(memMetrics.boundingRect.width + 3) readonly property color textColor: usePrimaryColor ? Color.mPrimary : Color.mOnSurface - // Threshold settings from widget configuration - readonly property int cpuWarningThreshold: (widgetSettings.cpuWarningThreshold !== undefined) ? widgetSettings.cpuWarningThreshold : widgetMetadata.cpuWarningThreshold - readonly property int cpuCriticalThreshold: (widgetSettings.cpuCriticalThreshold !== undefined) ? widgetSettings.cpuCriticalThreshold : widgetMetadata.cpuCriticalThreshold - readonly property int tempWarningThreshold: (widgetSettings.tempWarningThreshold !== undefined) ? widgetSettings.tempWarningThreshold : widgetMetadata.tempWarningThreshold - readonly property int tempCriticalThreshold: (widgetSettings.tempCriticalThreshold !== undefined) ? widgetSettings.tempCriticalThreshold : widgetMetadata.tempCriticalThreshold - readonly property int memWarningThreshold: (widgetSettings.memWarningThreshold !== undefined) ? widgetSettings.memWarningThreshold : widgetMetadata.memWarningThreshold - readonly property int memCriticalThreshold: (widgetSettings.memCriticalThreshold !== undefined) ? widgetSettings.memCriticalThreshold : widgetMetadata.memCriticalThreshold - readonly property int diskWarningThreshold: (widgetSettings.diskWarningThreshold !== undefined) ? widgetSettings.diskWarningThreshold : widgetMetadata.diskWarningThreshold - readonly property int diskCriticalThreshold: (widgetSettings.diskCriticalThreshold !== undefined) ? widgetSettings.diskCriticalThreshold : widgetMetadata.diskCriticalThreshold + // Threshold settings from global configuration + readonly property int cpuWarningThreshold: Settings.data.systemMonitor.cpuWarningThreshold + readonly property int cpuCriticalThreshold: Settings.data.systemMonitor.cpuCriticalThreshold + readonly property int tempWarningThreshold: Settings.data.systemMonitor.tempWarningThreshold + readonly property int tempCriticalThreshold: Settings.data.systemMonitor.tempCriticalThreshold + readonly property int memWarningThreshold: Settings.data.systemMonitor.memWarningThreshold + readonly property int memCriticalThreshold: Settings.data.systemMonitor.memCriticalThreshold + readonly property int diskWarningThreshold: Settings.data.systemMonitor.diskWarningThreshold + readonly property int diskCriticalThreshold: Settings.data.systemMonitor.diskCriticalThreshold // Warning threshold calculation properties readonly property bool cpuWarning: showCpuUsage && SystemStatService.cpuUsage > cpuWarningThreshold diff --git a/Modules/Panels/Settings/Bar/WidgetSettings/SystemMonitorSettings.qml b/Modules/Panels/Settings/Bar/WidgetSettings/SystemMonitorSettings.qml index adc464fc..86c65b96 100644 --- a/Modules/Panels/Settings/Bar/WidgetSettings/SystemMonitorSettings.qml +++ b/Modules/Panels/Settings/Bar/WidgetSettings/SystemMonitorSettings.qml @@ -21,16 +21,6 @@ ColumnLayout { property bool valueShowNetworkStats: widgetData.showNetworkStats !== undefined ? widgetData.showNetworkStats : widgetMetadata.showNetworkStats property bool valueShowDiskUsage: widgetData.showDiskUsage !== undefined ? widgetData.showDiskUsage : widgetMetadata.showDiskUsage - // Threshold settings - property int valueCpuWarningThreshold: widgetData.cpuWarningThreshold !== undefined ? widgetData.cpuWarningThreshold : widgetMetadata.cpuWarningThreshold - property int valueCpuCriticalThreshold: widgetData.cpuCriticalThreshold !== undefined ? widgetData.cpuCriticalThreshold : widgetMetadata.cpuCriticalThreshold - property int valueTempWarningThreshold: widgetData.tempWarningThreshold !== undefined ? widgetData.tempWarningThreshold : widgetMetadata.tempWarningThreshold - property int valueTempCriticalThreshold: widgetData.tempCriticalThreshold !== undefined ? widgetData.tempCriticalThreshold : widgetMetadata.tempCriticalThreshold - property int valueMemWarningThreshold: widgetData.memWarningThreshold !== undefined ? widgetData.memWarningThreshold : widgetMetadata.memWarningThreshold - property int valueMemCriticalThreshold: widgetData.memCriticalThreshold !== undefined ? widgetData.memCriticalThreshold : widgetMetadata.memCriticalThreshold - property int valueDiskWarningThreshold: widgetData.diskWarningThreshold !== undefined ? widgetData.diskWarningThreshold : widgetMetadata.diskWarningThreshold - property int valueDiskCriticalThreshold: widgetData.diskCriticalThreshold !== undefined ? widgetData.diskCriticalThreshold : widgetMetadata.diskCriticalThreshold - function saveSettings() { var settings = Object.assign({}, widgetData || {}) settings.usePrimaryColor = valueUsePrimaryColor @@ -40,27 +30,6 @@ ColumnLayout { settings.showMemoryAsPercent = valueShowMemoryAsPercent settings.showNetworkStats = valueShowNetworkStats settings.showDiskUsage = valueShowDiskUsage - settings.cpuWarningThreshold = valueCpuWarningThreshold - settings.cpuCriticalThreshold = valueCpuCriticalThreshold - settings.tempWarningThreshold = valueTempWarningThreshold - settings.tempCriticalThreshold = valueTempCriticalThreshold - settings.memWarningThreshold = valueMemWarningThreshold - settings.memCriticalThreshold = valueMemCriticalThreshold - settings.diskWarningThreshold = valueDiskWarningThreshold - settings.diskCriticalThreshold = valueDiskCriticalThreshold - // Ensure critical thresholds are not less than their warning counterparts. - if (settings.cpuCriticalThreshold < settings.cpuWarningThreshold) { - settings.cpuCriticalThreshold = Math.min(100, settings.cpuWarningThreshold) - } - if (settings.tempCriticalThreshold < settings.tempWarningThreshold) { - settings.tempCriticalThreshold = Math.min(100, settings.tempWarningThreshold) - } - if (settings.memCriticalThreshold < settings.memWarningThreshold) { - settings.memCriticalThreshold = Math.min(100, settings.memWarningThreshold) - } - if (settings.diskCriticalThreshold < settings.diskWarningThreshold) { - settings.diskCriticalThreshold = Math.min(100, settings.diskWarningThreshold) - } return settings } @@ -127,214 +96,4 @@ ColumnLayout { checked: valueShowDiskUsage onToggled: checked => valueShowDiskUsage = checked } - - NDivider { - Layout.fillWidth: true - Layout.topMargin: Style.marginM - Layout.bottomMargin: Style.marginM - } - - NHeader { - Layout.fillWidth: true - label: I18n.tr("bar.widget-settings.system-monitor.thresholds.header") - description: I18n.tr("bar.widget-settings.system-monitor.thresholds.description") - } - - // CPU Usage Thresholds - RowLayout { - Layout.fillWidth: true - spacing: Style.marginM - visible: valueShowCpuUsage - - // Warning threshold - RowLayout { - Layout.fillWidth: true - spacing: Style.marginXS - - NText { - text: I18n.tr("bar.widget-settings.system-monitor.cpu-warning-threshold.label") - pointSize: Style.fontSizeS - Layout.alignment: Qt.AlignVCenter - } - - NSpinBox { - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 5 - value: valueCpuWarningThreshold - onValueChanged: valueCpuWarningThreshold = value - suffix: "%" - } - } - - // Critical threshold - RowLayout { - Layout.fillWidth: true - spacing: Style.marginXS - - NText { - text: I18n.tr("bar.widget-settings.system-monitor.cpu-critical-threshold.label") - pointSize: Style.fontSizeS - Layout.alignment: Qt.AlignVCenter - } - - NSpinBox { - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 5 - value: valueCpuCriticalThreshold - onValueChanged: valueCpuCriticalThreshold = value - suffix: "%" - } - } - } - - // Temperature Thresholds - RowLayout { - Layout.fillWidth: true - spacing: Style.marginM - visible: valueShowCpuTemp - - RowLayout { - Layout.fillWidth: true - spacing: Style.marginXS - - NText { - text: I18n.tr("bar.widget-settings.system-monitor.temp-warning-threshold.label") - pointSize: Style.fontSizeS - Layout.alignment: Qt.AlignVCenter - } - - NSpinBox { - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 5 - value: valueTempWarningThreshold - onValueChanged: valueTempWarningThreshold = value - suffix: "°C" - } - } - - RowLayout { - Layout.fillWidth: true - spacing: Style.marginXS - - NText { - text: I18n.tr("bar.widget-settings.system-monitor.temp-critical-threshold.label") - pointSize: Style.fontSizeS - Layout.alignment: Qt.AlignVCenter - } - - NSpinBox { - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 5 - value: valueTempCriticalThreshold - onValueChanged: valueTempCriticalThreshold = value - suffix: "°C" - } - } - } - - // Memory Usage Thresholds - RowLayout { - Layout.fillWidth: true - spacing: Style.marginM - visible: valueShowMemoryUsage - - RowLayout { - Layout.fillWidth: true - spacing: Style.marginXS - - NText { - text: I18n.tr("bar.widget-settings.system-monitor.mem-warning-threshold.label") - pointSize: Style.fontSizeS - Layout.alignment: Qt.AlignVCenter - } - - NSpinBox { - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 5 - value: valueMemWarningThreshold - onValueChanged: valueMemWarningThreshold = value - suffix: "%" - } - } - - RowLayout { - Layout.fillWidth: true - spacing: Style.marginXS - - NText { - text: I18n.tr("bar.widget-settings.system-monitor.mem-critical-threshold.label") - pointSize: Style.fontSizeS - Layout.alignment: Qt.AlignVCenter - } - - NSpinBox { - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 5 - value: valueMemCriticalThreshold - onValueChanged: valueMemCriticalThreshold = value - suffix: "%" - } - } - } - - // Storage Space Thresholds - RowLayout { - Layout.fillWidth: true - spacing: Style.marginM - visible: valueShowDiskUsage - - RowLayout { - Layout.fillWidth: true - spacing: Style.marginXS - - NText { - text: I18n.tr("bar.widget-settings.system-monitor.disk-warning-threshold.label") - pointSize: Style.fontSizeS - Layout.alignment: Qt.AlignVCenter - } - - NSpinBox { - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 5 - value: valueDiskWarningThreshold - onValueChanged: valueDiskWarningThreshold = value - suffix: "%" - } - } - - RowLayout { - Layout.fillWidth: true - spacing: Style.marginXS - - NText { - text: I18n.tr("bar.widget-settings.system-monitor.disk-critical-threshold.label") - pointSize: Style.fontSizeS - Layout.alignment: Qt.AlignVCenter - } - - NSpinBox { - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 5 - value: valueDiskCriticalThreshold - onValueChanged: valueDiskCriticalThreshold = value - suffix: "%" - } - } - } } diff --git a/Modules/Panels/Settings/SettingsPanel.qml b/Modules/Panels/Settings/SettingsPanel.qml index c0dda187..f562a481 100644 --- a/Modules/Panels/Settings/SettingsPanel.qml +++ b/Modules/Panels/Settings/SettingsPanel.qml @@ -264,13 +264,12 @@ SmartPanel { "label": "settings.session-menu.title", "icon": "settings-session-menu", "source": sessionMenuTab - }, // { - // "id": SettingsPanel.Tab.SystemMonitor, - // "label": "settings.system-monitor.title", - // "icon": "settings-system-monitor", - // "source": systemMonitorTab - // }, - { + }, { + "id": SettingsPanel.Tab.SystemMonitor, + "label": "settings.system-monitor.title", + "icon": "settings-system-monitor", + "source": systemMonitorTab + }, { "id": SettingsPanel.Tab.Hooks, "label": "settings.hooks.title", "icon": "settings-hooks", diff --git a/Modules/Panels/Settings/Tabs/SystemMonitorTab.qml b/Modules/Panels/Settings/Tabs/SystemMonitorTab.qml index 80d58f33..cd36f80b 100644 --- a/Modules/Panels/Settings/Tabs/SystemMonitorTab.qml +++ b/Modules/Panels/Settings/Tabs/SystemMonitorTab.qml @@ -11,12 +11,234 @@ ColumnLayout { spacing: Style.marginL - Component.onCompleted: { - - } - NHeader { + Layout.fillWidth: true label: I18n.tr("settings.system-monitor.general.section.label") description: I18n.tr("settings.system-monitor.general.section.description") } + + // CPU Usage Thresholds + NText { + Layout.fillWidth: true + Layout.topMargin: Style.marginM + text: I18n.tr("settings.system-monitor.cpu-section.label") + pointSize: Style.fontSizeM + } + + RowLayout { + Layout.fillWidth: true + spacing: Style.marginM + + ColumnLayout { + Layout.fillWidth: true + spacing: Style.marginM + + NText { + text: I18n.tr("settings.system-monitor.cpu-warning-threshold.label") + pointSize: Style.fontSizeS + } + + NSpinBox { + from: 0 + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.cpuWarningThreshold + onValueChanged: { + Settings.data.systemMonitor.cpuWarningThreshold = value + // Ensure critical >= warning + if (Settings.data.systemMonitor.cpuCriticalThreshold < value) { + Settings.data.systemMonitor.cpuCriticalThreshold = value + } + } + suffix: "%" + } + } + + ColumnLayout { + Layout.fillWidth: true + spacing: Style.marginM + + NText { + text: I18n.tr("settings.system-monitor.cpu-critical-threshold.label") + pointSize: Style.fontSizeS + } + + NSpinBox { + from: Settings.data.systemMonitor.cpuWarningThreshold + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.cpuCriticalThreshold + onValueChanged: Settings.data.systemMonitor.cpuCriticalThreshold = value + suffix: "%" + } + } + } + + // Temperature Thresholds + NText { + Layout.fillWidth: true + Layout.topMargin: Style.marginM + text: I18n.tr("settings.system-monitor.temperature-section.label") + pointSize: Style.fontSizeM + } + + RowLayout { + Layout.fillWidth: true + spacing: Style.marginM + + ColumnLayout { + Layout.fillWidth: true + spacing: Style.marginM + + NText { + text: I18n.tr("settings.system-monitor.temp-warning-threshold.label") + pointSize: Style.fontSizeS + } + + NSpinBox { + from: 0 + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.tempWarningThreshold + onValueChanged: { + Settings.data.systemMonitor.tempWarningThreshold = value + if (Settings.data.systemMonitor.tempCriticalThreshold < value) { + Settings.data.systemMonitor.tempCriticalThreshold = value + } + } + suffix: "°C" + } + } + + ColumnLayout { + Layout.fillWidth: true + spacing: Style.marginM + + NText { + text: I18n.tr("settings.system-monitor.temp-critical-threshold.label") + pointSize: Style.fontSizeS + } + + NSpinBox { + from: Settings.data.systemMonitor.tempWarningThreshold + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.tempCriticalThreshold + onValueChanged: Settings.data.systemMonitor.tempCriticalThreshold = value + suffix: "°C" + } + } + } + + // Memory Usage Thresholds + NText { + Layout.fillWidth: true + Layout.topMargin: Style.marginM + text: I18n.tr("settings.system-monitor.memory-section.label") + pointSize: Style.fontSizeM + } + + RowLayout { + Layout.fillWidth: true + spacing: Style.marginM + + ColumnLayout { + Layout.fillWidth: true + spacing: Style.marginM + + NText { + text: I18n.tr("settings.system-monitor.mem-warning-threshold.label") + pointSize: Style.fontSizeS + } + + NSpinBox { + from: 0 + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.memWarningThreshold + onValueChanged: { + Settings.data.systemMonitor.memWarningThreshold = value + if (Settings.data.systemMonitor.memCriticalThreshold < value) { + Settings.data.systemMonitor.memCriticalThreshold = value + } + } + suffix: "%" + } + } + + ColumnLayout { + Layout.fillWidth: true + spacing: Style.marginM + + NText { + text: I18n.tr("settings.system-monitor.mem-critical-threshold.label") + pointSize: Style.fontSizeS + } + + NSpinBox { + from: Settings.data.systemMonitor.memWarningThreshold + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.memCriticalThreshold + onValueChanged: Settings.data.systemMonitor.memCriticalThreshold = value + suffix: "%" + } + } + } + + // Disk Usage Thresholds + NText { + Layout.fillWidth: true + Layout.topMargin: Style.marginM + text: I18n.tr("settings.system-monitor.disk-section.label") + pointSize: Style.fontSizeM + } + + RowLayout { + Layout.fillWidth: true + spacing: Style.marginM + + ColumnLayout { + Layout.fillWidth: true + spacing: Style.marginM + + NText { + text: I18n.tr("settings.system-monitor.disk-warning-threshold.label") + pointSize: Style.fontSizeS + } + + NSpinBox { + from: 0 + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.diskWarningThreshold + onValueChanged: { + Settings.data.systemMonitor.diskWarningThreshold = value + if (Settings.data.systemMonitor.diskCriticalThreshold < value) { + Settings.data.systemMonitor.diskCriticalThreshold = value + } + } + suffix: "%" + } + } + + ColumnLayout { + Layout.fillWidth: true + spacing: Style.marginM + + NText { + text: I18n.tr("settings.system-monitor.disk-critical-threshold.label") + pointSize: Style.fontSizeS + } + + NSpinBox { + from: Settings.data.systemMonitor.diskWarningThreshold + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.diskCriticalThreshold + onValueChanged: Settings.data.systemMonitor.diskCriticalThreshold = value + suffix: "%" + } + } + } } diff --git a/Services/UI/BarWidgetRegistry.qml b/Services/UI/BarWidgetRegistry.qml index 1719d819..c4133e47 100644 --- a/Services/UI/BarWidgetRegistry.qml +++ b/Services/UI/BarWidgetRegistry.qml @@ -150,15 +150,7 @@ Singleton { "showMemoryUsage": true, "showMemoryAsPercent": false, "showNetworkStats": false, - "showDiskUsage": false, - "cpuWarningThreshold": 80, - "cpuCriticalThreshold": 90, - "tempWarningThreshold": 80, - "tempCriticalThreshold": 90, - "memWarningThreshold": 80, - "memCriticalThreshold": 90, - "diskWarningThreshold": 80, - "diskCriticalThreshold": 90 + "showDiskUsage": false }, "Taskbar": { "allowUserSettings": true,