Skip to content

Commit 0a1cbf3

Browse files
authored
Merge pull request #125 from arduino/development
v0.10.0
2 parents 2b560af + 86d4a18 commit 0a1cbf3

File tree

15 files changed

+254
-124
lines changed

15 files changed

+254
-124
lines changed

Diff for: .github/workflows/build.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ jobs:
2424
config:
2525
- os: windows-2019
2626
- os: ubuntu-latest
27-
- os: macos-latest
27+
- os: macos-13
28+
- os: macos-14
2829
runs-on: ${{ matrix.config.os }}
2930
timeout-minutes: 90
3031

@@ -99,6 +100,8 @@ jobs:
99100
name: Arduino-Lab-for-MicroPython_Linux_X86-64
100101
- path: "*-mac_x64.zip"
101102
name: Arduino-Lab-for-MicroPython_macOS_X86-64
103+
- path: "*-mac_arm64.zip"
104+
name: Arduino-Lab-for-MicroPython_macOS_arm-64
102105
# - path: "*Windows_64bit.exe"
103106
# name: Windows_X86-64_interactive_installer
104107
# - path: "*Windows_64bit.msi"

Diff for: backend/helpers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const path = require('path')
44

55
async function openFolderDialog(win) {
66
// https://stackoverflow.com/questions/46027287/electron-open-folder-dialog
7-
let dir = await dialog.showOpenDialog(win, { properties: [ 'openDirectory' ] })
7+
const dir = await dialog.showOpenDialog(win, { properties: [ 'openDirectory' ] })
88
return dir.filePaths[0] || null
99
}
1010

