Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sponsor loading #4250

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/js/Sponsor.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 14 additions & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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]));
Expand Down
16 changes: 0 additions & 16 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ firmware_flasher.initialize = function (callback) {
}

self.isFlashing = false;
GUI.interval_resume('sponsor');
}

let result = getConfig('erase_chip');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1135,6 +1137,7 @@ firmware_flasher.initialize = function (callback) {
}

self.buildApi.loadTargets(() => {
console.log('Targets loaded');
$('#content').load("./tabs/firmware_flasher.html", onDocumentLoad);
});
};
Expand Down