polishing serial backend and background page

10.3.x-maintenance
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

@ -149,11 +149,10 @@ $(document).ready(function() {
});
});
function onOpen(openInfo) {
connectionId = openInfo.connectionId;
backgroundPage.connectionId = openInfo.connectionId; // also pass connectionId to the background page
if (connectionId != -1) {
function onOpen(openInfo) {
if (openInfo.connectionId > 0) {
connectionId = openInfo.connectionId;
// update connected_to
GUI.connected_to = GUI.connecting_to;
@ -229,20 +228,17 @@ 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
connectionId = -1; // reset connection id
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');
}
console.log('There was an error that happened during "connection-close" procedure.');
notify('Failed to close serial port', 'red');
}
}

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();