Skip to content

Extra resource #121

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 1 commit into from
Apr 26, 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
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',
''
)
}
}