@pmate/cli 0.42.2 → 0.42.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ function validApplicationUrl(raw) {
2
+ const url = new URL(raw)
3
+ const local = url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)
4
+ if (url.protocol !== 'https:' && !local) throw new Error('Application URL must use HTTPS')
5
+ if (url.username || url.password) throw new Error('Application URL cannot contain credentials')
6
+ return url
7
+ }
8
+
9
+ function installDesktopApps({ ipcMain, BrowserWindow, session, config, installNavigationRestrictions, openExternal, trusted }) {
10
+ const children = new Set()
11
+ ipcMain.handle('pmate:app:open', async (event, raw) => {
12
+ if (!trusted(event)) throw new Error('Untrusted app sender')
13
+ const target = validApplicationUrl(raw)
14
+ const child = new BrowserWindow({
15
+ width: 1100,
16
+ height: 780,
17
+ minWidth: 380,
18
+ minHeight: 540,
19
+ title: config.productName,
20
+ autoHideMenuBar: true,
21
+ webPreferences: { session, nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true },
22
+ })
23
+ children.add(child)
24
+ child.on('closed', () => children.delete(child))
25
+ // The child application owns its own document links. Keep shared authentication
26
+ // origins available in Electron, without inheriting Merry's external-link policy.
27
+ installNavigationRestrictions(child, { ...config, origin: target.origin, externalOrigins: [] }, openExternal)
28
+ try {
29
+ await child.loadURL(target.href)
30
+ return { opened: true }
31
+ } catch (error) {
32
+ child.close()
33
+ throw error
34
+ }
35
+ })
36
+ return { close: () => { for (const child of children) child.close(); children.clear() } }
37
+ }
38
+
39
+ module.exports = { installDesktopApps, validApplicationUrl }
@@ -8,13 +8,14 @@ const { desktopInstanceId, createDesktopReach } = require('./reach.cjs')
8
8
  const { createRendererReach } = require('./reach-renderer.cjs')
9
9
  const { createDesktopCalls, supportsDesktopCalls } = require('./calls.cjs')
10
10
  const { installNavigationRestrictions } = require('./navigation.cjs')
11
+ const { installDesktopApps } = require('./apps.cjs')
11
12
  const config = require('./desktop-config.json')
12
13
  app.setName(config.productName)
13
14
  if (process.platform === 'win32') app.setAppUserModelId(config.bundleId)
14
15
  // Stable across installer versions; separate from every other packaged PMate app.
15
16
  app.setPath('userData', path.join(app.getPath('appData'), config.bundleId))
16
17
  let mainWindow
17
- let desktopNotifications, desktopReach, desktopCalls
18
+ let desktopNotifications, desktopReach, desktopCalls, desktopApps
18
19
  function createWindow() {
19
20
  mainWindow = new BrowserWindow({ width: 1180, height: 820, minWidth: 380, minHeight: 540, title: config.productName, backgroundColor: '#f6f8fb', webPreferences: { additionalArguments: [`--pmate-app-version=${app.getVersion()}`, `--pmate-origin=${config.origin}`, `--pmate-desktop-calls=${supportsDesktopCalls(config.app)}`], preload: path.join(__dirname, 'preload.cjs'), partition: 'persist:desktop', nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true } })
20
21
  installNavigationRestrictions(mainWindow, config, url => shell.openExternal(url))
@@ -55,6 +56,8 @@ else {
55
56
  mainWindow.show(); mainWindow.focus()
56
57
  return mainWindow
57
58
  } })
59
+ desktopApps = installDesktopApps({ ipcMain, BrowserWindow, session: desktopSession, config, installNavigationRestrictions,
60
+ openExternal: url => shell.openExternal(url), trusted: event => desktopNotifications.trusted(event) })
58
61
  installUpdateHandlers({ ipcMain, app, shell, appId: config.app, trusted: event => desktopNotifications.trusted(event) })
59
62
  const instanceId = desktopInstanceId(app.getPath('userData'))
60
63
  const rendererReach = createRendererReach({ ipcMain, getWindow: () => mainWindow, trusted: event => desktopNotifications.trusted(event) })
@@ -85,7 +88,7 @@ else {
85
88
  if (!desktopNotifications.trusted(event)) throw new Error('Untrusted reach sender')
86
89
  desktopReach.stop(); desktopNotifications.reset()
87
90
  })
88
- app.on('before-quit', () => { desktopReach.stop(); desktopNotifications.reset() })
91
+ app.on('before-quit', () => { desktopApps.close(); desktopReach.stop(); desktopNotifications.reset() })
89
92
  createWindow()
90
93
  app.on('activate', () => { if (!mainWindow) createWindow() })
91
94
  }).catch(error => { console.error('Desktop startup failed:', error.message); app.exit(1) })
@@ -1,12 +1,15 @@
1
1
  const { contextBridge, ipcRenderer } = require('electron')
2
2
  const origin = process.argv.find(value => value.startsWith('--pmate-origin='))?.slice('--pmate-origin='.length)
3
3
  if (process.isMainFrame && location.origin === origin) contextBridge.exposeInMainWorld('pmateDesktop', Object.freeze({
4
- runtime: Object.freeze({ platform: process.platform, appVersion: process.argv.find(value => value.startsWith('--pmate-app-version='))?.slice('--pmate-app-version='.length), electronVersion: process.versions.electron, bridgeVersion: '1.0.0', contentSource: 'remote' }),
4
+ runtime: Object.freeze({ platform: process.platform, appVersion: process.argv.find(value => value.startsWith('--pmate-app-version='))?.slice('--pmate-app-version='.length), electronVersion: process.versions.electron, bridgeVersion: '1.1.0', contentSource: 'remote' }),
5
5
  updates: Object.freeze({
6
6
  check: () => ipcRenderer.invoke('pmate:update:check'),
7
7
  download: () => ipcRenderer.invoke('pmate:update:download'),
8
8
  }),
9
9
  openScreenSettings: () => ipcRenderer.invoke('pmate:screen-settings'),
10
+ apps: Object.freeze({
11
+ open: url => ipcRenderer.invoke('pmate:app:open', url),
12
+ }),
10
13
  reach: Object.freeze({
11
14
  onEvent: handler => {
12
15
  const listener = (_event, value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.42.2",
3
+ "version": "0.42.3",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {