1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-14 20:10:11 +03:00

fix for BUS holding after onClose

This commit is contained in:
cTn 2013-06-19 13:06:14 +02:00
parent 52e46bd9e2
commit a42a464d1f
3 changed files with 22 additions and 0 deletions

View file

@ -6,5 +6,15 @@ chrome.app.runtime.onLaunched.addListener(function() {
maxWidth: 960,
minHeight: 600,
maxHeight: 600
}, function(window_child) {
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.');
});
}
});
});
});

View file

@ -1,3 +1,13 @@
// Get access to the background window object
// 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;
});
// OS detection
var OS = "Unknown";
if (navigator.appVersion.indexOf("Win") != -1) OS = "Windows";

View file

@ -226,6 +226,7 @@ $(document).ready(function() {
function onOpen(openInfo) {
connectionId = openInfo.connectionId;
backgroundPage.connectionId = openInfo.connectionId; // also pass connectionId to the background page
if (connectionId != -1) {
console.log('Connection was opened with ID: ' + connectionId);
@ -273,6 +274,7 @@ 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
sensor_status(sensors_detected = 0); // reset active sensor indicators
$('#content').empty(); // empty content