Skip to content
Open
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
1 change: 1 addition & 0 deletions js/browser/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function installBrowserPlatform() {
appGetVersion: () => WEB_VERSION,
appGetLocale: () => navigator.language || "en",
appGetPath: () => "",
setBackgroundThrottling: () => {},
showOpenDialog: selectFile,
async showSaveDialog(options = {}) {
const defaultPath = options.defaultPath || "inav-download";
Expand Down
17 changes: 16 additions & 1 deletion js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import mspQueue from './serial_queue';
var GUI_control = function () {
this.connecting_to = false;
this.connected_to = false;
this.connect_lock = false;
this._connect_lock = false;
this.active_tab;
this.tab_switch_in_progress = false;
this.operating_system;
Expand Down Expand Up @@ -70,6 +70,21 @@ var GUI_control = function () {

};

// connect_lock is held for the whole firmware flashing. While it is held the renderer must not
// be throttled, otherwise flashing breaks when the window is unfocused, minimized or covered.
Object.defineProperty(GUI_control.prototype, 'connect_lock', {
get: function () {
return this._connect_lock;
},
set: function (locked) {
locked = !!locked;
if (locked !== this._connect_lock) {
this._connect_lock = locked;
window.electronAPI.setBackgroundThrottling(!locked);
}
}
});

// message = string
GUI_control.prototype.log = function (message) {
var command_log = $('div#log');
Expand Down
6 changes: 6 additions & 0 deletions js/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ app.whenReady().then(() => {
event.returnValue = app.getLocale();
});

// The renderer turns throttling off only while it flashes firmware: throttled timers
// break the flashing when the window is unfocused, minimized or covered.
ipcMain.on('setBackgroundThrottling', (event, allowed) => {
event.sender.setBackgroundThrottling(allowed);
});

ipcMain.handle('dialog.showOpenDialog', (_event, options) => {
return dialog.showOpenDialog(options);
}),
Expand Down
1 change: 1 addition & 0 deletions js/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
appGetPath: (name) => ipcRenderer.sendSync('appGetPath', name),
appGetVersion: () => ipcRenderer.sendSync('appGetVersion'),
appGetLocale: () => ipcRenderer.sendSync('appGetLocale'),
setBackgroundThrottling: (allowed) => ipcRenderer.send('setBackgroundThrottling', allowed),
showOpenDialog: (options) => ipcRenderer.invoke('dialog.showOpenDialog', options),
showSaveDialog: (options) => ipcRenderer.invoke('dialog.showSaveDialog', options),
alertDialog: (message) => ipcRenderer.sendSync('dialog.alert', message), // TODO: still blocks renderer event loop — needs same async fix (invoke/handle) as confirm; see ipcMain.on('dialog.alert') in main.js
Expand Down
4 changes: 4 additions & 0 deletions js/protocols/stm32usbdfu.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ STM32DFU_protocol.prototype.connect = function (usbDevices, hex, options, callba
self.options.erase_chip = true;
}

// also taken when flashing starts directly in DFU mode, released in cleanup()
GUI.connect_lock = true;

// reset and set some variables before we start
self.upload_time_start = new Date().getTime();
self.verify_hex = [];
Expand All @@ -111,6 +114,7 @@ STM32DFU_protocol.prototype.connect = function (usbDevices, hex, options, callba
} else {
console.log('USB DFU not found');
GUI.log(i18n.getMessage('stm32UsbDfuNotFound'));
GUI.connect_lock = false;
}

});
Expand Down
Loading