Skip to content

Commit

Permalink
Merge pull request #166 from arduino/development
Browse files Browse the repository at this point in the history
Fixing file save bug > 0.11.1
  • Loading branch information
ubidefeo authored Dec 18, 2024
2 parents 3d4a54b + 187424b commit 5c42aeb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
17 changes: 15 additions & 2 deletions backend/serial/serial-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions backend/serial/serial.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const MicroPython = require('micropython.js')
const path = require('path')

class Serial {
constructor(win = null) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 5c42aeb

Please sign in to comment.