diff --git a/js/protocols/stm32.js b/js/protocols/stm32.js
index 14ce4cad..23e4c345 100644
--- a/js/protocols/stm32.js
+++ b/js/protocols/stm32.js
@@ -748,25 +748,34 @@ STM32_protocol.prototype.upload_procedure = function (step) {
GUI.interval_remove('STM32_timeout'); // stop STM32 timeout timer (everything is finished now)
// close connection
- serial.disconnect(function (result) {
- PortUsage.reset();
+ if (serial.connectionId) {
+ serial.disconnect(self.cleanup);
+ } else {
+ self.cleanup();
+ }
- // unlocking connect button
- GUI.connect_lock = false;
-
- // unlock some UI elements TODO needs rework
- $('select[name="release"]').prop('disabled', false);
-
- // handle timing
- var timeSpent = new Date().getTime() - self.upload_time_start;
-
- console.log('Script finished after: ' + (timeSpent / 1000) + ' seconds');
-
- if (self.callback) self.callback();
- });
break;
}
};
+STM32_protocol.prototype.cleanup = function () {
+ PortUsage.reset();
+
+ // unlocking connect button
+ GUI.connect_lock = false;
+
+ // unlock some UI elements TODO needs rework
+ $('select[name="release"]').prop('disabled', false);
+
+ // handle timing
+ var timeSpent = new Date().getTime() - self.upload_time_start;
+
+ console.log('Script finished after: ' + (timeSpent / 1000) + ' seconds');
+
+ if (self.callback) {
+ self.callback();
+ }
+}
+
// initialize object
var STM32 = new STM32_protocol();
diff --git a/tabs/firmware_flasher.js b/tabs/firmware_flasher.js
index d7ea6747..532556cc 100755
--- a/tabs/firmware_flasher.js
+++ b/tabs/firmware_flasher.js
@@ -480,46 +480,36 @@ TABS.firmware_flasher.initialize = function (callback) {
$('input.flash_manual_baud_rate').change();
});
- chrome.storage.local.get('flash_on_connect', function (result) {
- if (result.flash_on_connect) {
- $('input.flash_on_connect').prop('checked', true);
+ $('input.flash_on_connect').change(function () {
+ var status = $(this).is(':checked');
+
+ if (status) {
+ var catch_new_port = function () {
+ PortHandler.port_detected('flash_detected_device', function (result) {
+ var port = result[0];
+
+ if (!GUI.connect_lock) {
+ GUI.log('Detected: ' + port + ' - triggering flash on connect');
+ console.log('Detected: ' + port + ' - triggering flash on connect');
+
+ // Trigger regular Flashing sequence
+ GUI.timeout_add('initialization_timeout', function () {
+ $('a.flash_firmware').click();
+ }, 100); // timeout so bus have time to initialize after being detected by the system
+ } else {
+ GUI.log('Detected ' + port + ' - previous device still flashing, please replug to try again');
+ }
+
+ // Since current port_detected request was consumed, create new one
+ catch_new_port();
+ }, false, true);
+ };
+
+ catch_new_port();
} else {
- $('input.flash_on_connect').prop('checked', false);
+ PortHandler.flush_callbacks();
}
-
- $('input.flash_on_connect').change(function () {
- var status = $(this).is(':checked');
-
- if (status) {
- var catch_new_port = function () {
- PortHandler.port_detected('flash_detected_device', function (result) {
- var port = result[0];
-
- if (!GUI.connect_lock) {
- GUI.log('Detected: ' + port + ' - triggering flash on connect');
- console.log('Detected: ' + port + ' - triggering flash on connect');
-
- // Trigger regular Flashing sequence
- GUI.timeout_add('initialization_timeout', function () {
- $('a.flash_firmware').click();
- }, 100); // timeout so bus have time to initialize after being detected by the system
- } else {
- GUI.log('Detected ' + port + ' - previous device still flashing, please replug to try again');
- }
-
- // Since current port_detected request was consumed, create new one
- catch_new_port();
- }, false, true);
- };
-
- catch_new_port();
- } else {
- PortHandler.flush_callbacks();
- }
-
- chrome.storage.local.set({'flash_on_connect': status});
- }).change();
- });
+ }).change();
chrome.storage.local.get('erase_chip', function (result) {
if (result.erase_chip) {