Skip to content

Commit

Permalink
Fix network widget elements duplicated (#21)
Browse files Browse the repository at this point in the history
* Fix network widget elements duplicated

This is due to the fact redis messages are received after reboot
while the widget is already created and did not rendered from scratch
To avoid such behaviour we add 2 boolean variable to check if the
mobile throttling ans 5G enabling/disabling operation was already done
or not.
  • Loading branch information
cmajed authored Jan 31, 2023
1 parent aace20a commit e661e63
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/plugins/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ module.exports = class Network extends OverlayPlugin {
this.renderToolbarButton();
this.renderWidget();

/*
* Redis message for enabling/disabling mobile throttling and 5G support
* could be sent without rendering the widget from scratch
* to avoid recreation of widget elements, check these parameters before.
*/
this.mobileThrottlingConfigured = false;
this.network5GConfigured = false;

this.wifiInputChecked = true;
this.mobileInputChecked = true;

Expand All @@ -60,6 +68,10 @@ module.exports = class Network extends OverlayPlugin {
}

enableMobileThrottling() {
if (this.mobileThrottlingConfigured) {
return;
}

this.mobilethrottling = true;
// Add wifi checkbox
const wifiGroup = document.createElement('div');
Expand Down Expand Up @@ -133,9 +145,15 @@ module.exports = class Network extends OverlayPlugin {
});

this.updateMobileSectionStatus();

this.mobileThrottlingConfigured = true;
}

disableMobileThrottling() {
if (this.mobileThrottlingConfigured) {
return;
}

this.mobilethrottling = false;

// Generate input rows for network profiles
Expand All @@ -151,16 +169,28 @@ module.exports = class Network extends OverlayPlugin {
this.selectProfile.add(option);
});
this.profileInputs.appendChild(this.selectProfile);

this.mobileThrottlingConfigured = true;
}

enable5G() {
if (this.network5GConfigured) {
return;
}

const profile = MOBILE_PROFILES.at(0);
const option = new Option(profile.label, profile.name);
this.selectMobileProfile.add(option);

this.network5GConfigured = true;
}

disable5G() {
// Nothing to do!
if (this.network5GConfigured) {
return;
}

this.network5GConfigured = true;
}

// Handle settings event to enable/disable wifi|mobile data
Expand Down

0 comments on commit e661e63

Please sign in to comment.