1
0
Fork 0
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:
cTn 2013-12-06 18:32:32 +01:00
parent 49317da015
commit a81cdb6d9d
3 changed files with 13 additions and 18 deletions

View file

@ -10,9 +10,9 @@ function start_app() {
window_child.onClosed.addListener(function() {
// connectionId is passed from the script side through the chrome.runtime.getBackgroundPage refference
// allowing us to automatically close the port when application shut down
if (connectionId != -1) {
chrome.serial.close(connectionId, function() {
console.log('CLEANUP: Connection to serial port was opened after application closed, closing the connection.');
if (app_window.connectionId > 0) {
chrome.serial.close(app_window.connectionId, function(result) {
console.log('SERIAL: Connection closed - ' + result);
});
}
});

View file

@ -150,10 +150,9 @@ $(document).ready(function() {
});
function onOpen(openInfo) {
if (openInfo.connectionId > 0) {
connectionId = openInfo.connectionId;
backgroundPage.connectionId = openInfo.connectionId; // also pass connectionId to the background page
if (connectionId != -1) {
// update connected_to
GUI.connected_to = GUI.connecting_to;
@ -229,22 +228,19 @@ function onOpen(openInfo) {
}
function onClosed(result) {
if (result) { // All went as expected
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
$('#tabs > ul li').removeClass('active'); // de-select any selected tabs
tab_initialize_default();
console.log('Connection closed successfully.');
} else { // Something went wrong
if (connectionId > 0) {
console.log('There was an error that happened during "connection-close" procedure.');
notify('Failed to close serial port', 'red');
}
}
}
function readPoll() {
chrome.serial.read(connectionId, 128, MSP_char_read);

View file

@ -2,10 +2,9 @@
// 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
// users can experience weird behavior if they would like to access the serial bus afterwards.
var backgroundPage;
chrome.runtime.getBackgroundPage(function(result) {
backgroundPage = result;
backgroundPage.connectionId = -1;
backgroundPage.app_window = window;
});
var timers = new Array();