Skip to content

Commit 8268359

Browse files
authored
Merge pull request #165 from arduino/bugfix/fix-file-transfer
Fix event handlers for file save and upload
2 parents 8d7586a + 98c4ed0 commit 8268359

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

Diff for: backend/serial/serial-bridge.js

+15-2
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)

Diff for: backend/serial/serial.js

+9-4
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) {

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "arduino-lab-micropython-ide",
33
"productName": "Arduino Lab for MicroPython",
4-
"version": "0.11.0",
4+
"version": "0.11.1",
55
"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.",
66
"main": "index.js",
77
"scripts": {

0 commit comments

Comments
 (0)