From 56cb42d69f511759bf95ee798046f64be1f67b13 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Wed, 18 Dec 2024 20:28:29 +0100 Subject: [PATCH 1/3] Fix event handlers for file save and upload --- backend/serial/serial-bridge.js | 17 +++++++++++++++-- backend/serial/serial.js | 13 +++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/backend/serial/serial-bridge.js b/backend/serial/serial-bridge.js index 715d21a..90d4d2e 100644 --- a/backend/serial/serial-bridge.js +++ b/backend/serial/serial-bridge.js @@ -53,10 +53,23 @@ const SerialBridge = { return await ipcRenderer.invoke('serial', 'removeFile', file) }, saveFileContent: async (filename, content, dataConsumer) => { - return await ipcRenderer.invoke('serial', 'saveFileContent', filename, content, dataConsumer) + if (ipcRenderer.listeners("serial-on-file-save-progress").length > 0) { + ipcRenderer.removeAllListeners("serial-on-file-save-progress") + } + ipcRenderer.on('serial-on-file-save-progress', (event, progress) => { + dataConsumer(progress) + }) + return await ipcRenderer.invoke('serial', 'saveFileContent', filename, content) }, uploadFile: async (src, dest, dataConsumer) => { - return await ipcRenderer.invoke('serial', 'uploadFile', src, dest, dataConsumer) + if (ipcRenderer.listeners("serial-on-upload-progress").length > 0) { + ipcRenderer.removeAllListeners("serial-on-upload-progress") + } + + ipcRenderer.on('serial-on-upload-progress', (event, progress) => { + dataConsumer(progress) + }) + return await ipcRenderer.invoke('serial', 'uploadFile', src, dest) }, downloadFile: async (src, dest) => { let contents = await ipcRenderer.invoke('serial', 'loadFile', src) diff --git a/backend/serial/serial.js b/backend/serial/serial.js index e702b17..0460254 100644 --- a/backend/serial/serial.js +++ b/backend/serial/serial.js @@ -1,4 +1,5 @@ const MicroPython = require('micropython.js') +const path = require('path') class Serial { constructor(win = null) { @@ -79,12 +80,16 @@ class Serial { return await this.board.fs_rm(file) } - async saveFileContent(filename, content, dataConsumer) { - return await this.board.fs_save(content || ' ', filename, dataConsumer) + async saveFileContent(filename, content) { + return await this.board.fs_save(content || ' ', filename, (progress) => { + this.win.webContents.send('serial-on-file-save-progress', progress) + }) } - async uploadFile(src, dest, dataConsumer) { - return await this.board.fs_put(src, dest.replaceAll(path.win32.sep, path.posix.sep), dataConsumer) + async uploadFile(src, dest) { + return await this.board.fs_put(src, dest.replaceAll(path.win32.sep, path.posix.sep), (progress) => { + this.win.webContents.send('serial-on-upload-progress', progress) + }) } async renameFile(oldName, newName) { From 98c4ed08c5f2b02cc266bb262f9e55305d9dd9d0 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Wed, 18 Dec 2024 20:44:18 +0100 Subject: [PATCH 2/3] 0.11.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42738a5..c40dfba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "arduino-lab-micropython-ide", - "version": "0.11.0", + "version": "0.11.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "arduino-lab-micropython-ide", - "version": "0.11.0", + "version": "0.11.1", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index e86c5ba..b3f5abb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "arduino-lab-micropython-ide", "productName": "Arduino Lab for MicroPython", - "version": "0.11.0", + "version": "0.11.1", "description": "Arduino Lab for MicroPython is a project sponsored by Arduino, based on original work by Murilo Polese.\nThis is an experimental pre-release software, please direct any questions exclusively to Github issues.", "main": "index.js", "scripts": { From 9f77078fc236d25c7753a26170038b8fc45314dd Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Wed, 18 Dec 2024 21:02:14 +0100 Subject: [PATCH 3/3] Silence console output of serial handler --- backend/ipc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/ipc.js b/backend/ipc.js index ab06335..62a404f 100644 --- a/backend/ipc.js +++ b/backend/ipc.js @@ -145,7 +145,7 @@ module.exports = function registerIPCHandlers(win, ipcMain, app, dialog) { }) ipcMain.handle('serial', (event, command, ...args) => { - console.debug('Handling IPC serial command:', command, ...args) + // console.debug('Handling IPC serial command:', command, ...args) return serial[command](...args) }) }