Skip to content

Commit

Permalink
Fix code duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquin (Pato) Decima committed Oct 17, 2022
1 parent 41a279e commit d854563
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
3 changes: 3 additions & 0 deletions js/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ app.config.globalProperties.$systeminformation = require('systeminformation');
app.config.globalProperties.$win = nw.Window.get();
app.config.globalProperties.$pid = process.pid;
app.config.globalProperties.$screen = screen;
app.config.globalProperties.$getIcon = (icon) => {
return app.config.globalProperties.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', icon]).stdout.toString();
};

app.mount('#app');
5 changes: 1 addition & 4 deletions js/components/MenuButtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ export default {
},
computed: {
icon() {
return this.$execSynx('python', [
'/usr/share/vasak-desktop-service/Vasak/getIcon.py',
'hydriam',
]).stdout.toString();
return this.$getIcon('hydriam');
},
},
template: `
Expand Down
44 changes: 22 additions & 22 deletions js/components/notificationtools/BatteryIndicator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
data() {
return {
icon: this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-missing-symbolic']).stdout.toString(),
icon: this.$getIcon('battery-missing-symbolic'),
percent: 0
};
},
Expand All @@ -15,49 +15,49 @@ export default {
this.percent = batteryInfo.percent;
if (batteryInfo.isCharging) {
if (batteryInfo.percent === 100) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-full-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-full-charging-symbolic');
} else if (batteryInfo.percent > 90) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-90-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-90-charging-symbolic');
} else if (batteryInfo.percent > 80) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-80-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-80-charging-symbolic');
} else if (batteryInfo.percent > 70) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-70-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-70-charging-symbolic');
} else if (batteryInfo.percent > 60) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-60-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-60-charging-symbolic');
} else if (batteryInfo.percent > 50) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-50-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-50-charging-symbolic');
} else if (batteryInfo.percent > 40) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-40-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-40-charging-symbolic');
} else if (batteryInfo.percent > 30) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-30-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-30-charging-symbolic');
} else if (batteryInfo.percent > 20) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-20-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-20-charging-symbolic');
} else {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-10-charging-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-10-charging-symbolic');
}
} else {
if (batteryInfo.percent === 100) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-full-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-full-symbolic');
} else if (batteryInfo.percent > 90) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-90-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-90-symbolic');
} else if (batteryInfo.percent > 80) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-80-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-80-symbolic');
} else if (batteryInfo.percent > 70) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-70-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-70-symbolic');
} else if (batteryInfo.percent > 60) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-60-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-60-symbolic');
} else if (batteryInfo.percent > 50) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-50-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-50-symbolic');
} else if (batteryInfo.percent > 40) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-40-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-40-symbolic');
} else if (batteryInfo.percent > 30) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-30-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-30-symbolic');
} else if (batteryInfo.percent > 20) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-20-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-20-symbolic');
} else if (batteryInfo.percent > 10) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-level-10-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-level-10-symbolic');
} else {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'battery-empty-symbolic']).stdout.toString();
this.icon = this.$getIcon('battery-empty-symbolic');
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions js/components/notificationtools/NetworkIndicator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
data() {
return {
icon: this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-disconnected-symbolic']).stdout.toString(),
icon: this.$getIcon('network-disconnected-symbolic'),
data: '127.0.0.1'
};
},
Expand All @@ -15,29 +15,29 @@ export default {

if (device.type === 'wired') {
if (device.operstate === 'down') {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-wired-disconnected-symbolic']).stdout.toString();
this.icon = this.$getIcon('network-wired-disconnected-symbolic');
} else {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-wired-symbolic']).stdout.toString();
this.icon = this.$getIcon('network-wired-symbolic');
}
} else {
if (device.operstate === 'down') {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-wireless-disconnected-symbolic']).stdout.toString();
this.icon = this.$getIcon('network-wireless-disconnected-symbolic');
} else {
const wifi = await this.$systeminformation.wifiConnections();
const myWifi = wifi.find(conn => conn.iface === device.iface);
this.data = `${myWifi.ssid}\n${device.ip4}`;

//elem.innerHTML = myWifi.signalLevel;
if (myWifi.signalLevel >= -30) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-wireless-signal-excellent-symbolic']).stdout.toString();
this.icon = this.$getIcon('network-wireless-signal-excellent-symbolic');
} else if (myWifi.signalLevel >= -67) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-wireless-signal-good-symbolic']).stdout.toString();
this.icon = this.$getIcon('network-wireless-signal-good-symbolic');
} else if (myWifi.signalLevel >= -70) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-wireless-signal-ok-symbolic']).stdout.toString();
this.icon = this.$getIcon('network-wireless-signal-ok-symbolic');
} else if (myWifi.signalLevel >= -80) {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-wireless-signal-weak-symbolic']).stdout.toString();
this.icon = this.$getIcon('network-wireless-signal-weak-symbolic');
} else {
this.icon = this.$execSynx('python', ['/usr/share/vasak-desktop-service/Vasak/getIcon.py', 'network-wireless-signal-none-symbolic']).stdout.toString();
this.icon = this.$getIcon('network-wireless-signal-none-symbolic');
}
}
}
Expand Down

0 comments on commit d854563

Please sign in to comment.