Don't show power panel if there's no battery
This commit is contained in:
@@ -15,6 +15,10 @@ Panel {
|
|||||||
property string activeProfile: ""
|
property string activeProfile: ""
|
||||||
property int profileIndex: 0
|
property int profileIndex: 0
|
||||||
property bool cursorActive: false
|
property bool cursorActive: false
|
||||||
|
readonly property bool batteryPresent: {
|
||||||
|
var device = UPower.displayDevice
|
||||||
|
return !!(device && device.isPresent)
|
||||||
|
}
|
||||||
|
|
||||||
function selectProfileByDelta(delta) {
|
function selectProfileByDelta(delta) {
|
||||||
if (profiles.length === 0) { profileIndex = 0; return }
|
if (profiles.length === 0) { profileIndex = 0; return }
|
||||||
@@ -28,7 +32,7 @@ Panel {
|
|||||||
|
|
||||||
function batteryIcon() {
|
function batteryIcon() {
|
||||||
var device = UPower.displayDevice
|
var device = UPower.displayDevice
|
||||||
if (!device || !device.isPresent) return ""
|
if (!root.batteryPresent) return ""
|
||||||
|
|
||||||
var chargingIcons = ["", "", "", "", "", "", "", "", "", ""]
|
var chargingIcons = ["", "", "", "", "", "", "", "", "", ""]
|
||||||
var defaultIcons = ["", "", "", "", "", "", "", "", "", ""]
|
var defaultIcons = ["", "", "", "", "", "", "", "", "", ""]
|
||||||
@@ -43,6 +47,8 @@ Panel {
|
|||||||
|
|
||||||
function modeLabel() {
|
function modeLabel() {
|
||||||
var device = UPower.displayDevice
|
var device = UPower.displayDevice
|
||||||
|
if (!root.batteryPresent) return ""
|
||||||
|
|
||||||
var percentage = device && device.isPresent ? device.percentage : 0
|
var percentage = device && device.isPresent ? device.percentage : 0
|
||||||
|
|
||||||
if (chargeThresholdActive) {
|
if (chargeThresholdActive) {
|
||||||
@@ -140,6 +146,8 @@ Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
|
if (!batteryPresent) return
|
||||||
|
|
||||||
if (!batteryProc.running) batteryProc.running = true
|
if (!batteryProc.running) batteryProc.running = true
|
||||||
if (!profilesProc.running) profilesProc.running = true
|
if (!profilesProc.running) profilesProc.running = true
|
||||||
if (!systemProc.running) systemProc.running = true
|
if (!systemProc.running) systemProc.running = true
|
||||||
@@ -191,6 +199,11 @@ Panel {
|
|||||||
|
|
||||||
onOpenedChanged: {
|
onOpenedChanged: {
|
||||||
if (opened) {
|
if (opened) {
|
||||||
|
if (!batteryPresent) {
|
||||||
|
close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
refresh()
|
refresh()
|
||||||
var idx = profiles.indexOf(activeProfile)
|
var idx = profiles.indexOf(activeProfile)
|
||||||
profileIndex = idx >= 0 ? idx : 0
|
profileIndex = idx >= 0 ? idx : 0
|
||||||
@@ -198,8 +211,11 @@ Panel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicitWidth: button.implicitWidth
|
onBatteryPresentChanged: if (!batteryPresent) close()
|
||||||
implicitHeight: button.implicitHeight
|
|
||||||
|
visible: batteryPresent
|
||||||
|
implicitWidth: batteryPresent ? button.implicitWidth : 0
|
||||||
|
implicitHeight: batteryPresent ? button.implicitHeight : 0
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: batteryProc
|
id: batteryProc
|
||||||
@@ -276,9 +292,9 @@ Panel {
|
|||||||
text: root.batteryIcon()
|
text: root.batteryIcon()
|
||||||
horizontalMargin: 8.5
|
horizontalMargin: 8.5
|
||||||
rightExtraMargin: 2
|
rightExtraMargin: 2
|
||||||
active: UPower.displayDevice && UPower.displayDevice.percentage <= 0.2 && UPower.onBattery
|
active: root.batteryPresent && UPower.displayDevice.percentage <= 0.2 && UPower.onBattery
|
||||||
tooltipText: ""
|
tooltipText: ""
|
||||||
onPressed: function(b) { root.toggle() }
|
onPressed: function(b) { if (root.batteryPresent) root.toggle() }
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardPanel {
|
KeyboardPanel {
|
||||||
@@ -286,7 +302,7 @@ Panel {
|
|||||||
anchorItem: button
|
anchorItem: button
|
||||||
owner: root
|
owner: root
|
||||||
bar: root.bar
|
bar: root.bar
|
||||||
open: root.opened
|
open: root.opened && root.batteryPresent
|
||||||
focusTarget: keyCatcher
|
focusTarget: keyCatcher
|
||||||
contentWidth: panel.fittedContentWidth(Style.space(380))
|
contentWidth: panel.fittedContentWidth(Style.space(380))
|
||||||
contentHeight: panel.fittedContentHeight(column.implicitHeight)
|
contentHeight: panel.fittedContentHeight(column.implicitHeight)
|
||||||
|
|||||||
Reference in New Issue
Block a user