@pmate/cli 0.36.0 → 0.36.1
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,4 +1,4 @@
|
|
|
1
|
-
const { createUpdateChecker } = require('./updates.cjs')
|
|
1
|
+
const { createUpdateChecker, installUpdateHandlers } = require('./updates.cjs')
|
|
2
2
|
const { app, BrowserWindow, session, shell, Menu, desktopCapturer, ipcMain, Notification, dialog } = require('electron')
|
|
3
3
|
const path = require('node:path')
|
|
4
4
|
const { installNotificationSettings } = require('./notification-settings.cjs')
|
|
@@ -72,6 +72,7 @@ else {
|
|
|
72
72
|
mainWindow.show(); mainWindow.focus()
|
|
73
73
|
return mainWindow
|
|
74
74
|
} })
|
|
75
|
+
installUpdateHandlers({ ipcMain, app, shell, appId: config.app, trusted: event => desktopNotifications.trusted(event) })
|
|
75
76
|
const instanceId = desktopInstanceId(app.getPath('userData'))
|
|
76
77
|
const rendererReach = createRendererReach({ ipcMain, getWindow: () => mainWindow, trusted: event => desktopNotifications.trusted(event) })
|
|
77
78
|
if (config.app === 'pmate:hello') desktopCalls = createDesktopCalls({ appId: config.app, instanceId, origin: config.origin, BrowserWindow, ipcMain, dialog })
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const { contextBridge, ipcRenderer } = require('electron')
|
|
2
2
|
contextBridge.exposeInMainWorld('pmateDesktop', Object.freeze({
|
|
3
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 }),
|
|
4
|
+
updates: Object.freeze({
|
|
5
|
+
check: () => ipcRenderer.invoke('pmate:update:check'),
|
|
6
|
+
download: () => ipcRenderer.invoke('pmate:update:download'),
|
|
7
|
+
}),
|
|
4
8
|
openScreenSettings: () => ipcRenderer.invoke('pmate:screen-settings'),
|
|
5
9
|
reach: Object.freeze({
|
|
6
10
|
onEvent: handler => {
|
|
@@ -48,4 +48,24 @@ function createUpdateChecker({ app, dialog, shell, appId, platform = process.pla
|
|
|
48
48
|
} finally { checking = false }
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
function installUpdateHandlers({ ipcMain, app, shell, appId, trusted, platform = process.platform, arch = process.arch, fetchImpl = fetch }) {
|
|
52
|
+
let checking
|
|
53
|
+
let available
|
|
54
|
+
ipcMain.handle('pmate:update:check', async event => {
|
|
55
|
+
if (!trusted(event)) throw new Error('Untrusted update sender')
|
|
56
|
+
if (!checking) {
|
|
57
|
+
available = undefined
|
|
58
|
+
checking = findUpdate({ appId, currentVersion: app.getVersion(), platform, arch, fetchImpl })
|
|
59
|
+
.then(update => { available = update; return update ? { version: update.version } : null })
|
|
60
|
+
.finally(() => { checking = undefined })
|
|
61
|
+
}
|
|
62
|
+
return checking
|
|
63
|
+
})
|
|
64
|
+
ipcMain.handle('pmate:update:download', async event => {
|
|
65
|
+
if (!trusted(event)) throw new Error('Untrusted update sender')
|
|
66
|
+
if (!available) throw new Error('Check for updates first')
|
|
67
|
+
await shell.openExternal(available.downloadUrl)
|
|
68
|
+
return true
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
module.exports = { compareVersions, findUpdate, createUpdateChecker, installUpdateHandlers }
|