mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Add new icon and make use of it
- Adds battery-charging-2 icon - Shows new icon if plugged in while battery is not charging.
This commit is contained in:
@@ -79,6 +79,7 @@ Singleton {
|
|||||||
"star-off": "star-off",
|
"star-off": "star-off",
|
||||||
"battery-exclamation": "battery-exclamation",
|
"battery-exclamation": "battery-exclamation",
|
||||||
"common.charging": "common.charging",
|
"common.charging": "common.charging",
|
||||||
|
"battery-charging-2": "battery-charging-2",
|
||||||
"battery-4": "battery-4",
|
"battery-4": "battery-4",
|
||||||
"battery-3": "battery-3",
|
"battery-3": "battery-3",
|
||||||
"battery-2": "battery-2",
|
"battery-2": "battery-2",
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Item {
|
|||||||
readonly property bool hideIfNotDetected: widgetSettings.hideIfNotDetected !== undefined ? widgetSettings.hideIfNotDetected : widgetMetadata.hideIfNotDetected
|
readonly property bool hideIfNotDetected: widgetSettings.hideIfNotDetected !== undefined ? widgetSettings.hideIfNotDetected : widgetMetadata.hideIfNotDetected
|
||||||
readonly property bool hideIfIdle: widgetSettings.hideIfIdle !== undefined ? widgetSettings.hideIfIdle : widgetMetadata.hideIfIdle
|
readonly property bool hideIfIdle: widgetSettings.hideIfIdle !== undefined ? widgetSettings.hideIfIdle : widgetMetadata.hideIfIdle
|
||||||
// Only show low battery warning if device is ready (prevents false positive during initialization)
|
// Only show low battery warning if device is ready (prevents false positive during initialization)
|
||||||
readonly property bool isLowBattery: isReady && !charging && percent <= warningThreshold
|
readonly property bool isLowBattery: isReady && (!charging && !isPluggedIn) && percent <= warningThreshold
|
||||||
|
|
||||||
// Visibility: show if hideIfNotDetected is false, or if battery is ready (after initialization)
|
// Visibility: show if hideIfNotDetected is false, or if battery is ready (after initialization)
|
||||||
readonly property bool shouldShow: !hideIfNotDetected || (isReady && (hideIfIdle ? (charging || battery.state === UPowerDeviceState.Discharging) : true))
|
readonly property bool shouldShow: !hideIfNotDetected || (isReady && (hideIfIdle ? (charging || battery.state === UPowerDeviceState.Discharging) : true))
|
||||||
@@ -50,6 +50,7 @@ Item {
|
|||||||
readonly property bool testMode: false
|
readonly property bool testMode: false
|
||||||
readonly property int testPercent: 35
|
readonly property int testPercent: 35
|
||||||
readonly property bool testCharging: false
|
readonly property bool testCharging: false
|
||||||
|
readonly property bool testPluggedIn: false
|
||||||
|
|
||||||
readonly property string deviceNativePath: widgetSettings.deviceNativePath || ""
|
readonly property string deviceNativePath: widgetSettings.deviceNativePath || ""
|
||||||
|
|
||||||
@@ -127,6 +128,7 @@ Item {
|
|||||||
readonly property bool isReady: testMode ? true : (initializationComplete && battery && battery.ready && isDevicePresent && (battery.percentage !== undefined || hasBluetoothBattery))
|
readonly property bool isReady: testMode ? true : (initializationComplete && battery && battery.ready && isDevicePresent && (battery.percentage !== undefined || hasBluetoothBattery))
|
||||||
readonly property real percent: testMode ? testPercent : (isReady ? (hasBluetoothBattery ? (bluetoothDevice.battery * 100) : (battery.percentage * 100)) : 0)
|
readonly property real percent: testMode ? testPercent : (isReady ? (hasBluetoothBattery ? (bluetoothDevice.battery * 100) : (battery.percentage * 100)) : 0)
|
||||||
readonly property bool charging: testMode ? testCharging : (isReady ? chargingStatus(battery.state) : false) // Assuming not charging if battery is not ready
|
readonly property bool charging: testMode ? testCharging : (isReady ? chargingStatus(battery.state) : false) // Assuming not charging if battery is not ready
|
||||||
|
readonly property bool isPluggedIn: testMode ? testPluggedIn : (isReady ? getPluggedInStatus(battery.state) : false) // We can be plugged in or charging but can't both.
|
||||||
property bool hasNotifiedLowBattery: false
|
property bool hasNotifiedLowBattery: false
|
||||||
|
|
||||||
implicitWidth: pill.width
|
implicitWidth: pill.width
|
||||||
@@ -135,8 +137,6 @@ Item {
|
|||||||
function chargingStatus(state) {
|
function chargingStatus(state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case UPowerDeviceState.Charging: // 1
|
case UPowerDeviceState.Charging: // 1
|
||||||
case UPowerDeviceState.FullyCharged: // 4
|
|
||||||
case UPowerDeviceState.PendingCharge: // 5
|
|
||||||
return true;
|
return true;
|
||||||
case UPowerDeviceState.Discharging: // 2
|
case UPowerDeviceState.Discharging: // 2
|
||||||
case UPowerDeviceState.Empty: // 3
|
case UPowerDeviceState.Empty: // 3
|
||||||
@@ -146,15 +146,23 @@ Item {
|
|||||||
return true; // unknown state 0 Fix #1417
|
return true; // unknown state 0 Fix #1417
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function getPluggedInStatus(state) {
|
||||||
function maybeNotify(currentPercent, isCharging) {
|
switch (state) {
|
||||||
if (!isCharging && !hasNotifiedLowBattery && currentPercent <= warningThreshold) {
|
case UPowerDeviceState.FullyCharged: // 4
|
||||||
|
case UPowerDeviceState.PendingCharge: // 5
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function maybeNotify(currentPercent, isCharging, isPluggedIn) {
|
||||||
|
if ((!isCharging && !isPluggedIn) && !hasNotifiedLowBattery && currentPercent <= warningThreshold) {
|
||||||
hasNotifiedLowBattery = true;
|
hasNotifiedLowBattery = true;
|
||||||
ToastService.showWarning(I18n.tr("toast.battery.low"), I18n.tr("toast.battery.low-desc", {
|
ToastService.showWarning(I18n.tr("toast.battery.low"), I18n.tr("toast.battery.low-desc", {
|
||||||
"percent": Math.round(currentPercent)
|
"percent": Math.round(currentPercent)
|
||||||
}));
|
}));
|
||||||
// Logger.e("Battery", "Low battery at " + currentPercent + "%", "isCharging: " + isCharging); // debug
|
// Logger.e("Battery", "Low battery at " + currentPercent + "%", "isCharging: " + isCharging, "isPluggedIn: " + isPluggedIn); // debug
|
||||||
} else if (hasNotifiedLowBattery && (isCharging || currentPercent > warningThreshold + 5)) {
|
} else if (hasNotifiedLowBattery && (isCharging || isPluggedIn || currentPercent > warningThreshold + 5)) {
|
||||||
hasNotifiedLowBattery = false;
|
hasNotifiedLowBattery = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,15 +175,15 @@ Item {
|
|||||||
target: battery
|
target: battery
|
||||||
function onPercentageChanged() {
|
function onPercentageChanged() {
|
||||||
if (battery) {
|
if (battery) {
|
||||||
maybeNotify(getCurrentPercent(), chargingStatus(battery.state));
|
maybeNotify(getCurrentPercent(), chargingStatus(battery.state), getPluggedInStatus(battery.state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function onStateChanged() {
|
function onStateChanged() {
|
||||||
if (battery) {
|
if (battery) {
|
||||||
if (chargingStatus(battery.state)) {
|
if (chargingStatus(battery.state) || getPluggedInStatus(battery.state)) {
|
||||||
hasNotifiedLowBattery = false;
|
hasNotifiedLowBattery = false;
|
||||||
}
|
}
|
||||||
maybeNotify(getCurrentPercent(), chargingStatus(battery.state));
|
maybeNotify(getCurrentPercent(), chargingStatus(battery.state), getPluggedInStatus(battery.state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,7 +192,7 @@ Item {
|
|||||||
target: bluetoothDevice
|
target: bluetoothDevice
|
||||||
function onBatteryChanged() {
|
function onBatteryChanged() {
|
||||||
if (bluetoothDevice && hasBluetoothBattery) {
|
if (bluetoothDevice && hasBluetoothBattery) {
|
||||||
maybeNotify(bluetoothDevice.battery * 100, battery ? chargingStatus(battery.state) : false);
|
maybeNotify(bluetoothDevice.battery * 100, battery ? chargingStatus(battery.state) : false, battery ? getPluggedInStatus(battery.state) : false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,7 +225,7 @@ Item {
|
|||||||
|
|
||||||
screen: root.screen
|
screen: root.screen
|
||||||
oppositeDirection: BarService.getPillDirection(root)
|
oppositeDirection: BarService.getPillDirection(root)
|
||||||
icon: testMode ? BatteryService.getIcon(testPercent, testCharging, true) : BatteryService.getIcon(percent, charging, isReady)
|
icon: testMode ? BatteryService.getIcon(testPercent, testCharging, testPluggedIn, true) : BatteryService.getIcon(percent, charging, isPluggedIn, isReady)
|
||||||
text: (isReady || testMode) ? Math.round(percent) : "-"
|
text: (isReady || testMode) ? Math.round(percent) : "-"
|
||||||
suffix: "%"
|
suffix: "%"
|
||||||
autoHide: false
|
autoHide: false
|
||||||
@@ -259,7 +267,7 @@ Item {
|
|||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
// Rate is 0 - check if plugged in (charging state) or idle
|
// Rate is 0 - check if plugged in (charging state) or idle
|
||||||
lines.push(charging ? I18n.tr("battery.plugged-in") : I18n.tr("common.idle"));
|
lines.push(isPluggedIn ? I18n.tr("battery.plugged-in") : I18n.tr("common.idle"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lines.push(charging ? I18n.tr("common.charging") : I18n.tr("common.discharging"));
|
lines.push(charging ? I18n.tr("common.charging") : I18n.tr("common.discharging"));
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ SmartPanel {
|
|||||||
readonly property bool isReady: battery && battery.ready && isDevicePresent && (battery.percentage !== undefined || hasBluetoothBattery)
|
readonly property bool isReady: battery && battery.ready && isDevicePresent && (battery.percentage !== undefined || hasBluetoothBattery)
|
||||||
readonly property int percent: isReady ? Math.round(hasBluetoothBattery ? (bluetoothDevice.battery * 100) : (battery.percentage * 100)) : -1
|
readonly property int percent: isReady ? Math.round(hasBluetoothBattery ? (bluetoothDevice.battery * 100) : (battery.percentage * 100)) : -1
|
||||||
readonly property bool charging: isReady ? battery.state === UPowerDeviceState.Charging : false
|
readonly property bool charging: isReady ? battery.state === UPowerDeviceState.Charging : false
|
||||||
|
readonly property bool isPluggedIn: isReady ? (battery.state === UPowerDeviceState.FullyCharged || battery.state === UPowerDeviceState.PendingCharge) : false
|
||||||
readonly property bool healthAvailable: isReady && battery.healthSupported
|
readonly property bool healthAvailable: isReady && battery.healthSupported
|
||||||
readonly property int healthPercent: healthAvailable ? Math.round(battery.healthPercentage) : -1
|
readonly property int healthPercent: healthAvailable ? Math.round(battery.healthPercentage) : -1
|
||||||
|
|
||||||
@@ -146,9 +147,12 @@ SmartPanel {
|
|||||||
"time": Time.formatVagueHumanReadableDuration(battery.timeToEmpty)
|
"time": Time.formatVagueHumanReadableDuration(battery.timeToEmpty)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!charging && isPluggedIn) {
|
||||||
|
return I18n.tr("battery.plugged-in"); // i18n: Could be Plugged in, not charging? Ask maintainers if i not forgot
|
||||||
|
}
|
||||||
return I18n.tr("common.idle");
|
return I18n.tr("common.idle");
|
||||||
}
|
}
|
||||||
readonly property string iconName: BatteryService.getIcon(percent, charging, isReady)
|
readonly property string iconName: BatteryService.getIcon(percent, charging, isPluggedIn, isReady)
|
||||||
|
|
||||||
property var batteryWidgetInstance: BarService.lookupWidget("Battery", screen ? screen.name : null)
|
property var batteryWidgetInstance: BarService.lookupWidget("Battery", screen ? screen.name : null)
|
||||||
readonly property var batteryWidgetSettings: batteryWidgetInstance ? batteryWidgetInstance.widgetSettings : null
|
readonly property var batteryWidgetSettings: batteryWidgetInstance ? batteryWidgetInstance.widgetSettings : null
|
||||||
@@ -215,7 +219,7 @@ SmartPanel {
|
|||||||
|
|
||||||
NIcon {
|
NIcon {
|
||||||
pointSize: Style.fontSizeXXL
|
pointSize: Style.fontSizeXXL
|
||||||
color: charging ? Color.mPrimary : Color.mOnSurface
|
color: (charging || isPluggedIn) ? Color.mPrimary : Color.mOnSurface
|
||||||
icon: iconName
|
icon: iconName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,13 +80,16 @@ Singleton {
|
|||||||
return primaryDevice.connected === true;
|
return primaryDevice.connected === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIcon(percent, charging, isReady) {
|
function getIcon(percent, charging, pluggedIn, isReady) {
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
return "battery-exclamation";
|
return "battery-exclamation";
|
||||||
}
|
}
|
||||||
if (charging) {
|
if (charging) {
|
||||||
return "common.charging";
|
return "common.charging";
|
||||||
}
|
}
|
||||||
|
if (pluggedIn) {
|
||||||
|
return "battery-charging-2";
|
||||||
|
}
|
||||||
if (percent >= 90) {
|
if (percent >= 90) {
|
||||||
return "battery-4";
|
return "battery-4";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user