Skip to content

Commit 0b84623

Browse files
authored
Merge pull request #30 from arduino/develop
Release Candidate v0.6
2 parents 53baad4 + d3d491a commit 0b84623

File tree

8 files changed

+180
-4918
lines changed

8 files changed

+180
-4918
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install Node.js 16.x
3636
uses: actions/setup-node@v3
3737
with:
38-
node-version: '14'
38+
node-version: '16'
3939
registry-url: 'https://registry.npmjs.org'
4040

4141
# - name: Install Python 2.7

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ ipcMain.handle('rename-file', (event, folder, filename, newFilename) => {
8181
return newFilename
8282
})
8383

84+
ipcMain.handle('set-window-size', (event, minWidth, minHeight) => {
85+
console.log('ipcMain', 'set-window-size', minWidth, minHeight)
86+
if (!win) {
87+
console.log('No window defined')
88+
return false
89+
}
90+
91+
win.setMinimumSize(minWidth, minHeight)
92+
})
93+
8494
// START APP
8595
function createWindow () {
8696
// Create the browser window.

micropython.js

+43-15
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ class MicroPythonBoard {
3232
async open(device) {
3333
if (device) {
3434
this.device = device
35-
}
36-
if (!this.device) {
37-
throw new Error(`No device specified`)
35+
} else {
36+
return Promise.reject(
37+
new Error(`No device specified`)
38+
)
3839
}
3940
if (this.serial && this.serial.isOpen) {
4041
await this.serial.close()
@@ -73,8 +74,10 @@ class MicroPythonBoard {
7374
timeout = null,
7475
data_consumer = () => false
7576
} = options || {}
77+
const parser = this.serial.pipe(
78+
new ReadlineParser({ delimiter: ending })
79+
)
7680
return new Promise((resolve, reject) => {
77-
const parser = this.serial.pipe(new ReadlineParser({ delimiter: ending }))
7881
let waiting = 0
7982
if (timeout) {
8083
waiting = setTimeout(() => {
@@ -196,11 +199,31 @@ class MicroPythonBoard {
196199
return Promise.reject()
197200
}
198201

199-
async fs_ls() {
202+
async fs_exists(filePath) {
203+
filePath = filePath || ''
204+
let command = `try:\n`
205+
command += ` f = open("${filePath}", "r")\n`
206+
command += ` print(1)\n`
207+
command += `except OSError:\n`
208+
command += ` print(0)\n`
200209
await this.enter_raw_repl()
201-
const output = await this.exec_raw({
202-
command: `import uos\nprint(uos.listdir())`
203-
})
210+
let output = await this.exec_raw({ command: command })
211+
await this.exit_raw_repl()
212+
// Extract output
213+
output = output.split('OK')
214+
let result = output[2] || ''
215+
return Promise.resolve(result[0] === '1')
216+
}
217+
218+
async fs_ls(folderPath) {
219+
folderPath = folderPath || ''
220+
let command = `import uos\n`
221+
command += `try:\n`
222+
command += ` print(uos.listdir("${folderPath}"))\n`
223+
command += `except OSError:\n`
224+
command += ` print([])\n`
225+
await this.enter_raw_repl()
226+
const output = await this.exec_raw({ command: command })
204227
await this.exit_raw_repl()
205228
return Promise.resolve(output)
206229
}
@@ -267,29 +290,34 @@ class MicroPythonBoard {
267290
const output = await this.exec_raw({
268291
command: `import uos\nuos.mkdir('${filePath}')`
269292
})
270-
console.log(output)
271293
return this.exit_raw_repl()
272294
}
273295
return Promise.reject()
274296
}
275297

276298
async fs_rmdir() {
277299
if (filePath) {
300+
let command = `import uos\n`
301+
command += `try:\n`
302+
command += ` uos.rmdir("${filePath}")\n`
303+
command += `except OSError:\n`
304+
command += ` print(0)\n`
278305
await this.enter_raw_repl()
279-
const output = await this.exec_raw({
280-
command: `import uos\nuos.rmdir('${filePath}')`
281-
})
306+
const output = await this.exec_raw({ command: command })
282307
return this.exit_raw_repl()
283308
}
284309
return Promise.reject()
285310
}
286311

287312
async fs_rm(filePath) {
288313
if (filePath) {
314+
let command = `import uos\n`
315+
command += `try:\n`
316+
command += ` uos.remove("${filePath}")\n`
317+
command += `except OSError:\n`
318+
command += ` print(0)\n`
289319
await this.enter_raw_repl()
290-
const output = await this.exec_raw({
291-
command: `import uos\nuos.remove('${filePath}')`
292-
})
320+
const output = await this.exec_raw({ command: command })
293321
return this.exit_raw_repl()
294322
}
295323
return Promise.reject()

0 commit comments

Comments
 (0)