@pmate/cli 0.35.10 → 0.35.12
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { app, BrowserWindow, session, shell, Menu, desktopCapturer, ipcMain, Notification, dialog } = require('electron')
|
|
2
2
|
const path = require('node:path')
|
|
3
|
+
const { installNotificationSettings } = require('./notification-settings.cjs')
|
|
3
4
|
const { createResourceHandler } = require('./resources.cjs')
|
|
4
5
|
const { installMediaPermissions } = require('./media.cjs')
|
|
5
6
|
const { createDesktopNotifications } = require('./notifications.cjs')
|
|
@@ -30,7 +31,7 @@ function restrict(window) {
|
|
|
30
31
|
window.webContents.on('did-create-window', child => restrict(child))
|
|
31
32
|
}
|
|
32
33
|
function createWindow() {
|
|
33
|
-
mainWindow = new BrowserWindow({ width: 1180, height: 820, minWidth: 380, minHeight: 540, title: config.productName, backgroundColor: '#f6f8fb', webPreferences: { preload: path.join(__dirname, 'preload.cjs'), partition: 'persist:desktop', nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true } })
|
|
34
|
+
mainWindow = new BrowserWindow({ width: 1180, height: 820, minWidth: 380, minHeight: 540, title: config.productName, backgroundColor: '#f6f8fb', webPreferences: { additionalArguments: [`--pmate-app-version=${app.getVersion()}`], preload: path.join(__dirname, 'preload.cjs'), partition: 'persist:desktop', nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true } })
|
|
34
35
|
restrict(mainWindow)
|
|
35
36
|
mainWindow.webContents.on('did-start-navigation', (_event, _url, _inPlace, mainFrame) => { if (mainFrame) desktopNotifications?.clearContext() })
|
|
36
37
|
mainWindow.webContents.on('did-fail-load', (_event, code, _description, url, mainFrame) => {
|
|
@@ -58,6 +59,7 @@ else {
|
|
|
58
59
|
if (process.platform === 'darwin') { void shell.openExternal('x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture'); return true }
|
|
59
60
|
return false
|
|
60
61
|
})
|
|
62
|
+
installNotificationSettings({ ipcMain, shell, origin: config.origin, getWindow: () => mainWindow })
|
|
61
63
|
Menu.setApplicationMenu(Menu.buildFromTemplate([
|
|
62
64
|
{ role: 'appMenu' }, { role: 'editMenu' }, { role: 'viewMenu' }, { role: 'windowMenu' },
|
|
63
65
|
{ label: config.productName, submenu: [{ label: 'Back to app', click: () => { if (!mainWindow) createWindow(); else void mainWindow.loadURL(config.origin) } }] },
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function installNotificationSettings({ ipcMain, shell, origin, getWindow, platform = process.platform }) {
|
|
2
|
+
ipcMain.handle('pmate:notification:settings', async event => {
|
|
3
|
+
const window = getWindow()
|
|
4
|
+
if (!window || event.sender !== window.webContents || event.senderFrame !== window.webContents.mainFrame || new URL(event.senderFrame.url).origin !== origin) throw new Error('Untrusted settings sender')
|
|
5
|
+
const url = platform === 'darwin' ? 'x-apple.systempreferences:com.apple.Notifications-Settings.extension'
|
|
6
|
+
: platform === 'win32' ? 'ms-settings:notifications' : undefined
|
|
7
|
+
if (!url) return false
|
|
8
|
+
await shell.openExternal(url)
|
|
9
|
+
return true
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
module.exports = { installNotificationSettings }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Main-process presentation boundary. Only the configured app's top frame may invoke it.
|
|
2
|
-
function createDesktopNotifications({ ipcMain, Notification, origin, appId, getWindow, showWindow, now = Date.now }) {
|
|
2
|
+
function createDesktopNotifications({ ipcMain, Notification, origin, appId, getWindow, showWindow, now = Date.now, platform = process.platform }) {
|
|
3
3
|
let activeThreadId, pendingOpen, epoch = 0
|
|
4
4
|
const shown = new Map()
|
|
5
5
|
const pending = new Map()
|
|
@@ -34,7 +34,7 @@ function createDesktopNotifications({ ipcMain, Notification, origin, appId, getW
|
|
|
34
34
|
}
|
|
35
35
|
if (input.threadId && input.threadId === activeThreadId && window && window.isVisible() && window.isFocused() && !window.isMinimized()) return 'suppressed'
|
|
36
36
|
if (!Notification.isSupported()) throw new Error('Desktop notifications unavailable')
|
|
37
|
-
const notification = new Notification({ title: input.title, body: input.body, silent: false })
|
|
37
|
+
const notification = new Notification({ title: input.title, body: input.body, silent: false, ...(platform === 'darwin' ? { sound: 'Ping' } : {}) })
|
|
38
38
|
const until = Math.min(input.expiresAtMs ?? now() + 86400000, now() + 86400000)
|
|
39
39
|
const presentationEpoch = epoch
|
|
40
40
|
const operation = new Promise((resolve, reject) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { contextBridge, ipcRenderer } = require('electron')
|
|
2
2
|
contextBridge.exposeInMainWorld('pmateDesktop', Object.freeze({
|
|
3
|
+
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 }),
|
|
3
4
|
openScreenSettings: () => ipcRenderer.invoke('pmate:screen-settings'),
|
|
4
5
|
reach: Object.freeze({
|
|
5
6
|
onEvent: handler => {
|
|
@@ -20,6 +21,7 @@ contextBridge.exposeInMainWorld('pmateDesktop', Object.freeze({
|
|
|
20
21
|
setPeople: people => ipcRenderer.invoke('pmate:call:people', people),
|
|
21
22
|
}),
|
|
22
23
|
notifications: Object.freeze({
|
|
24
|
+
openSettings: () => ipcRenderer.invoke('pmate:notification:settings'),
|
|
23
25
|
present: input => ipcRenderer.invoke('pmate:notification:present', input),
|
|
24
26
|
setActiveThread: threadId => ipcRenderer.invoke('pmate:notification:context', threadId),
|
|
25
27
|
onOpen: handler => {
|