Skip to content

Commit c49a333

Browse files
committed
Merge branch 'development' into feature/show-filename-transfer
2 parents 631bcfc + b05f397 commit c49a333

File tree

6 files changed

+62
-23
lines changed

6 files changed

+62
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ In order for the UI code to be independent of Electron code, there is an API def
6262

6363
There are 3 main operation "channels": Serial communication, local filesystem and window operations. These channels offer methods that should always return promises and are used mostly through [`async`/`await`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
6464

65-
While the serial communication is mediated by `/micropython.js`, the local filesystem and window operations are done through Electron's `ipcRenderer` calls. The handlers for these calls are defined at `/index.js`
65+
While the serial communication is mediated by [`micropython.js`](https://github.com/arduino/micropython.js), the local filesystem and window operations are done through Electron's `ipcRenderer` calls. The handlers for these calls are defined at [`backend`](https://github.com/arduino/lab-micropython-editor/tree/main/backend) folder.
6666

6767
## Running Arduino Lab for MicroPython from source code
6868

backend/ipc.js

Lines changed: 9 additions & 0 deletions
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-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "arduino-lab-micropython-ide",
33
"productName": "Arduino Lab for MicroPython",
4-
"version": "0.9.1",
4+
"version": "0.10.0",
55
"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.",
66
"main": "index.js",
77
"scripts": {
@@ -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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ async function store(state, emitter) {
117117
// Recover from getting stuck in raw repl
118118
await serial.getPrompt()
119119

120-
// Make sure there is a lib folder
121-
log('creating lib folder')
122-
await serial.createFolder('/lib')
123-
124120
// Connected and ready
125121
state.isConnecting = false
126122
state.isConnected = true
@@ -406,24 +402,36 @@ async function store(state, emitter) {
406402
emitter.emit('render')
407403

408404
if (state.isConnected) {
409-
state.boardFiles = await getBoardFiles(
410-
serial.getFullPath(
411-
state.boardNavigationRoot,
412-
state.boardNavigationPath,
413-
''
405+
try {
406+
state.boardFiles = await getBoardFiles(
407+
serial.getFullPath(
408+
state.boardNavigationRoot,
409+
state.boardNavigationPath,
410+
''
411+
)
414412
)
415-
)
413+
} catch (e) {
414+
state.boardFiles = []
415+
}
416416
} else {
417417
state.boardFiles = []
418418
}
419419

420-
state.diskFiles = await getDiskFiles(
421-
disk.getFullPath(
422-
state.diskNavigationRoot,
423-
state.diskNavigationPath,
424-
''
420+
try {
421+
state.diskFiles = await getDiskFiles(
422+
disk.getFullPath(
423+
state.diskNavigationRoot,
424+
state.diskNavigationPath,
425+
''
426+
)
425427
)
426-
)
428+
} catch (e) {
429+
state.diskNavigationRoot = null
430+
state.diskNavigationPath = '/'
431+
state.isLoadingFiles = false
432+
emitter.emit('render')
433+
return
434+
}
427435

428436
emitter.emit('refresh-selected-files')
429437
state.isLoadingFiles = false
@@ -1490,7 +1498,7 @@ function canEdit({ selectedFiles }) {
14901498

14911499
async function removeBoardFolder(fullPath) {
14921500
// 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')
1501+
let output = await serial.execFile(await getHelperFullPath())
14941502
await serial.run(`delete_folder('${fullPath}')`)
14951503
}
14961504

@@ -1522,7 +1530,7 @@ async function uploadFolder(srcPath, destPath, dataConsumer) {
15221530
async function downloadFolder(srcPath, destPath, dataConsumer) {
15231531
dataConsumer = dataConsumer || function() {}
15241532
await disk.createFolder(destPath)
1525-
let output = await serial.execFile('./ui/arduino/helpers.py')
1533+
let output = await serial.execFile(await getHelperFullPath())
15261534
output = await serial.run(`ilist_all('${srcPath}')`)
15271535
let files = []
15281536
try {
@@ -1550,3 +1558,20 @@ async function downloadFolder(srcPath, destPath, dataConsumer) {
15501558
}
15511559
}
15521560
}
1561+
1562+
async function getHelperFullPath() {
1563+
const appPath = await disk.getAppPath()
1564+
if (await win.isPackaged()) {
1565+
return disk.getFullPath(
1566+
appPath,
1567+
'..',
1568+
'ui/arduino/helpers.py'
1569+
)
1570+
} else {
1571+
return disk.getFullPath(
1572+
appPath,
1573+
'ui/arduino/helpers.py',
1574+
''
1575+
)
1576+
}
1577+
}

0 commit comments

Comments
 (0)