Skip to content

Commit

Permalink
Remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquin (Pato) Decima committed Oct 17, 2022
1 parent d854563 commit ad71bca
Showing 1 changed file with 29 additions and 45 deletions.
74 changes: 29 additions & 45 deletions js/components/notificationtools/BatteryIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit ad71bca

Please sign in to comment.