feat: update application icons and implement tray functionality

This commit is contained in:
Elysia
2026-01-31 16:37:51 +08:00
parent 0ed7f64a21
commit f89b9ebfd9
6 changed files with 64 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
<div align="center">
<img src="public/amber-pm-logo.png" alt="APM Logo" width="200" height="200" />
<img src="icons/amber-pm-logo.png" alt="APM Logo" width="200" height="200" />
**星火 APM 琥珀软件包管理器 - 桌面应用商店**

View File

@@ -10,9 +10,12 @@ files:
extraFiles:
- from: "extras"
to: "extras"
extraResources:
- from: "icons"
to: "icons"
linux:
icon: "public/amber-pm-logo.icns"
icon: "icons/amber-pm-logo.icns"
category: "System"
executableName: "apm-app-store"
desktop:

View File

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 124 KiB

View File

@@ -1,8 +1,9 @@
import { app, BrowserWindow, ipcMain, shell } from 'electron'
import { app, BrowserWindow, ipcMain, Menu, shell, Tray } from 'electron'
import { createRequire } from 'node:module'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import os from 'node:os'
import fs from 'node:fs'
import pino from 'pino'
import { handleCommandLine } from './deeplink.js'
import { isLoaded } from '../global.js'
@@ -93,6 +94,14 @@ async function createWindow() {
return { action: 'deny' }
})
// win.webContents.on('will-navigate', (event, url) => { }) #344
win.on('close', (event) => {
// 截获 close 默认行为
event.preventDefault();
// 点击关闭时触发close事件我们按照之前的思路在关闭时隐藏窗口隐藏任务栏窗口
win.hide();
win.setSkipTaskbar(true);
})
}
ipcMain.on('renderer-ready', (event, args) => {
@@ -128,6 +137,55 @@ app.on('activate', () => {
}
})
// 设置托盘
// 获取图标路径
function getIconPath() {
let iconPath = "";
const iconFile = process.platform === "win32" ? "amber-pm-logo.ico" : "amber-pm-logo.png"; // 图标文件名linux下需要png格式不然会不显示
// 判断是否在打包模式
if (app.isPackaged) {
// 打包模式
iconPath = path.join(process.resourcesPath, "icons", iconFile); // 路径根据自身情况调整
} else {
// 开发模式
const projectRoot = path.join(__dirname, "../.."); // __dirname 指向 dist-electron/main但资源在项目根目录所以..指向上一级
iconPath = path.join(projectRoot, "icons", iconFile);
}
// 检查文件是否存在
if (fs.existsSync(iconPath)) {
logger.info("图标文件存在:" + iconPath);
return iconPath;
} else {
logger.error("图标文件不存在:" + iconPath);
// 返回一个默认图标路径或null
return null;
}
}
let tray = null;
app.whenReady().then(() => {
tray = new Tray(getIconPath());
const contextMenu = Menu.buildFromTemplate([{
label: '显示主界面',
click: () => { win.show() }
},
{
label: '退出程序',
click: () => { win.destroy() }
}
]);
tray.setToolTip('APM 应用商店')
tray.setContextMenu(contextMenu)
// 双击触发
tray.on('click', () => {
// 双击通知区图标实现应用的显示或隐藏
win.isVisible() ? win.hide() : win.show()
win.isVisible() ? win.setSkipTaskbar(false) : win.setSkipTaskbar(true);
});
})
// New window example arg: new windows url
// ipcMain.handle('open-win', (_, arg) => {
// const childWindow = new BrowserWindow({

BIN
icons/amber-pm-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB