@pmate/cli 0.42.3 → 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.
@@ -8,6 +8,7 @@ function validApplicationUrl(raw) {
8
8
 
9
9
  function installDesktopApps({ ipcMain, BrowserWindow, session, config, installNavigationRestrictions, openExternal, trusted }) {
10
10
  const children = new Set()
11
+ const microphoneOrigins = new Map()
11
12
  ipcMain.handle('pmate:app:open', async (event, raw) => {
12
13
  if (!trusted(event)) throw new Error('Untrusted app sender')
13
14
  const target = validApplicationUrl(raw)
@@ -21,7 +22,8 @@ function installDesktopApps({ ipcMain, BrowserWindow, session, config, installNa
21
22
  webPreferences: { session, nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true },
22
23
  })
23
24
  children.add(child)
24
- child.on('closed', () => children.delete(child))
25
+ microphoneOrigins.set(child.webContents, target.origin)
26
+ child.on('closed', () => { children.delete(child); microphoneOrigins.delete(child.webContents) })
25
27
  // The child application owns its own document links. Keep shared authentication
26
28
  // origins available in Electron, without inheriting Merry's external-link policy.
27
29
  installNavigationRestrictions(child, { ...config, origin: target.origin, externalOrigins: [] }, openExternal)
@@ -33,7 +35,15 @@ function installDesktopApps({ ipcMain, BrowserWindow, session, config, installNa
33
35
  throw error
34
36
  }
35
37
  })
36
- return { close: () => { for (const child of children) child.close(); children.clear() } }
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
+ }
37
47
  }
38
48
 
39
49
  module.exports = { installDesktopApps, validApplicationUrl }
@@ -38,7 +38,7 @@ else {
38
38
  }
39
39
  return desktopSession.fetch(request, { bypassCustomProtocolHandlers: true })
40
40
  })
41
- 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 })
42
42
  ipcMain.handle('pmate:screen-settings', event => {
43
43
  if (!mainWindow || event.sender !== mainWindow.webContents || event.senderFrame !== mainWindow.webContents.mainFrame || new URL(mainWindow.webContents.getURL()).origin !== config.origin) return false
44
44
  if (process.platform === 'darwin') { void shell.openExternal('x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture'); return true }
@@ -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 && (permission === 'display-capture' || (permission === 'media' && details.mediaTypes?.length && details.mediaTypes.every(type => type === 'audio')))))
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 && (permission === 'display-capture' || (permission === 'media' && details.mediaType === 'audio')))
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.42.3",
3
+ "version": "0.42.4",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {