diff --git a/src/js/Sponsor.js b/src/js/Sponsor.js index 8f8cc0a34e..6abc2698bd 100644 --- a/src/js/Sponsor.js +++ b/src/js/Sponsor.js @@ -1,12 +1,12 @@ import BuildApi from './BuildApi'; import DarkTheme from './DarkTheme'; +import GUI from './gui'; import { ispConnected } from './utils/connection'; export default class Sponsor { constructor () { this._api = new BuildApi(); - this._timer = ispConnected() ? setInterval(() => { this.Refresh(); }, 30000) : null; } Refresh() { @@ -18,24 +18,23 @@ export default class Sponsor { return; } - this._api.loadSponsorTile(DarkTheme.enabled ? 'dark' : 'light', this._name, - (content) => { - if (content) { - this._div.fadeOut(500, () => { - this._div.html(content); - this._div.fadeIn(500); - }); - this._div.show(); - } else { - this._div.hide(); - } - }, - ); + this._api.loadSponsorTile(DarkTheme.enabled ? 'dark' : 'light', this._name, (content) => { + if (content) { + this._div.fadeOut(500, () => { + this._div.html(content); + this._div.fadeIn(500); + }); + this._div.show(); + } else { + this._div.hide(); + } + }); } loadSponsorTile(name, div) { this._name = name; this._div = div; - this.Refresh(); + + GUI.interval_add("sponsor", () => { this.Refresh(); }, 15000, true); } } diff --git a/src/js/gui.js b/src/js/gui.js index 9ebbfefcda..9ea7253638 100644 --- a/src/js/gui.js +++ b/src/js/gui.js @@ -78,6 +78,10 @@ class GuiControl { interval_add(name, code, interval, first) { const data = { 'name': name, 'timer': null, 'code': code, 'interval': interval, 'fired': 0, 'paused': false }; + if (this.interval_array.find((element) => element.name === name)) { + this.interval_remove(name); + } + if (first === true) { code(); // execute code diff --git a/src/js/main.js b/src/js/main.js index 375191e78a..efaa3f9fd9 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -132,8 +132,20 @@ function startProcess() { } }); + $('div.open_firmware_flasher a.flash').on('click', function () { + if ($('div#flashbutton a.flash_state').hasClass('active') && $('div#flashbutton a.flash').hasClass('active')) { + $('div#flashbutton a.flash_state').removeClass('active'); + $('div#flashbutton a.flash').removeClass('active'); + $('#tabs ul.mode-disconnected .tab_landing a').click(); + } else { + $('#tabs ul.mode-disconnected .tab_firmware_flasher a').click(); + $('div#flashbutton a.flash_state').addClass('active'); + $('div#flashbutton a.flash').addClass('active'); + } + }); + const ui_tabs = $('#tabs > ul'); - $('a', ui_tabs).click(function () { + $('a', '#tabs > ul').click(function () { if ($(this).parent().hasClass('active') === false && !GUI.tab_switch_in_progress) { // only initialize when the tab isn't already active const self = this; const tabClass = $(self).parent().prop('class'); @@ -157,6 +169,7 @@ function startProcess() { if (GUI.connected_to || GUI.connecting_to) { $('a.connect').click(); } + // this line is required but it triggers opening the firmware flasher tab again $('div.open_firmware_flasher a.flash').click(); } else if (GUI.allowedTabs.indexOf(tab) < 0) { gui_log(i18n.getMessage('tabSwitchUpgradeRequired', [tabName])); diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 6f2e4bf537..5db7ba518e 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -81,18 +81,6 @@ export function initializeSerialBackend() { } }); - $('div.open_firmware_flasher a.flash').click(function () { - if ($('div#flashbutton a.flash_state').hasClass('active') && $('div#flashbutton a.flash').hasClass('active')) { - $('div#flashbutton a.flash_state').removeClass('active'); - $('div#flashbutton a.flash').removeClass('active'); - $('#tabs ul.mode-disconnected .tab_landing a').click(); - } else { - $('#tabs ul.mode-disconnected .tab_firmware_flasher a').click(); - $('div#flashbutton a.flash_state').addClass('active'); - $('div#flashbutton a.flash').addClass('active'); - } - }); - PortHandler.initialize(); PortUsage.initialize(); } @@ -155,10 +143,6 @@ function connectDisconnect() { } } else { - if ($('div#flashbutton a.flash_state').hasClass('active') && $('div#flashbutton a.flash').hasClass('active')) { - $('div#flashbutton a.flash_state').removeClass('active'); - $('div#flashbutton a.flash').removeClass('active'); - } GUI.timeout_kill_all(); GUI.interval_kill_all(); GUI.tab_switch_cleanup(() => GUI.tab_switch_in_progress = false); diff --git a/src/js/tabs/firmware_flasher.js b/src/js/tabs/firmware_flasher.js index 5410fd62bd..85a21e791c 100644 --- a/src/js/tabs/firmware_flasher.js +++ b/src/js/tabs/firmware_flasher.js @@ -623,6 +623,7 @@ firmware_flasher.initialize = function (callback) { } self.isFlashing = false; + GUI.interval_resume('sponsor'); } let result = getConfig('erase_chip'); @@ -987,6 +988,7 @@ firmware_flasher.initialize = function (callback) { $('a.flash_firmware').on('click', function () { self.isFlashing = true; + GUI.interval_pause("sponsor"); const isFlashOnConnect = $('input.flash_on_connect').is(':checked'); self.enableFlashButton(false); @@ -1135,6 +1137,7 @@ firmware_flasher.initialize = function (callback) { } self.buildApi.loadTargets(() => { + console.log('Targets loaded'); $('#content').load("./tabs/firmware_flasher.html", onDocumentLoad); }); };