Skip to content

Commit

Permalink
Merge pull request #49 from arduino/feature/new-file-management
Browse files Browse the repository at this point in the history
Feature/new file management
  • Loading branch information
murilopolese authored Jun 22, 2023
2 parents c14d293 + f511561 commit 44bd0f6
Show file tree
Hide file tree
Showing 22 changed files with 1,433 additions and 589 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This project is sponsored by Arduino, based on original work by Murilo Polese. T

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`.

All operations over serial are abstracted and packaged on `/micropython.js` which is an attempt of porting `pyboard.py`. The port has its [own repository](https://github.com/murilopolese/micropython.js) but for the sake of simplicity and transparency, `micropython.js` is committed as source code.
All operations over serial are abstracted and packaged on `/micropython.js` which is an attempt of porting `pyboard.py`. The port has its [own repository](https://github.com/arduino/micropython.js) but for the sake of simplicity and transparency, `micropython.js` is committed as source code.

The User Interface (UI) source code stays inside `/ui` folder and is completely independent of the Electron code.

Expand All @@ -39,7 +39,6 @@ At the root of the repository you will find:
- `/scripts`: Scripts executed during the build process.
- `/ui`: Available user interfaces.
- `/index.js`: Main Electron code.
- `/micropython.js`: Serial connection abstraction.
- `/preload.js`: Creates Disk and Serial APIs on Electron's main process and exposes it to Electron's renderer process (context bridge).

## Arduino UI
Expand Down Expand Up @@ -82,4 +81,3 @@ Some changes on the Electron code will require reopening the app but all UI chan
## Disclaimer

This software is provided “as is” and we make no express or implied warranties whatsoever with respect to its functionality, operability, or use, including, without limitation, any implied warranties of merchantability, fitness for a particular purpose, or infringement. We expressly disclaim any liability whatsoever for any direct, indirect, consequential, incidental or special damages, including, without limitation, lost revenues, lost profits, losses resulting from business interruption or loss of data, regardless of the form of action or legal theory under which the liability may be asserted, even if advised of the possibility or likelihood of such damages.

25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ function listFolder(folder) {
return files
}

function ilistFolder(folder, filesOnly) {
let files = fs.readdirSync(path.resolve(folder))
files = files.map(f => {
let filePath = path.resolve(folder, f)
return {
path: f,
type: fs.lstatSync(filePath).isDirectory() ? 'folder' : 'file'
}
})
// Filter out directories
if (filesOnly) {
files = files.filter(f => f.type === 'file')
}
// Filter out dot files
files = files.filter(f => f.path.indexOf('.') !== 0)
return files
}


// LOCAL FILE SYSTEM ACCESS
ipcMain.handle('open-folder', async (event) => {
console.log('ipcMain', 'open-folder')
Expand All @@ -39,6 +58,12 @@ ipcMain.handle('list-files', async (event, folder) => {
return listFolder(folder)
})

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

ipcMain.handle('load-file', (event, folder, filename) => {
console.log('ipcMain', 'load-file', folder, filename )
let filePath = path.resolve(folder, filename)
Expand Down
Loading

0 comments on commit 44bd0f6

Please sign in to comment.