Skip to content

Commit a4ffba4

Browse files
authored
Merge pull request #164 from arduino/feature/launch-pkg-installer
Add button to launch package installer
2 parents 83e7c5a + b81a84d commit a4ffba4

File tree

5 files changed

+84
-2
lines changed

5 files changed

+84
-2
lines changed

backend/ipc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs')
22
const registerMenu = require('./menu.js')
33
const serial = require('./serial/serial.js').sharedInstance
4+
const { shell } = require('electron');
45

56
const {
67
openFolderDialog,
@@ -138,6 +139,25 @@ module.exports = function registerIPCHandlers(win, ipcMain, app, dialog) {
138139
registerMenu(win, state)
139140
})
140141

142+
ipcMain.handle('launch-app', async (event, urlScheme) => {
143+
// Launch an external app with a custom protocol
144+
return new Promise((resolve, reject) => {
145+
try {
146+
shell.openExternal(urlScheme).then(() => {
147+
resolve(true); // App opened successfully
148+
}).catch(() => {
149+
resolve(false); // App not installed
150+
});
151+
} catch (err) {
152+
reject(err);
153+
}
154+
});
155+
});
156+
157+
ipcMain.handle('open-url', async (event, url) => {
158+
shell.openExternal(url);
159+
});
160+
141161
win.on('close', (event) => {
142162
console.log('BrowserWindow', 'close')
143163
event.preventDefault()

preload.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ console.log('preload')
22
const { contextBridge, ipcRenderer } = require('electron')
33
const path = require('path')
44
const shortcuts = require('./backend/shortcuts.js').shortcuts.global
5-
const { emit, platform } = require('process')
5+
const { platform } = require('process')
66
const SerialBridge = require('./backend/serial/serial-bridge.js')
77

88
const Disk = {
@@ -85,6 +85,21 @@ const Window = {
8585
getShortcuts: () => shortcuts
8686
}
8787

88+
/**
89+
* Launches an app using the provided URL scheme (e.g. myapp://). If the app is not installed, it will
90+
* fallback to open the provided fallback URL.
91+
* @param {string} url The URL scheme to use to launch the app
92+
* @param {string} fallbackUrl The URL to open if the app is not installed
93+
*/
94+
async function launchApp(url, fallbackUrl) {
95+
const success = await ipcRenderer.invoke('launch-app', url);
96+
97+
if (!success) {
98+
await ipcRenderer.invoke('open-url', fallbackUrl); // Fallback to open a URL in the default browser
99+
}
100+
}
101+
102+
contextBridge.exposeInMainWorld('launchApp', launchApp)
88103
contextBridge.exposeInMainWorld('BridgeSerial', SerialBridge)
89104
contextBridge.exposeInMainWorld('BridgeDisk', Disk)
90105
contextBridge.exposeInMainWorld('BridgeWindow', Window)

ui/arduino/media/install-package.svg

Lines changed: 33 additions & 0 deletions
Loading

ui/arduino/store.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ async function store(state, emitter) {
116116
updateMenu()
117117
})
118118

119+
emitter.on('launch-app', async (url, fallbackUrl) => {
120+
window.launchApp(url, fallbackUrl)
121+
})
122+
119123
// CONNECTION DIALOG
120124
emitter.on('open-connection-dialog', async () => {
121125
log('open-connection-dialog')

ui/arduino/views/components/toolbar.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ function Toolbar(state, emit) {
6969
disabled: !_canSave,
7070
onClick: () => emit('save')
7171
})}
72+
73+
${!window.BridgeWindow.isLinux() ? html`<div class="separator"></div>` : ''}
74+
75+
${!window.BridgeWindow.isLinux() ? Button({
76+
icon: 'install-package.svg',
77+
label: `Add Package`,
78+
onClick: () => {
79+
if(state.isConnected) emit('disconnect') // Package installer requires exclusive access to the serial port
80+
emit('launch-app', 'micropython-package-installer://', 'https://github.com/arduino/lab-micropython-package-installer/releases/latest')
81+
}
82+
}) : '' }
7283
</div>
7384
7485
<div id="app-views">
@@ -88,7 +99,6 @@ function Toolbar(state, emit) {
8899
square: true,
89100
onClick: () => emit('change-view', 'file-manager')
90101
})}
91-
92102
</div>
93103
</div>
94104
`

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy