Skip to content

Commit 82021fd

Browse files
authored
Fix sponsor loading (#4250)
1 parent b84559a commit 82021fd

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

src/js/Sponsor.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import BuildApi from './BuildApi';
22
import DarkTheme from './DarkTheme';
3+
import GUI from './gui';
34
import { ispConnected } from './utils/connection';
45

56
export default class Sponsor {
67

78
constructor () {
89
this._api = new BuildApi();
9-
this._timer = ispConnected() ? setInterval(() => { this.Refresh(); }, 30000) : null;
1010
}
1111

1212
Refresh() {
@@ -18,24 +18,23 @@ export default class Sponsor {
1818
return;
1919
}
2020

21-
this._api.loadSponsorTile(DarkTheme.enabled ? 'dark' : 'light', this._name,
22-
(content) => {
23-
if (content) {
24-
this._div.fadeOut(500, () => {
25-
this._div.html(content);
26-
this._div.fadeIn(500);
27-
});
28-
this._div.show();
29-
} else {
30-
this._div.hide();
31-
}
32-
},
33-
);
21+
this._api.loadSponsorTile(DarkTheme.enabled ? 'dark' : 'light', this._name, (content) => {
22+
if (content) {
23+
this._div.fadeOut(500, () => {
24+
this._div.html(content);
25+
this._div.fadeIn(500);
26+
});
27+
this._div.show();
28+
} else {
29+
this._div.hide();
30+
}
31+
});
3432
}
3533

3634
loadSponsorTile(name, div) {
3735
this._name = name;
3836
this._div = div;
39-
this.Refresh();
37+
38+
GUI.interval_add("sponsor", () => { this.Refresh(); }, 15000, true);
4039
}
4140
}

src/js/gui.js

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class GuiControl {
7878
interval_add(name, code, interval, first) {
7979
const data = { 'name': name, 'timer': null, 'code': code, 'interval': interval, 'fired': 0, 'paused': false };
8080

81+
if (this.interval_array.find((element) => element.name === name)) {
82+
this.interval_remove(name);
83+
}
84+
8185
if (first === true) {
8286
code(); // execute code
8387

src/js/main.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,20 @@ function startProcess() {
132132
}
133133
});
134134

135+
$('div.open_firmware_flasher a.flash').on('click', function () {
136+
if ($('div#flashbutton a.flash_state').hasClass('active') && $('div#flashbutton a.flash').hasClass('active')) {
137+
$('div#flashbutton a.flash_state').removeClass('active');
138+
$('div#flashbutton a.flash').removeClass('active');
139+
$('#tabs ul.mode-disconnected .tab_landing a').click();
140+
} else {
141+
$('#tabs ul.mode-disconnected .tab_firmware_flasher a').click();
142+
$('div#flashbutton a.flash_state').addClass('active');
143+
$('div#flashbutton a.flash').addClass('active');
144+
}
145+
});
146+
135147
const ui_tabs = $('#tabs > ul');
136-
$('a', ui_tabs).click(function () {
148+
$('a', '#tabs > ul').click(function () {
137149
if ($(this).parent().hasClass('active') === false && !GUI.tab_switch_in_progress) { // only initialize when the tab isn't already active
138150
const self = this;
139151
const tabClass = $(self).parent().prop('class');
@@ -157,6 +169,7 @@ function startProcess() {
157169
if (GUI.connected_to || GUI.connecting_to) {
158170
$('a.connect').click();
159171
}
172+
// this line is required but it triggers opening the firmware flasher tab again
160173
$('div.open_firmware_flasher a.flash').click();
161174
} else if (GUI.allowedTabs.indexOf(tab) < 0) {
162175
gui_log(i18n.getMessage('tabSwitchUpgradeRequired', [tabName]));

src/js/serial_backend.js

-16
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ export function initializeSerialBackend() {
8181
}
8282
});
8383

84-
$('div.open_firmware_flasher a.flash').click(function () {
85-
if ($('div#flashbutton a.flash_state').hasClass('active') && $('div#flashbutton a.flash').hasClass('active')) {
86-
$('div#flashbutton a.flash_state').removeClass('active');
87-
$('div#flashbutton a.flash').removeClass('active');
88-
$('#tabs ul.mode-disconnected .tab_landing a').click();
89-
} else {
90-
$('#tabs ul.mode-disconnected .tab_firmware_flasher a').click();
91-
$('div#flashbutton a.flash_state').addClass('active');
92-
$('div#flashbutton a.flash').addClass('active');
93-
}
94-
});
95-
9684
PortHandler.initialize();
9785
PortUsage.initialize();
9886
}
@@ -155,10 +143,6 @@ function connectDisconnect() {
155143
}
156144

157145
} else {
158-
if ($('div#flashbutton a.flash_state').hasClass('active') && $('div#flashbutton a.flash').hasClass('active')) {
159-
$('div#flashbutton a.flash_state').removeClass('active');
160-
$('div#flashbutton a.flash').removeClass('active');
161-
}
162146
GUI.timeout_kill_all();
163147
GUI.interval_kill_all();
164148
GUI.tab_switch_cleanup(() => GUI.tab_switch_in_progress = false);

src/js/tabs/firmware_flasher.js

+3
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ firmware_flasher.initialize = function (callback) {
623623
}
624624

625625
self.isFlashing = false;
626+
GUI.interval_resume('sponsor');
626627
}
627628

628629
let result = getConfig('erase_chip');
@@ -987,6 +988,7 @@ firmware_flasher.initialize = function (callback) {
987988

988989
$('a.flash_firmware').on('click', function () {
989990
self.isFlashing = true;
991+
GUI.interval_pause("sponsor");
990992
const isFlashOnConnect = $('input.flash_on_connect').is(':checked');
991993

992994
self.enableFlashButton(false);
@@ -1135,6 +1137,7 @@ firmware_flasher.initialize = function (callback) {
11351137
}
11361138

11371139
self.buildApi.loadTargets(() => {
1140+
console.log('Targets loaded');
11381141
$('#content').load("./tabs/firmware_flasher.html", onDocumentLoad);
11391142
});
11401143
};

0 commit comments

Comments
 (0)