Skip to content

Commit

Permalink
Fix potentially missing disconnect error, and warning badge race
Browse files Browse the repository at this point in the history
  • Loading branch information
pdf committed Feb 1, 2017
1 parent 0185b90 commit 955efd3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ function resetReconnect() {

function onDisconnect() {
port = null;
setWarningBadge([255, 0, 0, 220]);
// Disconnected, cancel back-off reset
if (typeof reconnectResetTimer === 'number') {
window.clearTimeout(reconnectResetTimer);
Expand All @@ -219,9 +220,11 @@ function onDisconnect() {
reconnectTimer = null;
}

var message = chrome.runtime.lastError.message;
var message;
if (chrome.runtime.lastError) {
message = chrome.runtime.lastError.message;
}
console.warn('Disconnected from native host: ' + message);
setWarningBadge([255, 0, 0, 220]);

// Exponential back-off on reconnect
reconnectTimer = window.setTimeout(function() {
Expand All @@ -231,6 +234,7 @@ function onDisconnect() {
}

function connect() {
clearWarningBadge();
port = chrome.runtime.connectNative(hostname);
// Reset the back-off delay if we stay connected
reconnectResetTimer = window.setTimeout(function() {
Expand All @@ -239,7 +243,6 @@ function connect() {

port.onDisconnect.addListener(onDisconnect);
port.onMessage.addListener(onMessage);
clearWarningBadge();
port.postMessage({ type: 'typeDevices' });
}

Expand Down

0 comments on commit 955efd3

Please sign in to comment.