@pmate/cli 0.44.0 → 0.44.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.
package/dist/index.js
CHANGED
|
@@ -18275,6 +18275,7 @@ var import_node_child_process9 = require("child_process");
|
|
|
18275
18275
|
var import_node_fs21 = require("fs");
|
|
18276
18276
|
var import_node_os10 = require("os");
|
|
18277
18277
|
var import_node_path26 = __toESM(require("path"));
|
|
18278
|
+
var import_sharp2 = __toESM(require("sharp"));
|
|
18278
18279
|
|
|
18279
18280
|
// src/desktopRelease.ts
|
|
18280
18281
|
init_sessionStore();
|
|
@@ -18335,6 +18336,11 @@ function readDesktopConfig(file, appId) {
|
|
|
18335
18336
|
if (c.externalOrigins !== void 0 && !Array.isArray(c.externalOrigins)) throw new Error("externalOrigins must be an array");
|
|
18336
18337
|
c.externalOrigins?.forEach(origin);
|
|
18337
18338
|
if (c.notaryProfile !== void 0 && (typeof c.notaryProfile !== "string" || !c.notaryProfile.trim())) throw new Error("Invalid notaryProfile");
|
|
18339
|
+
if (c.tray !== void 0) {
|
|
18340
|
+
if (!c.tray || typeof c.tray !== "object" || typeof c.tray.icon !== "string" || !c.tray.icon.trim()) throw new Error("Invalid desktop tray icon");
|
|
18341
|
+
if (c.tray.platforms !== void 0 && (!Array.isArray(c.tray.platforms) || !c.tray.platforms.length || c.tray.platforms.some((value) => !["mac", "win"].includes(value)))) throw new Error("Invalid desktop tray platforms");
|
|
18342
|
+
if (c.tray.closeToTray !== void 0 && typeof c.tray.closeToTray !== "boolean") throw new Error("Invalid desktop closeToTray");
|
|
18343
|
+
}
|
|
18338
18344
|
if ("web" in c) throw new Error("Remote desktop builds do not accept web build configuration; remove web");
|
|
18339
18345
|
return c;
|
|
18340
18346
|
}
|
|
@@ -18407,16 +18413,26 @@ async function runBuildCommand(command, cwd, env = process.env) {
|
|
|
18407
18413
|
child.once("exit", (code, signal) => code === 0 ? resolve() : reject(new Error(`${command[0]} failed (${signal ?? code})`)));
|
|
18408
18414
|
});
|
|
18409
18415
|
}
|
|
18416
|
+
async function renderTrayIcons(source, output) {
|
|
18417
|
+
const idle = await (0, import_sharp2.default)(source).resize(36, 36, { fit: "contain" }).png().toBuffer();
|
|
18418
|
+
const gap = Buffer.from('<svg width="36" height="36" xmlns="http://www.w3.org/2000/svg"><circle cx="30" cy="6" r="7" fill="#000"/></svg>');
|
|
18419
|
+
const dot = Buffer.from('<svg width="36" height="36" xmlns="http://www.w3.org/2000/svg"><circle cx="30" cy="6" r="5" fill="#000"/></svg>');
|
|
18420
|
+
await (0, import_sharp2.default)(idle).toFile(import_node_path26.default.join(output, "trayTemplate.png"));
|
|
18421
|
+
await (0, import_sharp2.default)(idle).composite([{ input: gap, blend: "dest-out" }, { input: dot }]).png().toFile(import_node_path26.default.join(output, "trayUnreadTemplate.png"));
|
|
18422
|
+
}
|
|
18410
18423
|
async function buildDesktop(args) {
|
|
18411
18424
|
const { file, output } = resolveDesktopPaths(args);
|
|
18412
18425
|
const c = readDesktopConfig(file, args.id);
|
|
18413
18426
|
const base = import_node_path26.default.dirname(file);
|
|
18414
18427
|
const icon = import_node_path26.default.resolve(base, c.icon);
|
|
18428
|
+
const tray = c.tray && (!c.tray.platforms || c.tray.platforms.includes(args.platform)) ? c.tray : void 0;
|
|
18429
|
+
const trayIcon = tray ? import_node_path26.default.resolve(base, tray.icon) : void 0;
|
|
18415
18430
|
const env = desktopBuildEnvironment(c);
|
|
18416
18431
|
if (!(0, import_node_fs21.existsSync)(icon) || !(0, import_node_fs21.statSync)(icon).isFile()) throw new Error(`Desktop icon not found: ${icon}`);
|
|
18432
|
+
if (trayIcon && (!(0, import_node_fs21.existsSync)(trayIcon) || !(0, import_node_fs21.statSync)(trayIcon).isFile())) throw new Error(`Desktop tray icon not found: ${trayIcon}`);
|
|
18417
18433
|
if (!["mac", "win"].includes(args.platform) || !["arm64", "x64"].includes(args.arch)) throw new Error("Supported target: mac|win --arch arm64|x64");
|
|
18418
18434
|
if (args.platform === "mac" && process.platform !== "darwin") throw new Error("macOS desktop packaging requires a macOS build host");
|
|
18419
|
-
const plan = { config: file, notaryProfile: env.APPLE_KEYCHAIN_PROFILE, app: c.app, productName: c.productName, version: c.version, target: "electron", platform: args.platform, arch: args.arch, contentSource: "remote", origin: c.origin, output, electron: ELECTRON_VERSION, builder: BUILDER_VERSION, signed: args.signed };
|
|
18435
|
+
const plan = { config: file, notaryProfile: env.APPLE_KEYCHAIN_PROFILE, app: c.app, productName: c.productName, version: c.version, target: "electron", platform: args.platform, arch: args.arch, contentSource: "remote", origin: c.origin, tray: !!tray, output, electron: ELECTRON_VERSION, builder: BUILDER_VERSION, signed: args.signed };
|
|
18420
18436
|
console.log(JSON.stringify({ phase: "plan", ...plan }, null, 2));
|
|
18421
18437
|
if (args.dryRun) return;
|
|
18422
18438
|
if (args.signed && args.platform === "mac") {
|
|
@@ -18429,7 +18445,8 @@ async function buildDesktop(args) {
|
|
|
18429
18445
|
(0, import_node_fs21.mkdirSync)(appDir);
|
|
18430
18446
|
const templateDir = import_node_path26.default.join(__dirname, "templates", "electron");
|
|
18431
18447
|
(0, import_node_fs21.cpSync)(templateDir, appDir, { recursive: true });
|
|
18432
|
-
|
|
18448
|
+
if (trayIcon) await renderTrayIcons(trayIcon, appDir);
|
|
18449
|
+
(0, import_node_fs21.writeFileSync)(import_node_path26.default.join(appDir, "desktop-config.json"), JSON.stringify({ app: c.app, productName: c.productName, origin: c.origin, authOrigins: c.authOrigins, externalOrigins: c.externalOrigins ?? [], bundleId: c.bundleId, ...tray ? { tray: { closeToTray: tray.closeToTray !== false } } : {} }));
|
|
18433
18450
|
(0, import_node_fs21.writeFileSync)(import_node_path26.default.join(appDir, "package.json"), JSON.stringify({ name: c.bundleId.replace(/\./g, "-"), version: c.version, description: `${c.productName} desktop application`, author: "PMate", main: "main.cjs", dependencies: { "@pmate/chat-sdk": "0.11.7", "electron-updater": "6.8.3" } }));
|
|
18434
18451
|
await runBuildCommand(["npm", "install", "--omit=dev", "--no-audit", "--no-fund"], appDir);
|
|
18435
18452
|
const cache = import_node_path26.default.join((0, import_node_os10.homedir)(), ".cache", "pmate", "electron", `${ELECTRON_VERSION}-${BUILDER_VERSION}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { createUpdateChecker, installUpdateHandlers } = require('./updates.cjs')
|
|
2
|
-
const { app, BrowserWindow, session, shell, Menu, desktopCapturer, ipcMain, Notification, dialog } = require('electron')
|
|
2
|
+
const { app, BrowserWindow, session, shell, Menu, Tray, nativeImage, desktopCapturer, ipcMain, Notification, dialog } = require('electron')
|
|
3
3
|
const path = require('node:path')
|
|
4
4
|
const { installNotificationSettings } = require('./notification-settings.cjs')
|
|
5
5
|
const { installMediaPermissions } = require('./media.cjs')
|
|
@@ -9,26 +9,35 @@ const { createRendererReach } = require('./reach-renderer.cjs')
|
|
|
9
9
|
const { createDesktopCalls, supportsDesktopCalls } = require('./calls.cjs')
|
|
10
10
|
const { installNavigationRestrictions } = require('./navigation.cjs')
|
|
11
11
|
const { installDesktopApps } = require('./apps.cjs')
|
|
12
|
+
const { createDesktopTray } = require('./tray.cjs')
|
|
12
13
|
const config = require('./desktop-config.json')
|
|
13
14
|
app.setName(config.productName)
|
|
14
15
|
if (process.platform === 'win32') app.setAppUserModelId(config.bundleId)
|
|
15
16
|
// Stable across installer versions; separate from every other packaged PMate app.
|
|
16
17
|
app.setPath('userData', path.join(app.getPath('appData'), config.bundleId))
|
|
17
18
|
let mainWindow
|
|
18
|
-
let desktopNotifications, desktopReach, desktopCalls, desktopApps
|
|
19
|
+
let desktopNotifications, desktopReach, desktopCalls, desktopApps, desktopTray
|
|
19
20
|
function createWindow() {
|
|
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 } })
|
|
21
|
+
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)}`, `--pmate-desktop-tray=${!!config.tray}`], preload: path.join(__dirname, 'preload.cjs'), partition: 'persist:desktop', nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true } })
|
|
21
22
|
installNavigationRestrictions(mainWindow, config, url => shell.openExternal(url))
|
|
22
23
|
mainWindow.webContents.on('did-start-navigation', (_event, _url, _inPlace, mainFrame) => { if (mainFrame) desktopNotifications?.clearContext() })
|
|
23
24
|
mainWindow.webContents.on('did-fail-load', (_event, code, _description, url, mainFrame) => {
|
|
24
25
|
if (mainFrame && code !== -3 && url !== `${config.origin}/_desktop/offline`) void mainWindow.loadURL(`${config.origin}/_desktop/offline`).catch(error => console.error("Offline page failed:", error.message))
|
|
25
26
|
})
|
|
26
27
|
void mainWindow.loadURL(config.origin).catch(error => console.error("Page load failed:", error.message))
|
|
28
|
+
mainWindow.on('close', event => { if (desktopTray?.shouldHideOnClose()) { event.preventDefault(); mainWindow.hide() } })
|
|
27
29
|
mainWindow.on('closed', () => { mainWindow = null })
|
|
30
|
+
return mainWindow
|
|
31
|
+
}
|
|
32
|
+
function showMainWindow() {
|
|
33
|
+
if (!mainWindow) createWindow()
|
|
34
|
+
if (mainWindow.isMinimized()) mainWindow.restore()
|
|
35
|
+
mainWindow.show(); mainWindow.focus()
|
|
36
|
+
return mainWindow
|
|
28
37
|
}
|
|
29
38
|
if (!app.requestSingleInstanceLock()) app.quit()
|
|
30
39
|
else {
|
|
31
|
-
app.on('second-instance',
|
|
40
|
+
app.on('second-instance', showMainWindow)
|
|
32
41
|
app.whenReady().then(() => {
|
|
33
42
|
const desktopSession = session.fromPartition('persist:desktop')
|
|
34
43
|
desktopSession.protocol.handle('https', request => {
|
|
@@ -47,16 +56,17 @@ else {
|
|
|
47
56
|
installNotificationSettings({ ipcMain, shell, origin: config.origin, getWindow: () => mainWindow })
|
|
48
57
|
let updateController
|
|
49
58
|
const checkForUpdates = createUpdateChecker({ app, dialog, shell, appId: config.app, getController: () => updateController })
|
|
59
|
+
if (config.tray) desktopTray = createDesktopTray({ Tray, Menu, nativeImage, iconPath: path.join(__dirname, 'trayTemplate.png'), unreadIconPath: path.join(__dirname, 'trayUnreadTemplate.png'),
|
|
60
|
+
productName: config.productName, getWindow: () => mainWindow, createWindow, checkForUpdates, quit: () => app.quit(), closeToTray: config.tray.closeToTray !== false })
|
|
50
61
|
Menu.setApplicationMenu(Menu.buildFromTemplate([
|
|
51
62
|
{ role: 'appMenu' }, { role: 'editMenu' }, { role: 'viewMenu' }, { role: 'windowMenu' },
|
|
52
63
|
{ label: config.productName, submenu: [{ label: '检查更新…', click: checkForUpdates }, { type: 'separator' }, { label: 'Back to app', click: () => { if (!mainWindow) createWindow(); else void mainWindow.loadURL(config.origin).catch(error => console.error("Page load failed:", error.message)) } }] },
|
|
53
64
|
]))
|
|
54
|
-
desktopNotifications = createDesktopNotifications({ ipcMain, Notification, origin: config.origin, appId: config.app, getWindow: () => mainWindow, showWindow:
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} })
|
|
65
|
+
desktopNotifications = createDesktopNotifications({ ipcMain, Notification, origin: config.origin, appId: config.app, getWindow: () => mainWindow, showWindow: showMainWindow })
|
|
66
|
+
if (desktopTray) ipcMain.handle('pmate:tray:unread', (event, count) => {
|
|
67
|
+
if (!desktopNotifications.trusted(event) || !Number.isSafeInteger(count) || count < 0 || count > 999999) throw new Error('Invalid tray unread count')
|
|
68
|
+
desktopTray.setUnread(count)
|
|
69
|
+
})
|
|
60
70
|
desktopApps = installDesktopApps({ ipcMain, BrowserWindow, session: desktopSession, config, installNavigationRestrictions,
|
|
61
71
|
openExternal: url => shell.openExternal(url), trusted: event => desktopNotifications.trusted(event) })
|
|
62
72
|
updateController = installUpdateHandlers({ ipcMain, app, shell, appId: config.app, trusted: event => desktopNotifications.trusted(event), updater: require('electron-updater').autoUpdater, getWindow: () => mainWindow })
|
|
@@ -89,9 +99,10 @@ else {
|
|
|
89
99
|
if (!desktopNotifications.trusted(event)) throw new Error('Untrusted reach sender')
|
|
90
100
|
desktopReach.stop(); desktopNotifications.reset()
|
|
91
101
|
})
|
|
92
|
-
app.on('before-quit', () => { desktopApps.close(); desktopReach.stop(); desktopNotifications.reset() })
|
|
102
|
+
app.on('before-quit', () => { desktopTray?.beginQuit(); desktopApps.close(); desktopReach.stop(); desktopNotifications.reset() })
|
|
103
|
+
app.on('will-quit', () => desktopTray?.destroy())
|
|
93
104
|
createWindow()
|
|
94
|
-
app.on('activate',
|
|
105
|
+
app.on('activate', showMainWindow)
|
|
95
106
|
}).catch(error => { console.error('Desktop startup failed:', error.message); app.exit(1) })
|
|
96
|
-
app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit() })
|
|
107
|
+
app.on('window-all-closed', () => { if (!config.tray && process.platform !== 'darwin') app.quit() })
|
|
97
108
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
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.3.0', contentSource: 'remote' }),
|
|
5
5
|
updates: Object.freeze({
|
|
6
6
|
check: () => ipcRenderer.invoke('pmate:update:check'),
|
|
7
7
|
download: () => ipcRenderer.invoke('pmate:update:download'),
|
|
@@ -15,6 +15,9 @@ if (process.isMainFrame && location.origin === origin) contextBridge.exposeInMai
|
|
|
15
15
|
apps: Object.freeze({
|
|
16
16
|
open: url => ipcRenderer.invoke('pmate:app:open', url),
|
|
17
17
|
}),
|
|
18
|
+
tray: process.argv.includes('--pmate-desktop-tray=true') ? Object.freeze({
|
|
19
|
+
setUnread: count => ipcRenderer.invoke('pmate:tray:unread', count),
|
|
20
|
+
}) : undefined,
|
|
18
21
|
reach: Object.freeze({
|
|
19
22
|
onEvent: handler => {
|
|
20
23
|
const listener = (_event, value) => {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function createDesktopTray({ Tray, Menu, nativeImage, iconPath, unreadIconPath, productName, platform = process.platform, getWindow, createWindow, checkForUpdates, quit, closeToTray = true }) {
|
|
2
|
+
const load = path => {
|
|
3
|
+
const source = nativeImage.createFromPath(path)
|
|
4
|
+
if (source.isEmpty()) throw new Error(`Invalid tray icon: ${path}`)
|
|
5
|
+
const image = source.resize({ width: 18, height: 18, quality: 'best' })
|
|
6
|
+
if (platform === 'darwin') image.setTemplateImage(true)
|
|
7
|
+
return image
|
|
8
|
+
}
|
|
9
|
+
const icons = { idle: load(iconPath), unread: load(unreadIconPath) }
|
|
10
|
+
const tray = new Tray(icons.idle)
|
|
11
|
+
let quitting = false
|
|
12
|
+
|
|
13
|
+
const show = () => {
|
|
14
|
+
const window = getWindow() ?? createWindow()
|
|
15
|
+
if (window.isMinimized()) window.restore()
|
|
16
|
+
window.show()
|
|
17
|
+
window.focus()
|
|
18
|
+
return window
|
|
19
|
+
}
|
|
20
|
+
const hide = () => getWindow()?.hide()
|
|
21
|
+
const toggle = () => {
|
|
22
|
+
const window = getWindow()
|
|
23
|
+
if (window?.isVisible()) hide()
|
|
24
|
+
else show()
|
|
25
|
+
}
|
|
26
|
+
const menu = () => Menu.buildFromTemplate([
|
|
27
|
+
{ label: `打开 ${productName}`, click: show },
|
|
28
|
+
{ label: `隐藏 ${productName}`, enabled: !!getWindow()?.isVisible(), click: hide },
|
|
29
|
+
{ type: 'separator' },
|
|
30
|
+
{ label: '检查更新…', click: checkForUpdates },
|
|
31
|
+
{ type: 'separator' },
|
|
32
|
+
{ label: `退出 ${productName}`, click: () => { quitting = true; quit() } },
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
tray.setToolTip(productName)
|
|
36
|
+
if (platform === 'darwin') tray.setIgnoreDoubleClickEvents(true)
|
|
37
|
+
tray.on('click', toggle)
|
|
38
|
+
tray.on('right-click', () => tray.popUpContextMenu(menu()))
|
|
39
|
+
return {
|
|
40
|
+
show,
|
|
41
|
+
hide,
|
|
42
|
+
setUnread(count) { tray.setImage(count > 0 ? icons.unread : icons.idle) },
|
|
43
|
+
shouldHideOnClose() { return closeToTray && !quitting },
|
|
44
|
+
beginQuit() { quitting = true },
|
|
45
|
+
destroy() { tray.destroy() },
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = { createDesktopTray }
|