Skip to content

Commit 055140a

Browse files
committed
Add NSIS patching script and application icon
- Introduced a new script `patch-electron-builder-nsis.ts` to automate patching of NSIS templates for enhanced installer details output. - Added an application icon `icon.png` to the resources directory.
1 parent 2fafed4 commit 055140a

7 files changed

Lines changed: 79 additions & 14 deletions

File tree

dev/maimai-v2.jpg

219 KB
Loading

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "maibot-onekey-desktop",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Electron desktop shell for MaiBot OneKey.",
55
"license": "GPL-3.0-only",
66
"type": "module",
@@ -12,7 +12,8 @@
1212
"check": "bun run typecheck && bun run build",
1313
"preview": "electron-vite preview",
1414
"release:check": "bun run scripts/release/check-windows-payload.ts",
15-
"release:win": "bun run release:check && bun run build && electron-builder --win nsis --x64",
15+
"release:patch-nsis": "bun run scripts/release/patch-electron-builder-nsis.ts",
16+
"release:win": "bun run release:check && bun run release:patch-nsis && bun run build && electron-builder --win nsis --x64",
1617
"pack:win": "bun run release:win"
1718
},
1819
"dependencies": {
@@ -64,6 +65,10 @@
6465
"node_modules/node-addon-api/**"
6566
],
6667
"extraResources": [
68+
{
69+
"from": "resources/icon.png",
70+
"to": "icon.png"
71+
},
6772
{
6873
"from": "runtime",
6974
"to": "runtime",
@@ -87,9 +92,16 @@
8792
],
8893
"win": {
8994
"target": "nsis",
95+
"icon": "resources/icon.ico",
9096
"requestedExecutionLevel": "asInvoker",
9197
"artifactName": "${productName}-${version}-win-${arch}.${ext}"
9298
},
99+
"mac": {
100+
"icon": "resources/icon.icns"
101+
},
102+
"linux": {
103+
"icon": "resources/icon.png"
104+
},
93105
"nsis": {
94106
"oneClick": false,
95107
"perMachine": false,

resources/icon.icns

1.89 MB
Binary file not shown.

resources/icon.ico

137 KB
Binary file not shown.

resources/icon.png

1.08 MB
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { readFile, writeFile } from "node:fs/promises";
2+
import { join } from "node:path";
3+
4+
async function patchFile(
5+
path: string,
6+
patchName: string,
7+
pattern: RegExp,
8+
replacement: string,
9+
alreadyPatched: string,
10+
): Promise<void> {
11+
const content = await readFile(path, "utf8");
12+
if (content.includes(alreadyPatched)) {
13+
console.log(`[ok] ${patchName}: already patched`);
14+
return;
15+
}
16+
17+
if (!pattern.test(content)) {
18+
throw new Error(`${patchName}: expected template content was not found in ${path}`);
19+
}
20+
21+
await writeFile(path, content.replace(pattern, replacement), "utf8");
22+
console.log(`[ok] ${patchName}: patched`);
23+
}
24+
25+
const nsisTemplateRoot = join(process.cwd(), "node_modules", "app-builder-lib", "templates", "nsis");
26+
27+
await patchFile(
28+
join(nsisTemplateRoot, "installSection.nsh"),
29+
"enable NSIS details output",
30+
/(\$\{IfNot\} \$\{Silent\}\r?\n)\s*SetDetailsPrint none(\r?\n\$\{endif\})/u,
31+
"$1 SetDetailsPrint both$2",
32+
"SetDetailsPrint both",
33+
);
34+
35+
await patchFile(
36+
join(nsisTemplateRoot, "include", "extractAppPackage.nsh"),
37+
"show copied files in NSIS details",
38+
/CopyFiles \/SILENT "\$PLUGINSDIR\\7z-out\\\*" \$OUTDIR/u,
39+
'CopyFiles "$PLUGINSDIR\\7z-out\\*" $OUTDIR',
40+
'CopyFiles "$PLUGINSDIR\\7z-out\\*" $OUTDIR',
41+
);

src/main/index.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ let tray: Tray | null = null;
2121
let allowQuit = false;
2222
let quitRequested = false;
2323

24+
function createFallbackIcon(): Electron.NativeImage {
25+
return nativeImage.createFromDataURL(
26+
"data:image/svg+xml;utf8," +
27+
encodeURIComponent(
28+
`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
29+
<rect width="32" height="32" rx="7" fill="#245B3A"/>
30+
<path d="M9 20.5V11l7 6 7-6v9.5" fill="none" stroke="#F4FFF6" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
31+
<circle cx="11" cy="22" r="1.6" fill="#B7F0C4"/>
32+
<circle cx="21" cy="22" r="1.6" fill="#B7F0C4"/>
33+
</svg>`,
34+
),
35+
);
36+
}
37+
38+
function createAppIcon(): Electron.NativeImage {
39+
const iconPath = app.isPackaged
40+
? join(process.resourcesPath, "icon.png")
41+
: join(process.cwd(), "resources", "icon.png");
42+
const icon = nativeImage.createFromPath(iconPath);
43+
return icon.isEmpty() ? createFallbackIcon() : icon;
44+
}
45+
2446
function broadcastWindowState(window: BrowserWindow): void {
2547
if (window.isDestroyed()) {
2648
return;
@@ -43,6 +65,7 @@ function createMainWindow(): BrowserWindow {
4365
show: false,
4466
backgroundColor: "#f5f7f2",
4567
frame: false,
68+
icon: createAppIcon(),
4669
titleBarStyle: process.platform === "darwin" ? "hidden" : "default",
4770
trafficLightPosition: process.platform === "darwin" ? { x: -100, y: -100 } : undefined,
4871
webPreferences: {
@@ -129,18 +152,7 @@ function requestQuit(): void {
129152
}
130153

131154
function createTray(): Tray {
132-
const icon = nativeImage.createFromDataURL(
133-
"data:image/svg+xml;utf8," +
134-
encodeURIComponent(
135-
`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
136-
<rect width="32" height="32" rx="7" fill="#245B3A"/>
137-
<path d="M9 20.5V11l7 6 7-6v9.5" fill="none" stroke="#F4FFF6" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
138-
<circle cx="11" cy="22" r="1.6" fill="#B7F0C4"/>
139-
<circle cx="21" cy="22" r="1.6" fill="#B7F0C4"/>
140-
</svg>`,
141-
),
142-
);
143-
const nextTray = new Tray(icon);
155+
const nextTray = new Tray(createAppIcon().resize({ width: 32, height: 32 }));
144156

145157
const withLog =
146158
(action: () => Promise<unknown>) =>

0 commit comments

Comments
 (0)