diff --git a/js/components/notificationtools/BatteryIndicator.js b/js/components/notificationtools/BatteryIndicator.js index 9632bde..5b3f960 100644 --- a/js/components/notificationtools/BatteryIndicator.js +++ b/js/components/notificationtools/BatteryIndicator.js @@ -9,56 +9,40 @@ export default { setInterval(() => this.checkBattery(), 1000); }, methods: { + setIcon(icon, isCharging) { + if (isCharging) { + this.icon = this.$getIcon(`${icon}-charging-symbolic`); + }else{ + this.icon = this.$getIcon(`${icon}-symbolic`); + } + }, async checkBattery() { const batteryInfo = await this.$systeminformation.battery(); if (batteryInfo.hasBattery) { this.percent = batteryInfo.percent; - if (batteryInfo.isCharging) { - if (batteryInfo.percent === 100) { - this.icon = this.$getIcon('battery-full-charging-symbolic'); - } else if (batteryInfo.percent > 90) { - this.icon = this.$getIcon('battery-level-90-charging-symbolic'); - } else if (batteryInfo.percent > 80) { - this.icon = this.$getIcon('battery-level-80-charging-symbolic'); - } else if (batteryInfo.percent > 70) { - this.icon = this.$getIcon('battery-level-70-charging-symbolic'); - } else if (batteryInfo.percent > 60) { - this.icon = this.$getIcon('battery-level-60-charging-symbolic'); - } else if (batteryInfo.percent > 50) { - this.icon = this.$getIcon('battery-level-50-charging-symbolic'); - } else if (batteryInfo.percent > 40) { - this.icon = this.$getIcon('battery-level-40-charging-symbolic'); - } else if (batteryInfo.percent > 30) { - this.icon = this.$getIcon('battery-level-30-charging-symbolic'); - } else if (batteryInfo.percent > 20) { - this.icon = this.$getIcon('battery-level-20-charging-symbolic'); - } else { - this.icon = this.$getIcon('battery-level-10-charging-symbolic'); - } + + if (batteryInfo.percent === 100) { + this.setIcon('battery-full', batteryInfo.isCharging); + } else if (batteryInfo.percent > 90) { + this.setIcon('battery-level-90', batteryInfo.isCharging); + } else if (batteryInfo.percent > 80) { + this.setIcon('battery-level-80', batteryInfo.isCharging); + } else if (batteryInfo.percent > 70) { + this.setIcon('battery-level-70', batteryInfo.isCharging); + } else if (batteryInfo.percent > 60) { + this.setIcon('battery-level-60', batteryInfo.isCharging); + } else if (batteryInfo.percent > 50) { + this.setIcon('battery-level-50', batteryInfo.isCharging); + } else if (batteryInfo.percent > 40) { + this.setIcon('battery-level-40', batteryInfo.isCharging); + } else if (batteryInfo.percent > 30) { + this.setIcon('battery-level-30', batteryInfo.isCharging); + } else if (batteryInfo.percent > 20) { + this.setIcon('battery-level-20', batteryInfo.isCharging); + } else if (batteryInfo.percent > 10) { + this.setIcon('battery-level-10', batteryInfo.isCharging); } else { - if (batteryInfo.percent === 100) { - this.icon = this.$getIcon('battery-full-symbolic'); - } else if (batteryInfo.percent > 90) { - this.icon = this.$getIcon('battery-level-90-symbolic'); - } else if (batteryInfo.percent > 80) { - this.icon = this.$getIcon('battery-level-80-symbolic'); - } else if (batteryInfo.percent > 70) { - this.icon = this.$getIcon('battery-level-70-symbolic'); - } else if (batteryInfo.percent > 60) { - this.icon = this.$getIcon('battery-level-60-symbolic'); - } else if (batteryInfo.percent > 50) { - this.icon = this.$getIcon('battery-level-50-symbolic'); - } else if (batteryInfo.percent > 40) { - this.icon = this.$getIcon('battery-level-40-symbolic'); - } else if (batteryInfo.percent > 30) { - this.icon = this.$getIcon('battery-level-30-symbolic'); - } else if (batteryInfo.percent > 20) { - this.icon = this.$getIcon('battery-level-20-symbolic'); - } else if (batteryInfo.percent > 10) { - this.icon = this.$getIcon('battery-level-10-symbolic'); - } else { - this.icon = this.$getIcon('battery-empty-symbolic'); - } + this.setIcon('battery-empty', batteryInfo.isCharging); } }