Skip to content

Fix event handlers for file save and upload #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading