mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-15 04:15:28 +03:00
polishing serial backend and background page
This commit is contained in:
parent
49317da015
commit
a81cdb6d9d
3 changed files with 13 additions and 18 deletions
|
@ -10,9 +10,9 @@ function start_app() {
|
||||||
window_child.onClosed.addListener(function() {
|
window_child.onClosed.addListener(function() {
|
||||||
// connectionId is passed from the script side through the chrome.runtime.getBackgroundPage refference
|
// connectionId is passed from the script side through the chrome.runtime.getBackgroundPage refference
|
||||||
// allowing us to automatically close the port when application shut down
|
// allowing us to automatically close the port when application shut down
|
||||||
if (connectionId != -1) {
|
if (app_window.connectionId > 0) {
|
||||||
chrome.serial.close(connectionId, function() {
|
chrome.serial.close(app_window.connectionId, function(result) {
|
||||||
console.log('CLEANUP: Connection to serial port was opened after application closed, closing the connection.');
|
console.log('SERIAL: Connection closed - ' + result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -149,11 +149,10 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function onOpen(openInfo) {
|
function onOpen(openInfo) {
|
||||||
connectionId = openInfo.connectionId;
|
if (openInfo.connectionId > 0) {
|
||||||
backgroundPage.connectionId = openInfo.connectionId; // also pass connectionId to the background page
|
connectionId = openInfo.connectionId;
|
||||||
|
|
||||||
if (connectionId != -1) {
|
|
||||||
// update connected_to
|
// update connected_to
|
||||||
GUI.connected_to = GUI.connecting_to;
|
GUI.connected_to = GUI.connecting_to;
|
||||||
|
|
||||||
|
@ -229,20 +228,17 @@ function onOpen(openInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onClosed(result) {
|
function onClosed(result) {
|
||||||
if (result) { // All went as expected
|
connectionId = -1; // reset connection id
|
||||||
connectionId = -1; // reset connection id
|
|
||||||
backgroundPage.connectionId = connectionId; // also pass latest connectionId to the background page
|
if (result) { // All went as expected
|
||||||
|
|
||||||
sensor_status(sensors_detected = 0); // reset active sensor indicators
|
sensor_status(sensors_detected = 0); // reset active sensor indicators
|
||||||
$('#tabs > ul li').removeClass('active'); // de-select any selected tabs
|
$('#tabs > ul li').removeClass('active'); // de-select any selected tabs
|
||||||
tab_initialize_default();
|
tab_initialize_default();
|
||||||
|
|
||||||
console.log('Connection closed successfully.');
|
console.log('Connection closed successfully.');
|
||||||
} else { // Something went wrong
|
} else { // Something went wrong
|
||||||
if (connectionId > 0) {
|
console.log('There was an error that happened during "connection-close" procedure.');
|
||||||
console.log('There was an error that happened during "connection-close" procedure.');
|
notify('Failed to close serial port', 'red');
|
||||||
notify('Failed to close serial port', 'red');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
main.js
3
main.js
|
@ -2,10 +2,9 @@
|
||||||
// This object is used to pass current connectionId to the backround page
|
// This object is used to pass current connectionId to the backround page
|
||||||
// so the onClosed event can close the port for us if it was left opened, without this
|
// so the onClosed event can close the port for us if it was left opened, without this
|
||||||
// users can experience weird behavior if they would like to access the serial bus afterwards.
|
// users can experience weird behavior if they would like to access the serial bus afterwards.
|
||||||
var backgroundPage;
|
|
||||||
chrome.runtime.getBackgroundPage(function(result) {
|
chrome.runtime.getBackgroundPage(function(result) {
|
||||||
backgroundPage = result;
|
backgroundPage = result;
|
||||||
backgroundPage.connectionId = -1;
|
backgroundPage.app_window = window;
|
||||||
});
|
});
|
||||||
|
|
||||||
var timers = new Array();
|
var timers = new Array();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue