Skip to content

Commit

Permalink
Include helper as extra resource and load its path correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
murilopolese committed Apr 25, 2024
1 parent d16a173 commit 8b085dc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
9 changes: 9 additions & 0 deletions backend/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ module.exports = function registerIPCHandlers(win, ipcMain, app) {
app.exit()
})

ipcMain.handle('is-packaged', () => {
return app.isPackaged
})

ipcMain.handle('get-app-path', () => {
console.log('ipcMain', 'get-app-path')
return app.getAppPath()
})

win.on('close', (event) => {
console.log('BrowserWindow', 'close')
event.preventDefault()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"build": {
"appId": "cc.arduino.micropython-lab",
"artifactName": "${productName}-${os}_${arch}.${ext}",
"extraResources": "./ui/arduino/helpers.py",
"mac": {
"target": "zip",
"icon": "build_resources/icon.icns"
Expand Down
6 changes: 5 additions & 1 deletion preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ const Disk = {
},
fileExists: async (filePath) => {
return ipcRenderer.invoke('file-exists', filePath)
},
getAppPath: () => {
return ipcRenderer.invoke('get-app-path')
}
}

Expand All @@ -153,7 +156,8 @@ const Window = {
ipcRenderer.invoke('set-window-size', minWidth, minHeight)
},
beforeClose: (callback) => ipcRenderer.on('check-before-close', callback),
confirmClose: () => ipcRenderer.invoke('confirm-close')
confirmClose: () => ipcRenderer.invoke('confirm-close'),
isPackaged: () => ipcRenderer.invoke('is-packaged')
}


Expand Down
21 changes: 19 additions & 2 deletions ui/arduino/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ function canEdit({ selectedFiles }) {

async function removeBoardFolder(fullPath) {
// TODO: Replace with getting the file tree from the board and deleting one by one
let output = await serial.execFile('./ui/arduino/helpers.py')
let output = await serial.execFile(await getHelperFullPath())
await serial.run(`delete_folder('${fullPath}')`)
}

Expand Down Expand Up @@ -1522,7 +1522,7 @@ async function uploadFolder(srcPath, destPath, dataConsumer) {
async function downloadFolder(srcPath, destPath, dataConsumer) {
dataConsumer = dataConsumer || function() {}
await disk.createFolder(destPath)
let output = await serial.execFile('./ui/arduino/helpers.py')
let output = await serial.execFile(await getHelperFullPath())
output = await serial.run(`ilist_all('${srcPath}')`)
let files = []
try {
Expand Down Expand Up @@ -1550,3 +1550,20 @@ async function downloadFolder(srcPath, destPath, dataConsumer) {
}
}
}

async function getHelperFullPath() {
const appPath = await disk.getAppPath()
if (await win.isPackaged()) {
return disk.getFullPath(
appPath,
'..',
'ui/arduino/helpers.py'
)
} else {
return disk.getFullPath(
appPath,
'ui/arduino/helpers.py',
''
)
}
}

0 comments on commit 8b085dc

Please sign in to comment.