Skip to content

Commit 8b085dc

Browse files
committed
Include helper as extra resource and load its path correctly
1 parent d16a173 commit 8b085dc

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

backend/ipc.js

+9
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ module.exports = function registerIPCHandlers(win, ipcMain, app) {
113113
app.exit()
114114
})
115115

116+
ipcMain.handle('is-packaged', () => {
117+
return app.isPackaged
118+
})
119+
120+
ipcMain.handle('get-app-path', () => {
121+
console.log('ipcMain', 'get-app-path')
122+
return app.getAppPath()
123+
})
124+
116125
win.on('close', (event) => {
117126
console.log('BrowserWindow', 'close')
118127
event.preventDefault()

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"build": {
2222
"appId": "cc.arduino.micropython-lab",
2323
"artifactName": "${productName}-${os}_${arch}.${ext}",
24+
"extraResources": "./ui/arduino/helpers.py",
2425
"mac": {
2526
"target": "zip",
2627
"icon": "build_resources/icon.icns"

preload.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ const Disk = {
145145
},
146146
fileExists: async (filePath) => {
147147
return ipcRenderer.invoke('file-exists', filePath)
148+
},
149+
getAppPath: () => {
150+
return ipcRenderer.invoke('get-app-path')
148151
}
149152
}
150153

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

159163

ui/arduino/store.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ function canEdit({ selectedFiles }) {
14901490

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

@@ -1522,7 +1522,7 @@ async function uploadFolder(srcPath, destPath, dataConsumer) {
15221522
async function downloadFolder(srcPath, destPath, dataConsumer) {
15231523
dataConsumer = dataConsumer || function() {}
15241524
await disk.createFolder(destPath)
1525-
let output = await serial.execFile('./ui/arduino/helpers.py')
1525+
let output = await serial.execFile(await getHelperFullPath())
15261526
output = await serial.run(`ilist_all('${srcPath}')`)
15271527
let files = []
15281528
try {
@@ -1550,3 +1550,20 @@ async function downloadFolder(srcPath, destPath, dataConsumer) {
15501550
}
15511551
}
15521552
}
1553+
1554+
async function getHelperFullPath() {
1555+
const appPath = await disk.getAppPath()
1556+
if (await win.isPackaged()) {
1557+
return disk.getFullPath(
1558+
appPath,
1559+
'..',
1560+
'ui/arduino/helpers.py'
1561+
)
1562+
} else {
1563+
return disk.getFullPath(
1564+
appPath,
1565+
'ui/arduino/helpers.py',
1566+
''
1567+
)
1568+
}
1569+
}

0 commit comments

Comments
 (0)