From 8b085dc332e0ccdee60e18f92906100034a7a96f Mon Sep 17 00:00:00 2001 From: Murilo Polese Date: Thu, 25 Apr 2024 10:46:30 +0200 Subject: [PATCH] Include helper as extra resource and load its path correctly --- backend/ipc.js | 9 +++++++++ package.json | 1 + preload.js | 6 +++++- ui/arduino/store.js | 21 +++++++++++++++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/backend/ipc.js b/backend/ipc.js index b1133b4..d4ddc74 100644 --- a/backend/ipc.js +++ b/backend/ipc.js @@ -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() diff --git a/package.json b/package.json index 74ab24b..d87247b 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/preload.js b/preload.js index 05abf0c..3388904 100644 --- a/preload.js +++ b/preload.js @@ -145,6 +145,9 @@ const Disk = { }, fileExists: async (filePath) => { return ipcRenderer.invoke('file-exists', filePath) + }, + getAppPath: () => { + return ipcRenderer.invoke('get-app-path') } } @@ -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') } diff --git a/ui/arduino/store.js b/ui/arduino/store.js index 93ed063..f008c4b 100644 --- a/ui/arduino/store.js +++ b/ui/arduino/store.js @@ -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}')`) } @@ -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 { @@ -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', + '' + ) + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy