@pmate/cli 0.42.2 → 0.42.4
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,49 @@
|
|
|
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
|
+
const microphoneOrigins = new Map()
|
|
12
|
+
ipcMain.handle('pmate:app:open', async (event, raw) => {
|
|
13
|
+
if (!trusted(event)) throw new Error('Untrusted app sender')
|
|
14
|
+
const target = validApplicationUrl(raw)
|
|
15
|
+
const child = new BrowserWindow({
|
|
16
|
+
width: 1100,
|
|
17
|
+
height: 780,
|
|
18
|
+
minWidth: 380,
|
|
19
|
+
minHeight: 540,
|
|
20
|
+
title: config.productName,
|
|
21
|
+
autoHideMenuBar: true,
|
|
22
|
+
webPreferences: { session, nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true },
|
|
23
|
+
})
|
|
24
|
+
children.add(child)
|
|
25
|
+
microphoneOrigins.set(child.webContents, target.origin)
|
|
26
|
+
child.on('closed', () => { children.delete(child); microphoneOrigins.delete(child.webContents) })
|
|
27
|
+
// The child application owns its own document links. Keep shared authentication
|
|
28
|
+
// origins available in Electron, without inheriting Merry's external-link policy.
|
|
29
|
+
installNavigationRestrictions(child, { ...config, origin: target.origin, externalOrigins: [] }, openExternal)
|
|
30
|
+
try {
|
|
31
|
+
await child.loadURL(target.href)
|
|
32
|
+
return { opened: true }
|
|
33
|
+
} catch (error) {
|
|
34
|
+
child.close()
|
|
35
|
+
throw error
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
return {
|
|
39
|
+
getMicrophoneOrigin: contents => {
|
|
40
|
+
const expected = microphoneOrigins.get(contents)
|
|
41
|
+
if (!expected) return null
|
|
42
|
+
const child = [...children].find(window => !window.isDestroyed() && window.webContents === contents)
|
|
43
|
+
try { return child && new URL(contents.getURL()).origin === expected ? expected : null } catch { return null }
|
|
44
|
+
},
|
|
45
|
+
close: () => { for (const child of children) child.close(); children.clear(); microphoneOrigins.clear() },
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
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))
|
|
@@ -37,7 +38,7 @@ else {
|
|
|
37
38
|
}
|
|
38
39
|
return desktopSession.fetch(request, { bypassCustomProtocolHandlers: true })
|
|
39
40
|
})
|
|
40
|
-
installMediaPermissions(desktopSession, { origin: config.origin, getWindow: () => mainWindow, getWindows: () => [mainWindow, desktopCalls?.getWindow()], desktopCapturer, BrowserWindow, ipcMain })
|
|
41
|
+
installMediaPermissions(desktopSession, { origin: config.origin, getWindow: () => mainWindow, getWindows: () => [mainWindow, desktopCalls?.getWindow()], getMicrophoneOrigin: contents => desktopApps?.getMicrophoneOrigin(contents), desktopCapturer, BrowserWindow, ipcMain })
|
|
41
42
|
ipcMain.handle('pmate:screen-settings', event => {
|
|
42
43
|
if (!mainWindow || event.sender !== mainWindow.webContents || event.senderFrame !== mainWindow.webContents.mainFrame || new URL(mainWindow.webContents.getURL()).origin !== config.origin) return false
|
|
43
44
|
if (process.platform === 'darwin') { void shell.openExternal('x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture'); return true }
|
|
@@ -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,15 +1,21 @@
|
|
|
1
1
|
const { chooseScreen } = require('./share-picker.cjs')
|
|
2
|
-
function installMediaPermissions(desktopSession, { origin, getWindow, getWindows = () => [getWindow()], desktopCapturer, BrowserWindow, ipcMain }) {
|
|
2
|
+
function installMediaPermissions(desktopSession, { origin, getWindow, getWindows = () => [getWindow()], desktopCapturer, BrowserWindow, ipcMain, getMicrophoneOrigin = () => null }) {
|
|
3
3
|
const sameOrigin = raw => { try { return new URL(raw).origin === origin } catch { return false } }
|
|
4
4
|
const trusted = contents => {
|
|
5
5
|
return getWindows().some(window => !!window && !window.isDestroyed() && contents === window.webContents && sameOrigin(contents.getURL()))
|
|
6
6
|
}
|
|
7
|
+
const audioAllowed = (contents, raw, details) => {
|
|
8
|
+
if (details.isMainFrame !== true) return false
|
|
9
|
+
if (trusted(contents) && sameOrigin(raw)) return true
|
|
10
|
+
const expected = getMicrophoneOrigin(contents)
|
|
11
|
+
try { return !!expected && new URL(raw).origin === expected } catch { return false }
|
|
12
|
+
}
|
|
7
13
|
desktopSession.setPermissionRequestHandler((contents, permission, callback, details) => {
|
|
8
14
|
const allowed = trusted(contents) && details.isMainFrame === true && sameOrigin(details.requestingUrl)
|
|
9
|
-
callback(Boolean(allowed &&
|
|
15
|
+
callback(Boolean((allowed && permission === 'display-capture') || (permission === 'media' && audioAllowed(contents, details.requestingUrl, details) && details.mediaTypes?.length && details.mediaTypes.every(type => type === 'audio'))))
|
|
10
16
|
})
|
|
11
17
|
desktopSession.setPermissionCheckHandler((contents, permission, requestingOrigin, details) => {
|
|
12
|
-
return Boolean(trusted(contents) && sameOrigin(requestingOrigin) && details.isMainFrame === true &&
|
|
18
|
+
return Boolean((trusted(contents) && sameOrigin(requestingOrigin) && details.isMainFrame === true && permission === 'display-capture') || (permission === 'media' && details.mediaType === 'audio' && audioAllowed(contents, requestingOrigin, details)))
|
|
13
19
|
})
|
|
14
20
|
desktopSession.setDisplayMediaRequestHandler(async (request, callback) => {
|
|
15
21
|
const window = getWindows().find(window => window && !window.isDestroyed() && request.frame === window.webContents.mainFrame)
|
|
@@ -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.
|
|
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) => {
|