Skip to content

Commit 56cb42d

Browse files
committed
Fix event handlers for file save and upload
1 parent 8d7586a commit 56cb42d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

backend/serial/serial-bridge.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,23 @@ const SerialBridge = {
5353
return await ipcRenderer.invoke('serial', 'removeFile', file)
5454
},
5555
saveFileContent: async (filename, content, dataConsumer) => {
56-
return await ipcRenderer.invoke('serial', 'saveFileContent', filename, content, dataConsumer)
56+
if (ipcRenderer.listeners("serial-on-file-save-progress").length > 0) {
57+
ipcRenderer.removeAllListeners("serial-on-file-save-progress")
58+
}
59+
ipcRenderer.on('serial-on-file-save-progress', (event, progress) => {
60+
dataConsumer(progress)
61+
})
62+
return await ipcRenderer.invoke('serial', 'saveFileContent', filename, content)
5763
},
5864
uploadFile: async (src, dest, dataConsumer) => {
59-
return await ipcRenderer.invoke('serial', 'uploadFile', src, dest, dataConsumer)
65+
if (ipcRenderer.listeners("serial-on-upload-progress").length > 0) {
66+
ipcRenderer.removeAllListeners("serial-on-upload-progress")
67+
}
68+
69+
ipcRenderer.on('serial-on-upload-progress', (event, progress) => {
70+
dataConsumer(progress)
71+
})
72+
return await ipcRenderer.invoke('serial', 'uploadFile', src, dest)
6073
},
6174
downloadFile: async (src, dest) => {
6275
let contents = await ipcRenderer.invoke('serial', 'loadFile', src)

backend/serial/serial.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const MicroPython = require('micropython.js')
2+
const path = require('path')
23

34
class Serial {
45
constructor(win = null) {
@@ -79,12 +80,16 @@ class Serial {
7980
return await this.board.fs_rm(file)
8081
}
8182

82-
async saveFileContent(filename, content, dataConsumer) {
83-
return await this.board.fs_save(content || ' ', filename, dataConsumer)
83+
async saveFileContent(filename, content) {
84+
return await this.board.fs_save(content || ' ', filename, (progress) => {
85+
this.win.webContents.send('serial-on-file-save-progress', progress)
86+
})
8487
}
8588

86-
async uploadFile(src, dest, dataConsumer) {
87-
return await this.board.fs_put(src, dest.replaceAll(path.win32.sep, path.posix.sep), dataConsumer)
89+
async uploadFile(src, dest) {
90+
return await this.board.fs_put(src, dest.replaceAll(path.win32.sep, path.posix.sep), (progress) => {
91+
this.win.webContents.send('serial-on-upload-progress', progress)
92+
})
8893
}
8994

9095
async renameFile(oldName, newName) {

0 commit comments

Comments
 (0)