From ed963bfdada5c7e3cb68f1e386a0b388c00161b9 Mon Sep 17 00:00:00 2001 From: cTn Date: Mon, 20 Jan 2014 20:15:23 +0100 Subject: [PATCH] bugfix --- background.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/background.js b/background.js index 8e324d8c05..3c50737271 100644 --- a/background.js +++ b/background.js @@ -7,8 +7,12 @@ 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 (app_window.serial.connectionId > 0) { - chrome.serial.disconnect(app_window.serial.connectionId, function(result) { + + // save connectionId in separate variable before app_window is destroyed + var connectionId = app_window.serial.connectionId; + + if (connectionId > 0) { + chrome.serial.disconnect(connectionId, function(result) { console.log('SERIAL: Connection closed - ' + result); }); }