diff --git a/js/serial_backend.js b/js/serial_backend.js index 5276e0a32b..b4c98c8811 100644 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -145,6 +145,18 @@ $(document).ready(function() { text: port })); }); + + chrome.storage.local.get('last_used_port', function(result) { + // if last_used_port was set, we try to select it + if (typeof result.last_used_port != 'undefined') { + // check if same port exists, if it does, select it + ports.forEach(function(port) { + if (port == result.last_used_port) { + $(port_picker).val(result.last_used_port); + } + }); + } + }); } else { $(port_picker).append($("", { value: 0, @@ -218,6 +230,19 @@ function onOpen(openInfo) { if (connectionId != -1) { console.log('Connection was opened with ID: ' + connectionId); + // save selected port with chrome.storage if the port differs + chrome.storage.local.get('last_used_port', function(result) { + if (typeof result.last_used_port != 'undefined') { + if (result.last_used_port != selected_port) { + // last used port doesn't match the one found in local db, we will store the new one + chrome.storage.local.set({'last_used_port': selected_port}, function() { + // Debug message is currently disabled (we dont need to spam the console log with that) + // console.log('Last selected port was saved in chrome.storage.'); + }); + } + } + }); + connection_delay = setTimeout(function() { // start polling serial_poll = setInterval(readPoll, 10); diff --git a/manifest.json b/manifest.json index f0155fc8f0..951d804e1f 100644 --- a/manifest.json +++ b/manifest.json @@ -13,6 +13,7 @@ "permissions": [ "serial", + "storage", "fileSystem", "fileSystem.write" ], diff --git a/tabs/initial_setup.html b/tabs/initial_setup.html index a52298846d..ad1efc51c0 100644 --- a/tabs/initial_setup.html +++ b/tabs/initial_setup.html @@ -22,7 +22,7 @@ Backup Restore
- Backup your configuration in case of an accident. + Backup your configuration in case of an accident. (CLI settings not included)