diff --git a/Assets/settings-default.json b/Assets/settings-default.json index adafe774e..2ef5f0338 100644 --- a/Assets/settings-default.json +++ b/Assets/settings-default.json @@ -274,6 +274,8 @@ "diskCriticalThreshold": 90, "diskAvailWarningThreshold": 20, "diskAvailCriticalThreshold": 10, + "batteryWarningThreshold": 20, + "batteryCriticalThreshold": 5, "cpuPollingInterval": 1000, "gpuPollingInterval": 3000, "enableDgpuMonitoring": false, @@ -371,8 +373,7 @@ }, "enableMediaToast": false, "enableKeyboardLayoutToast": true, - "batteryWarningThreshold": 20, - "batteryCriticalThreshold": 5 + "enableBatteryToast": true }, "osd": { "enabled": true, diff --git a/Assets/settings-search-index.json b/Assets/settings-search-index.json index b86ab9174..19344f80e 100644 --- a/Assets/settings-search-index.json +++ b/Assets/settings-search-index.json @@ -1171,7 +1171,7 @@ { "labelKey": "panels.notifications.toast-battery-label", "descriptionKey": "panels.notifications.toast-battery-description", - "widget": "NLabel", + "widget": "NCheckbox", "tab": 9, "tabLabel": "common.notifications", "subTab": 4, diff --git a/Assets/settings-widgets-default.json b/Assets/settings-widgets-default.json index 19ff9fc74..426ffefe4 100644 --- a/Assets/settings-widgets-default.json +++ b/Assets/settings-widgets-default.json @@ -14,7 +14,7 @@ "hideWhenIdle": false }, "Battery": { - "displayMode": "graphic", + "displayMode": "graphic-clean", "deviceNativePath": "__default__", "showPowerProfiles": false, "showNoctaliaPerformance": false, diff --git a/Commons/Migrations/Migration48.qml b/Commons/Migrations/Migration48.qml new file mode 100644 index 000000000..a775e95e2 --- /dev/null +++ b/Commons/Migrations/Migration48.qml @@ -0,0 +1,22 @@ +import QtQuick + +QtObject { + id: root + + // Migrate battery thresholds from notifications to systemMonitor + function migrate(adapter, logger, rawJson) { + logger.i("Settings", "Migrating settings to v48"); + + if (rawJson?.notifications?.batteryWarningThreshold !== undefined) { + adapter.systemMonitor.batteryWarningThreshold = rawJson.notifications.batteryWarningThreshold; + logger.i("Settings", "Migrated notifications.batteryWarningThreshold to systemMonitor: " + adapter.systemMonitor.batteryWarningThreshold); + } + + if (rawJson?.notifications?.batteryCriticalThreshold !== undefined) { + adapter.systemMonitor.batteryCriticalThreshold = rawJson.notifications.batteryCriticalThreshold; + logger.i("Settings", "Migrated notifications.batteryCriticalThreshold to systemMonitor: " + adapter.systemMonitor.batteryCriticalThreshold); + } + + return true; + } +} diff --git a/Commons/Migrations/MigrationRegistry.qml b/Commons/Migrations/MigrationRegistry.qml index c8f14de70..a69ddf265 100644 --- a/Commons/Migrations/MigrationRegistry.qml +++ b/Commons/Migrations/MigrationRegistry.qml @@ -21,7 +21,8 @@ QtObject { 44: migration44Component, 45: migration45Component, 46: migration46Component, - 47: migration47Component + 47: migration47Component, + 48: migration48Component }) // Migration components @@ -40,4 +41,5 @@ QtObject { property Component migration45Component: Migration45 {} property Component migration46Component: Migration46 {} property Component migration47Component: Migration47 {} + property Component migration48Component: Migration48 {} } diff --git a/Commons/Settings.qml b/Commons/Settings.qml index b194e0393..1dd05d5de 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -25,7 +25,7 @@ Singleton { - Default cache directory: ~/.cache/noctalia */ readonly property alias data: adapter // Used to access via Settings.data.xxx.yyy - readonly property int settingsVersion: 47 + readonly property int settingsVersion: 48 readonly property bool isDebug: Quickshell.env("NOCTALIA_DEBUG") === "1" readonly property string shellName: "noctalia" readonly property string configDir: Quickshell.env("NOCTALIA_CONFIG_DIR") || (Quickshell.env("XDG_CONFIG_HOME") || Quickshell.env("HOME") + "/.config") + "/" + shellName + "/" @@ -486,6 +486,8 @@ Singleton { property int diskCriticalThreshold: 90 property int diskAvailWarningThreshold: 20 property int diskAvailCriticalThreshold: 10 + property int batteryWarningThreshold: 20 + property int batteryCriticalThreshold: 5 property int cpuPollingInterval: 1000 property int gpuPollingInterval: 3000 property bool enableDgpuMonitoring: false // Opt-in: reading dGPU sysfs/nvidia-smi wakes it from D3cold, draining battery @@ -592,8 +594,7 @@ Singleton { } property bool enableMediaToast: false property bool enableKeyboardLayoutToast: true - property int batteryWarningThreshold: 20 - property int batteryCriticalThreshold: 5 + property bool enableBatteryToast: true } // on-screen display diff --git a/Modules/Bar/Widgets/Battery.qml b/Modules/Bar/Widgets/Battery.qml index e4c31fcf0..ed8573302 100644 --- a/Modules/Bar/Widgets/Battery.qml +++ b/Modules/Bar/Widgets/Battery.qml @@ -76,7 +76,6 @@ Item { } let rateText = BatteryService.getRateText(selectedDevice); - console.log(rateText); if (rateText) { const entries = rateText.split(":").map(a => a.trim()); rows.push(entries); diff --git a/Modules/Panels/Settings/Tabs/Notifications/ToastSubTab.qml b/Modules/Panels/Settings/Tabs/Notifications/ToastSubTab.qml index 33b1ddcff..f6aa029ac 100644 --- a/Modules/Panels/Settings/Tabs/Notifications/ToastSubTab.qml +++ b/Modules/Panels/Settings/Tabs/Notifications/ToastSubTab.qml @@ -25,69 +25,11 @@ ColumnLayout { onToggled: checked => Settings.data.notifications.enableKeyboardLayoutToast = checked } - NDivider { + NCheckbox { Layout.fillWidth: true - } - - RowLayout { - - NLabel { - label: I18n.tr("panels.notifications.toast-battery-label") - description: I18n.tr("panels.notifications.toast-battery-description") - } - - Item { - Layout.fillWidth: true - } - - GridLayout { - Layout.fillWidth: true - columns: 2 - columnSpacing: Style.marginM - rowSpacing: Style.marginM - - NText { - Layout.alignment: Qt.AlignHCenter - horizontalAlignment: Text.AlignHCenter - text: I18n.tr("panels.system-monitor.threshold-warning") - pointSize: Style.fontSizeS - color: Color.mOnSurfaceVariant - } - - NText { - Layout.alignment: Qt.AlignHCenter - horizontalAlignment: Text.AlignHCenter - text: I18n.tr("panels.system-monitor.threshold-critical") - pointSize: Style.fontSizeS - color: Color.mOnSurfaceVariant - } - - NSpinBox { - Layout.alignment: Qt.AlignHCenter - from: 0 - to: 100 - stepSize: 5 - value: Settings.data.notifications.batteryWarningThreshold - defaultValue: Settings.getDefaultValue("notifications.batteryWarningThreshold") - suffix: "%" - onValueChanged: { - Settings.data.notifications.batteryWarningThreshold = value; - if (Settings.data.notifications.batteryCriticalThreshold > value) { - Settings.data.notifications.batteryCriticalThreshold = value; - } - } - } - - NSpinBox { - Layout.alignment: Qt.AlignHCenter - from: 0 - to: Settings.data.notifications.batteryWarningThreshold - stepSize: 5 - value: Settings.data.notifications.batteryCriticalThreshold - defaultValue: Settings.getDefaultValue("notifications.batteryCriticalThreshold") - suffix: "%" - onValueChanged: Settings.data.notifications.batteryCriticalThreshold = value - } - } + label: I18n.tr("panels.notifications.toast-battery-label") + description: I18n.tr("panels.notifications.toast-battery-description") + checked: Settings.data.notifications.enableBatteryToast + onToggled: checked => Settings.data.notifications.enableBatteryToast = checked } } diff --git a/Modules/Panels/Settings/Tabs/SystemMonitor/ThresholdsSubTab.qml b/Modules/Panels/Settings/Tabs/SystemMonitor/ThresholdsSubTab.qml index fcd74c0fb..e91db9817 100644 --- a/Modules/Panels/Settings/Tabs/SystemMonitor/ThresholdsSubTab.qml +++ b/Modules/Panels/Settings/Tabs/SystemMonitor/ThresholdsSubTab.qml @@ -276,5 +276,38 @@ ColumnLayout { suffix: "%" onValueChanged: Settings.data.systemMonitor.diskAvailCriticalThreshold = value } + + // Battery + NText { + text: I18n.tr("panels.notifications.toast-battery-label") + pointSize: Style.fontSizeM + } + + NSpinBox { + Layout.alignment: Qt.AlignHCenter + from: 0 + to: 100 + stepSize: 5 + value: Settings.data.systemMonitor.batteryWarningThreshold + defaultValue: Settings.getDefaultValue("systemMonitor.batteryWarningThreshold") + suffix: "%" + onValueChanged: { + Settings.data.systemMonitor.batteryWarningThreshold = value; + if (Settings.data.systemMonitor.batteryCriticalThreshold > value) { + Settings.data.systemMonitor.batteryCriticalThreshold = value; + } + } + } + + NSpinBox { + Layout.alignment: Qt.AlignHCenter + from: 0 + to: Settings.data.systemMonitor.batteryWarningThreshold + stepSize: 5 + value: Settings.data.systemMonitor.batteryCriticalThreshold + defaultValue: Settings.getDefaultValue("systemMonitor.batteryCriticalThreshold") + suffix: "%" + onValueChanged: Settings.data.systemMonitor.batteryCriticalThreshold = value + } } } diff --git a/Services/Hardware/BatteryService.qml b/Services/Hardware/BatteryService.qml index d9c3fbaff..6e730e675 100644 --- a/Services/Hardware/BatteryService.qml +++ b/Services/Hardware/BatteryService.qml @@ -18,8 +18,8 @@ Singleton { readonly property bool batteryPluggedIn: isPluggedIn(primaryDevice) readonly property bool batteryReady: isDeviceReady(primaryDevice) readonly property bool batteryPresent: isDevicePresent(primaryDevice) - readonly property real warningThreshold: Settings.data.notifications.batteryWarningThreshold - readonly property real criticalThreshold: Settings.data.notifications.batteryCriticalThreshold + readonly property real warningThreshold: Settings.data.systemMonitor.batteryWarningThreshold + readonly property real criticalThreshold: Settings.data.systemMonitor.batteryCriticalThreshold readonly property string batteryIcon: getIcon(batteryPercentage, batteryCharging, batteryPluggedIn, batteryReady) readonly property var laptopBatteries: UPower.devices.values.filter(d => d.isLaptopBattery).sort((x, y) => { @@ -312,6 +312,9 @@ Singleton { } function notify(device, level) { + if (!Settings.data.notifications.enableBatteryToast) + return; + var name = getDeviceName(device); var titleKey = level === "critical" ? "toast.battery.critical" : "toast.battery.low"; var descKey = level === "critical" ? "toast.battery.critical-desc" : "toast.battery.low-desc";