diff --git a/src/api/flash/defyFlasher/flash.js b/src/api/flash/defyFlasher/flash.js index 506a01287..441708d22 100644 --- a/src/api/flash/defyFlasher/flash.js +++ b/src/api/flash/defyFlasher/flash.js @@ -163,8 +163,8 @@ export class FlashDefyWireless { */ async saveBackupFile() { const userDataPath = await ipcRenderer.invoke("get-userPath", "userData"); - const route = path.join(userDataPath, this.backupFileName + ".json"); - console.log("saving file to: " + route); + const route = path.join(userDataPath, `${this.backupFileName}.json`); + console.log(`saving file to: ${route}`); fs.writeFile(route, JSON.stringify(this.backupFileData), err => { if (err) throw err; }); @@ -212,7 +212,9 @@ export class FlashDefyWireless { this.backup = backup; return new Promise(async (resolve, reject) => { stateUpdate("reset", 10); - focus.command("upgrade.neuron"); + focus.command("upgrade.neuron").catch(err => { + if (err) console.log("answer after shutdown not received"); + }); console.log("waiting for bootloader"); await this.delay(1000); stateUpdate("reset", 30); diff --git a/src/api/focus/index.js b/src/api/focus/index.js index 019a27ac6..eee986428 100644 --- a/src/api/focus/index.js +++ b/src/api/focus/index.js @@ -80,27 +80,30 @@ class Focus { } async open(device, info, file) { - try { - if (file !== null) { - await this.fileOpen(info, file); - return true; - } - - if (this._port !== undefined && this._port.isOpen === false) { - this.close(); - } + if (file !== null) { + await this.fileOpen(info, file); + return true; + } - // console.log("Warning! device being opened"); - // console.log("port status opened?", this._port ? this._port.isOpen : "unknown"); - // console.log("received device", device); - // console.log("received info: ", info); + if (this._port !== undefined && this._port.isOpen === false) { + this.close(); + } + // console.log("Warning! device being opened"); + // console.log("port status opened?", this._port ? this._port.isOpen : "unknown"); + // console.log("received device", device); + // console.log("received info: ", info); + try { let path; if (typeof device === "string") path = device; if (typeof device === "object") path = device.settings.path; if (path !== undefined) { await SerialPort.list(); - this._port = new SerialPort({ path, baudRate: 115200, autoOpen: true }); + this._port = new SerialPort({ path, baudRate: 115200, autoOpen: false }); + await this._port.open(err => { + if (err) console.error("error when opening port: ", err); + else console.log("connected"); + }); } else { throw Error("device not a string or object!"); } @@ -142,18 +145,18 @@ class Focus { // Ignore } } - - // Setup error port alert - this._port.on("error", async function (err) { - console.error(`Error on SerialPort: ${err}`); - await this._port.close(); - }); - this.closed = false; - return this._port; } catch (error) { console.error("found this error while opening!", error); // throw new Error("Unable to connect"); } + + // Setup error port alert + this._port.on("error", async function (err) { + console.error(`Error on SerialPort: ${err}`); + await this._port.close(); + }); + this.closed = false; + return this._port; } clearContext() {