1111
function listFolder(folder) {
12-
files = fs.readdirSync(path.resolve(folder))
12+
let files = fs.readdirSync(path.resolve(folder))
1313
// Filter out directories
1414
files = files.filter(f => {
1515
let filePath = path.resolve(folder, f)
@@ -38,7 +38,7 @@ function ilistFolder(folder) {
3838

3939
function getAllFiles(dirPath, arrayOfFiles) {
4040
// https://coderrocketfuel.com/article/recursively-list-all-the-files-in-a-directory-using-node-js
41-
files = ilistFolder(dirPath)
41+
let files = ilistFolder(dirPath)
4242
arrayOfFiles = arrayOfFiles || []
4343
files.forEach(function(file) {
4444
const p = path.join(dirPath, file.path)

Diff for: backend/ipc.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
getAllFiles
77
} = require('./helpers.js')
88

9-
module.exports = function registerIPCHandlers(win, ipcMain) {
9+
module.exports = function registerIPCHandlers(win, ipcMain, app) {
1010
ipcMain.handle('open-folder', async (event) => {
1111
console.log('ipcMain', 'open-folder')
1212
const folder = await openFolderDialog(win)
@@ -107,4 +107,24 @@ module.exports = function registerIPCHandlers(win, ipcMain) {
107107

108108
win.setMinimumSize(minWidth, minHeight)
109109
})
110+
111+
ipcMain.handle('confirm-close', () => {
112+
console.log('ipcMain', 'confirm-close')
113+
app.exit()
114+
})
115+
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+
125+
win.on('close', (event) => {
126+
console.log('BrowserWindow', 'close')
127+
event.preventDefault()
128+
win.webContents.send('check-before-close')
129+
})
110130
}

Diff for: backend/menu.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const openAboutWindow = require('about-window').default
44

55
module.exports = function registerMenu(win) {
66
const isMac = process.platform === 'darwin'
7-
const isDev = !app.isPackaged
87
const template = [
98
...(isMac ? [{
109
label: app.name,
@@ -56,17 +55,13 @@ module.exports = function registerMenu(win) {
5655
label: 'View',
5756
submenu: [
5857
{ role: 'reload' },
58+
{ role: 'toggleDevTools' },
5959
{ type: 'separator' },
6060
{ role: 'resetZoom' },
6161
{ role: 'zoomIn' },
6262
{ role: 'zoomOut' },
6363
{ type: 'separator' },
6464
{ role: 'togglefullscreen' },
65-
...(isDev ? [
66-
{ type: 'separator' },
67-
{ role: 'toggleDevTools' },
68-
]:[
69-
])
7065
]
7166
},
7267
{

Diff for: index.js

+33-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const registerIPCHandlers = require('./backend/ipc.js')
66
const registerMenu = require('./backend/menu.js')
77

88
let win = null // main window
9+
let splash = null
10+
let splashTimestamp = null
911

1012
// START APP
1113
function createWindow () {
@@ -17,17 +19,42 @@ function createWindow () {
1719
nodeIntegration: false,
1820
webSecurity: true,
1921
enableRemoteModule: false,
20-
preload: path.join(__dirname, "preload.js")
22+
preload: path.join(__dirname, "preload.js"),
23+
show: false
2124
}
2225
})
2326
// and load the index.html of the app.
2427
win.loadFile('ui/arduino/index.html')
2528

26-
registerIPCHandlers(win, ipcMain)
27-
registerMenu(win)
28-
}
29+
// If the app takes a while to open, show splash screen
30+
// Create the splash screen
31+
splash = new BrowserWindow({
32+
width: 450,
33+
height: 140,
34+
transparent: true,
35+
frame: false,
36+
alwaysOnTop: true
37+
});
38+
splash.loadFile('ui/arduino/splash.html')
39+
splashTimestamp = Date.now()
40+
41+
win.once('ready-to-show', () => {
42+
if (Date.now()-splashTimestamp > 1000) {
43+
splash.destroy()
44+
} else {
45+
setTimeout(() => {
46+
splash.destroy()
47+
}, 500)
48+
}
49+
win.show()
50+
})
2951

52+
registerIPCHandlers(win, ipcMain, app)
53+
registerMenu(win)
3054

31-
// TODO: Loading splash screen
55+
app.on('activate', () => {
56+
if (BrowserWindow.getAllWindows().length === 0) createWindow()
57+
})
58+
}
3259

33-
app.whenReady().then(createWindow)
60+
app.on('ready', createWindow)

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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": {
88
"post-set-shell": "npm config set script-shell bash",
99
"rebuild": "electron-rebuild",
1010
"dev": "electron --inspect ./",
11-
"build": "npm run post-set-shell && electron-builder $(if [ $(uname -m) = arm64 ]; then echo --mac --x64; fi)",
11+
"build": "npm run post-set-shell && electron-builder",
1212
"postinstall": "npm run post-set-shell && npm run rebuild"
1313
},
1414
"devDependencies": {
@@ -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"

Diff for: preload.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const Serial = {
1313
return ports.filter(p => p.vendorId && p.productId)
1414
},
1515
connect: async (path) => {
16-
return await board.open(path)
16+
return board.open(path)
1717
},
1818
disconnect: async () => {
19-
return await board.close()
19+
return board.close()
2020
},
2121
run: async (code) => {
2222
return board.run(code)
@@ -145,15 +145,22 @@ 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

151154
const Window = {
152155
setWindowSize: (minWidth, minHeight) => {
153156
ipcRenderer.invoke('set-window-size', minWidth, minHeight)
154-
}
157+
},
158+
beforeClose: (callback) => ipcRenderer.on('check-before-close', callback),
159+
confirmClose: () => ipcRenderer.invoke('confirm-close'),
160+
isPackaged: () => ipcRenderer.invoke('is-packaged')
155161
}
156162

163+
157164
contextBridge.exposeInMainWorld('BridgeSerial', Serial)
158165
contextBridge.exposeInMainWorld('BridgeDisk', Disk)
159166
contextBridge.exposeInMainWorld('BridgeWindow', Window)

Diff for: ui/arduino/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<script type="text/javascript" src="views/components/repl-panel.js" charset="utf-8"></script>
3131
<script type="text/javascript" src="views/components/tabs.js" charset="utf-8"></script>
3232
<script type="text/javascript" src="views/components/toolbar.js" charset="utf-8"></script>
33+
<script type="text/javascript" src="views/components/overlay.js" charset="utf-8"></script>
3334

3435
<!-- Views -->
3536
<script type="text/javascript" src="views/editor.js" charset="utf-8"></script>

Diff for: ui/arduino/main.js

+18-17
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,26 @@ function App(state, emit) {
1919
`
2020
}
2121

22-
let overlay = html`<div id="overlay" class="closed"></div>`
23-
24-
if (state.diskFiles == null) {
25-
emit('load-disk-files')
26-
overlay = html`<div id="overlay" class="open"><p>Loading files...</p></div>`
22+
if (state.view == 'file-manager') {
23+
return html`
24+
<div id="app">
25+
${FileManagerView(state, emit)}
26+
${Overlay(state, emit)}
27+
</div>
28+
`
29+
} else {
30+
return html`
31+
<div id="app">
32+
${EditorView(state, emit)}
33+
${Overlay(state, emit)}
34+
</div>
35+
`
2736
}
28-
29-
if (state.isRemoving) overlay = html`<div id="overlay" class="open"><p>Removing...</p></div>`
30-
if (state.isConnecting) overlay = html`<div id="overlay" class="open"><p>Connecting...</p></div>`
31-
if (state.isLoadingFiles) overlay = html`<div id="overlay" class="open"><p>Loading files...</p></div>`
32-
if (state.isSaving) overlay = html`<div id="overlay" class="open"><p>Saving file... ${state.savingProgress}</p></div>`
33-
if (state.isTransferring) overlay = html`<div id="overlay" class="open"><p>Transferring file... ${state.transferringProgress}</p></div>`
34-
35-
const view = state.view == 'editor' ? EditorView(state, emit) : FileManagerView(state, emit)
3637
return html`
3738
<div id="app">
38-
${view}
39-
${overlay}
39+
${Overlay(state, emit)}
4040
</div>
4141
`
42-
4342
}
4443

4544
window.addEventListener('load', () => {
@@ -49,7 +48,9 @@ window.addEventListener('load', () => {
4948
app.mount('#app')
5049

5150
app.emitter.on('DOMContentLoaded', () => {
52-
app.emitter.emit('refresh-files')
51+
if (app.state.diskNavigationRoot) {
52+
app.emitter.emit('refresh-files')
53+
}
5354
})
5455

5556
})

Diff for: ui/arduino/splash.html

+21
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)