This commit is contained in:
2025-09-30 17:16:11 +08:00
parent e650a7c7f3
commit 52ce0e1969
25 changed files with 689 additions and 989 deletions

View File

@@ -57,26 +57,43 @@ function getJavaExecutablePath(): string {
return 'java';
}
function findJarFile(directory: string): string {
if (!existsSync(directory)) return '';
const files = require('fs').readdirSync(directory);
const jarFile = files.find((f: string) => f.startsWith('erp_client_sb-') && f.endsWith('.jar'));
return jarFile ? join(directory, jarFile) : '';
}
function extractVersionFromJar(jarPath: string): string {
if (!jarPath) return '';
const match = require('path').basename(jarPath).match(/erp_client_sb-(\d+\.\d+\.\d+)\.jar/);
return match?.[1] || '';
}
function getJarFilePath(): string {
if (process.env.NODE_ENV === 'development') {
return join(__dirname, '../../public/erp_client_sb-2.4.7.jar');
return findJarFile(join(__dirname, '../../public'));
}
// 生产环境需要将JAR包从asar提取到临时位置
const tempDir = join(app.getPath('temp'), 'erp-client');
const tempJarPath = join(tempDir, 'erp_client_sb-2.4.7.jar');
if (!existsSync(tempDir)) mkdirSync(tempDir, { recursive: true });
// 确保临时目录存在
if (!existsSync(tempDir)) {
mkdirSync(tempDir, { recursive: true });
const asarJarPath = findJarFile(join(__dirname, '../assets'));
if (!asarJarPath) return '';
const asarFileName = require('path').basename(asarJarPath);
const tempJarPath = join(tempDir, asarFileName);
// 如果临时目录版本不同,删除旧版本并复制新版本
const existingJar = findJarFile(tempDir);
if (existingJar && require('path').basename(existingJar) !== asarFileName) {
require('fs').unlinkSync(existingJar);
}
// 如果临时JAR不存在从asar中复制
if (!existsSync(tempJarPath)) {
const asarJarPath = join(__dirname, '../assets/erp_client_sb-2.4.7.jar');
if (existsSync(asarJarPath)) {
copyFileSync(asarJarPath, tempJarPath);
}
copyFileSync(asarJarPath, tempJarPath);
}
return tempJarPath;
@@ -213,7 +230,7 @@ function startSpringBoot() {
}
}
//startSpringBoot();
startSpringBoot();
function stopSpringBoot() {
if (!springProcess) return;
@@ -299,9 +316,9 @@ app.whenReady().then(() => {
}
//11111
setTimeout(() => {
openAppIfNotOpened();
}, 2000);
// setTimeout(() => {
// openAppIfNotOpened();
// }, 2000);
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
@@ -323,6 +340,8 @@ ipcMain.on('message', (event, message) => {
console.log(message);
});
ipcMain.handle('get-jar-version', () => extractVersionFromJar(getJarFilePath()));
function checkPendingUpdate() {
try {
const updateFilePath = join(process.resourcesPath, 'app.asar.update');