Skip to content

Commit

Permalink
Merge pull request #112 from arduino/development
Browse files Browse the repository at this point in the history
v0.9.0
  • Loading branch information
murilopolese authored Apr 16, 2024
2 parents 8b57764 + 4ef45c9 commit 9160342
Show file tree
Hide file tree
Showing 535 changed files with 37,999 additions and 10,265 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Arduino MicroPython Lab
name: Arduino Lab for MicroPython

on:
push:
Expand Down Expand Up @@ -96,15 +96,15 @@ jobs:
matrix:
artifact:
- path: "*-linux_x64.zip"
name: Linux_X86-64
name: Arduino-Lab-for-MicroPython_Linux_X86-64
- path: "*-mac_x64.zip"
name: macOS
name: Arduino-Lab-for-MicroPython_macOS_X86-64
# - path: "*Windows_64bit.exe"
# name: Windows_X86-64_interactive_installer
# - path: "*Windows_64bit.msi"
# name: Windows_X86-64_MSI
- path: "*-win_x64.zip"
name: Windows_X86-64_zip
name: Arduino-Lab-for-MicroPython_Windows_X86-64

steps:
- name: Download job transfer artifact
Expand Down
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
# Arduino Lab for MicroPython

Arduino Lab for MicroPython is a lightweight editor for MicroPython programs, supporting connection with a board, code upload, file transfer, interactive REPL shell.
This project is sponsored by Arduino, based on original work by Murilo Polese. This is an experimental pre-release software, please direct any questions only to Github issues.
<p align="center">

<img src="https://github.com/arduino/lab-micropython-editor/blob/development/ui/arduino/documents/Screenshot%20from%202024-04-15%2009-48-25.png?raw=true" width="50%" />

</p>

Arduino Lab for MicroPython is a lightweight editor for MicroPython programs, supporting connection with a board, code upload, file transfer and interactive REPL shell.
This project is sponsored by Arduino, based on original work by [Murilo Polese](http://www.murilopolese.com). This is an experimental pre-release software, please direct any questions only to Github issues.

## Features
- MicroPython's Read Eval Print Loop (REPL)
- Enter paste mode
- Enter raw repl
- Software reset
- Tab to autocomplete
- File system management (Disk and MicroPython File System)
- Create
- Rename
- Multiple file and folder selection
- Remove
- Upload
- Download
- Text editor with Python syntax highlight
- Code execution controls
- Text editor
- Python syntax highlight and autocomplete
- Multiple tabs
- Rename tabs
- Code execution
- Run what's on text editor
- Stop (keyboard interrupt)
- Soft reset

## Technical
## Technical overview

Arduino Lab for MicroPython is an [Electron](https://www.electronjs.org/) app that has its main purpose to communicate over serial with a microprocessor running [MicroPython](https://micropython.org/). All Electron code is at `/index.js`.

Expand All @@ -36,33 +47,21 @@ At the root of the repository you will find:

- `/.github`: Github's workflow configuration.
- `/build_resources`: Icons and other assets used during the build process.
- `/scripts`: Scripts executed during the build process.
- `/ui`: Available user interfaces.
- `/index.js`: Main Electron code.
- `/preload.js`: Creates Disk and Serial APIs on Electron's main process and exposes it to Electron's renderer process (context bridge).

## Arduino UI
- `/preload.js`: Creates Disk, Serial and Window APIs on Electron's main process and exposes it to Electron's renderer process (context bridge).

Default UI is a [choo-choo](https://github.com/choojs/choo) app. It has pre-built dependencies so no build process is required for the interface.
## User interface

The dependencies and source code are included manually in the `/ui/arduino/index.html` file.

The app is a standard [choo-choo](https://github.com/choojs/choo) app and it has:

- `/ui/arduino/app.js`: A router deciding which view to load.
- `/ui/arduino/components`: HTML templates and components.
- `/ui/arduino/store.js`: A "store" that handles events emitted by the views, change the app state and orchestrate re-rendering.
- `/ui/arduino/libs`: Prebuilt dependencies.

It can be useful to learn more about [Choo](https://github.com/choojs/choo) or the [Elm Architecture](https://guide.elm-lang.org/architecture/).
Read more at [`/ui/arduino/README.md`](./ui/arduino/README.md)

## Disk and Serial API

In order for the UI code to be independent of Electron code, there is an API defined at `/preload.js` that describes all the allowed operations.

There are 2 main operation "channels": Serial communication and local Filesystem operations. Both channels offer methods that always return promises and are used mostly through [`async`/`await`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
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).

While the serial communication is mediated by `/micropython.js`, the local filesystem operations are done through Electron's `ipcRenderer` calls. The handlers for these calls are defined at `/index.js`
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`

## Running Arduino Lab for MicroPython from source code

Expand All @@ -73,7 +72,6 @@ While the serial communication is mediated by `/micropython.js`, the local files

Some changes on the Electron code will require reopening the app but all UI changes will only require refreshing the window (ctrl-r/cmd-r).


## Trademarks

"Python" and the Python Logo are trademarks of the Python Software Foundation.
Expand Down
51 changes: 51 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ function ilistFolder(folder) {
return files
}

function getAllFiles(dirPath, arrayOfFiles) {
// https://coderrocketfuel.com/article/recursively-list-all-the-files-in-a-directory-using-node-js
files = ilistFolder(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function(file) {
const p = path.join(dirPath, file.path)
const stat = fs.statSync(p)
arrayOfFiles.push({
path: p,
type: stat.isDirectory() ? 'folder' : 'file'
})
if (stat.isDirectory()) {
arrayOfFiles = getAllFiles(p, arrayOfFiles)
}
})
return arrayOfFiles
}

// LOCAL FILE SYSTEM ACCESS
ipcMain.handle('open-folder', async (event) => {
console.log('ipcMain', 'open-folder')
Expand All @@ -63,6 +81,12 @@ ipcMain.handle('ilist-files', async (event, folder) => {
return ilistFolder(folder)
})

ipcMain.handle('ilist-all-files', (event, folder) => {
console.log('ipcMain', 'ilist-all-files', folder)
if (!folder) return []
return getAllFiles(folder)
})

ipcMain.handle('load-file', (event, filePath) => {
console.log('ipcMain', 'load-file', filePath)
let content = fs.readFileSync(filePath)
Expand Down Expand Up @@ -98,6 +122,32 @@ ipcMain.handle('rename-file', (event, filePath, newFilePath) => {
return true
})

ipcMain.handle('create-folder', (event, folderPath) => {
console.log('ipcMain', 'create-folder', folderPath)
try {
fs.mkdirSync(folderPath, { recursive: true })
} catch(e) {
console.log('error', e)
return false
}
return true
})

ipcMain.handle('remove-folder', (event, folderPath) => {
console.log('ipcMain', 'remove-folder', folderPath)
fs.rmdirSync(folderPath, { recursive: true, force: true })
return true
})

ipcMain.handle('file-exists', (event, filePath) => {
console.log('ipcMain', 'file-exists', filePath)
try {
fs.accessSync(filePath, fs.constants.F_OK)
return true
} catch(err) {
return false
}
})
// WINDOW MANAGEMENT

ipcMain.handle('set-window-size', (event, minWidth, minHeight) => {
Expand Down Expand Up @@ -125,6 +175,7 @@ function createWindow () {
})
// and load the index.html of the app.
win.loadFile('ui/arduino/index.html')
// win.loadFile('ui/sandbox/index.html')
}

// TODO: Loading splash screen
Expand Down
Loading

0 comments on commit 9160342

Please sign in to comment.