Skip to content

Commit dc06e4d

Browse files
committed
Refactor Electron Forge configuration and update batch script
- Updated `forge.config.js` to change application name to 'HotPE_Client', set platform to 'win32', and modify packaging options. - Removed unused plugins and configurations related to Fuses. - Enhanced `package.json` to include a new script for packaging with 7z and added an Electron mirror configuration. - Updated `update.bat` script to improve error handling, ensure administrator privileges, and streamline the update process. - Adjusted file paths and cleanup procedures in the update script for better reliability.
1 parent 18760cf commit dc06e4d

6 files changed

Lines changed: 99 additions & 136 deletions

File tree

bun.lock

Lines changed: 25 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

forge.config.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
2-
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
31

42
module.exports = {
53
packagerConfig: {
64
asar: true,
7-
name: 'HotPE Client',
5+
platform: "win32",
6+
name: 'HotPE_Client',
87
icon: './logo.ico',
9-
extraResource: ['./resources/'],
8+
extraResource: ['resources/tools'],
9+
ignore: ['src', 'resources'],
10+
win32metadata: {
11+
"requested-execution-level": "requireAdministrator"
12+
}
1013
},
1114
rebuildConfig: {},
1215
makers: [
13-
{
16+
/* {
1417
name: '@electron-forge/maker-zip',
1518
platforms: ['win32'],
16-
},
19+
}, */
1720
],
1821
plugins: [
1922
{
2023
name: '@electron-forge/plugin-vite',
2124
config: {
22-
// `build` can specify multiple entry points
2325
build: [
2426
{
25-
// `entry` is an alias for `build.lib.entry` in the corresponding file of `config`
2627
entry: 'src/main/index.ts',
2728
config: 'vite.main.config.ts',
2829
},
@@ -36,20 +37,5 @@ module.exports = {
3637
],
3738
},
3839
},
39-
{
40-
name: '@electron-forge/plugin-auto-unpack-natives',
41-
config: {},
42-
},
43-
// Fuses are used to enable/disable various Electron functionality
44-
// at package time, before code signing the application
45-
new FusesPlugin({
46-
version: FuseVersion.V1,
47-
[FuseV1Options.RunAsNode]: false,
48-
[FuseV1Options.EnableCookieEncryption]: true,
49-
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
50-
[FuseV1Options.EnableNodeCliInspectArguments]: false,
51-
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
52-
[FuseV1Options.OnlyLoadAppFromAsar]: true,
53-
}),
5440
],
5541
};

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
"scripts": {
77
"start": "electron-forge start",
88
"package": "electron-forge package",
9-
"make": "electron-forge make",
9+
"make": "electron-forge make --arch=ia32 && bun run pack-7z",
10+
"pack-7z": "cd out&&del HotPE_Client.7z&&.\\..\\resources\\tools\\7z\\7z.exe a -t7z -mx=9 HotPE_Client.7z -ir!HotPE_Client HotPE_Client-win32-ia32\\*",
1011
"publish": "electron-forge publish",
1112
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
1213
},
14+
"config": {
15+
"ELECTRON_MIRROR":"https://npmmirror.com/mirrors/electron/"
16+
},
1317
"dependencies": {
1418
"electron-is-dev": "^2.0.0",
15-
"electron-squirrel-startup": "^1.0.1",
1619
"iconv-lite": "^0.6.3",
1720
"ini": "^4.1.1",
1821
"react-markdown": "^8.0.7"
@@ -22,11 +25,8 @@
2225
"@douyinfe/semi-ui": "^2.51.3",
2326
"@electron-forge/cli": "^6.0.4",
2427
"@electron-forge/maker-zip": "^6.0.4",
25-
"@electron-forge/plugin-fuses": "^6.0.4",
2628
"@electron-forge/plugin-vite": "^6.0.4",
27-
"@electron/fuses": "^1.8.0",
2829
"@icon-park/react": "^1.4.2",
29-
"@types/copyfiles": "^2.4.1",
3030
"@types/ini": "^1.3.31",
3131
"@types/node": "^20.3.2",
3232
"@types/react": "^17.0.2",
@@ -36,7 +36,6 @@
3636
"@typescript-eslint/eslint-plugin": "^5.60.1",
3737
"@typescript-eslint/parser": "^5.60.1",
3838
"@vitejs/plugin-react-swc": "^3.3.2",
39-
"copyfiles": "^2.4.1",
4039
"electron": "^18.0.0",
4140
"eslint": "^8.43.0",
4241
"eslint-plugin-react-hooks": "^4.6.0",

resources/tools/7z/7z.dll

63 KB
Binary file not shown.

resources/tools/7z/7z.exe

18 KB
Binary file not shown.

resources/tools/update/update.bat

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,85 @@
1-
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
1+
@echo off
2+
:: 检查是否具有管理员权限,如果没有则请求提升权限
3+
net session >nul 2>&1
4+
if '%errorlevel%' NEQ '0' (
5+
powershell -Command "Start-Process '%~f0' -Verb RunAs"
6+
exit /b
7+
)
28

39
::{pack}为新客户端压缩包路径,{clientDir}为客户端路径:末带\
4-
@echo off
5-
chcp 65001
10+
chcp 65001 >nul
611
mode con cols=60 lines=20
712
color 03
813
cd /d "%~dp0"
914
title HotPE客户端更新中,请稍等...
10-
taskkill /IM "HotPE Client.exe" /F > tmp
11-
TIMEOUT /T 3
1215

16+
:: 终止可能正在运行的进程
17+
taskkill /IM "HotPE Client.exe" /F > nul 2>&1
18+
taskkill /IM "HotPE_Client.exe" /F > nul 2>&1
19+
TIMEOUT /T 3 /NOBREAK > nul
1320

21+
:: 如果是隐藏模式运行,则跳转到退出部分
1422
if "%1"=="h" GOTO exit
1523

1624
echo 释放文件
17-
mkdir "%~dp0updateTemp\" > tmp
18-
"%~dp07z.exe" x -y "-o%~dp0updateTemp\" "{pack}" > tmp
25+
mkdir "%~dp0updateTemp\" > nul 2>&1
26+
if not exist "%~dp0updateTemp\" (
27+
echo 创建临时目录失败
28+
goto :error
29+
)
30+
31+
"%~dp07z.exe" x -y "-o%~dp0updateTemp\" "{pack}" > nul 2>&1
32+
if errorlevel 1 (
33+
echo 解压更新包失败
34+
goto :error
35+
)
1936

2037
echo 清理旧文件
21-
::删除根目录所有文件,不包括文件夹
22-
del "{clientDir}*" /F /Q > tmp
23-
24-
rd "{clientDir}locales\" /S /Q > tmp
38+
:: 删除根目录所有文件,不包括文件夹
39+
del "{clientDir}*" /F /Q > nul 2>&1
2540

26-
del "{pack}" /F /Q > tmp
27-
del "{clientDir}resources\app.asar" /F /Q > tmp
28-
del "{clientDir}resources\app-update.yml" /F /Q > tmp
29-
del "{clientDir}resources\elevate.exe" /F /Q > tmp
30-
del "{clientDir}resources\config.json" /F /Q > tmp
41+
:: 删除子目录,使用更安全的方式检查目录是否存在再删除
42+
if exist "{clientDir}locales\" rd "{clientDir}locales\" /S /Q > nul 2>&1
43+
if exist "{clientDir}resources\app.asar" del "{clientDir}resources\app.asar" /F /Q > nul 2>&1
44+
if exist "{clientDir}resources\app-update.yml" del "{clientDir}resources\app-update.yml" /F /Q > nul 2>&1
45+
if exist "{clientDir}resources\elevate.exe" del "{clientDir}resources\elevate.exe" /F /Q > nul 2>&1
46+
if exist "{clientDir}resources\config.json" del "{clientDir}resources\config.json" /F /Q > nul 2>&1
47+
if exist "{clientDir}resources\tools\" rd "{clientDir}resources\tools\" /S /Q > nul 2>&1
3148

32-
rd "{clientDir}resources\tools\" /S /Q > tmp
49+
:: 删除更新包自身
50+
if exist "{pack}" del "{pack}" /F /Q > nul 2>&1
3351

3452
echo 替换文件
35-
xcopy "%~dp0updateTemp\HotPE_Client\*" "{clientDir}*" /E /C /Q /H /R /Y > tmp
53+
if not exist "%~dp0updateTemp\HotPE_Client\" (
54+
echo 更新包内缺少必要的文件
55+
goto :error
56+
)
3657

58+
xcopy "%~dp0updateTemp\HotPE_Client\*" "{clientDir}" /E /C /Q /H /R /Y > nul 2>&1
59+
if errorlevel 1 (
60+
echo 复制文件失败
61+
goto :error
62+
)
3763

3864
echo 清理退出
39-
rd "%~dp0updateTemp\" /S /Q > tmp
40-
::rd ".\7z\" /S /Q
41-
del "%~dp07z.exe" /F /Q > tmp
42-
del "%~dp07z.dll" /F /Q > tmp
65+
if exist "%~dp0updateTemp\" rd "%~dp0updateTemp\" /S /Q > nul 2>&1
66+
if exist "%~dp07z.exe" del "%~dp07z.exe" /F /Q > nul 2>&1
67+
if exist "%~dp07z.dll" del "%~dp07z.dll" /F /Q > nul 2>&1
68+
if exist "%~dp0tmp" del "%~dp0tmp" /F /Q > nul 2>&1
4369

44-
del "%~dp0tmp" /F /Q
45-
46-
::更新标记
70+
:: 创建更新标记
4771
echo. > "{clientDir}update.mark"
4872

49-
start mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
73+
:: 以隐藏模式重新启动此脚本以完成最终步骤
74+
powershell -Command "Start-Process -FilePath '%~f0' -ArgumentList 'h' -Verb RunAs -WindowStyle Hidden"
75+
exit /b
5076

51-
:exit
52-
cd /d "{clientDir}" && start /b cmd /c "{clientDir}HotPE Client.exe"
77+
:error
78+
echo 更新过程中发生错误
79+
pause
80+
exit /b
5381

54-
del %0 && exit
82+
:exit
83+
cd /d "{clientDir}" && start /b cmd /c "{clientDir}HotPE_Client.exe"
84+
del "%~f0" > nul 2>&1
85+
exit /b

0 commit comments

Comments
 (0)