打包完成

This commit is contained in:
萌森 2024-06-28 12:21:47 +08:00
parent e8aad4690c
commit 16de4f118e
7 changed files with 33 additions and 17 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
package-lock.json
node_modules/*
node_modules/*
out/*

View File

@ -4,6 +4,11 @@ const { FuseV1Options, FuseVersion } = require('@electron/fuses');
module.exports = {
packagerConfig: {
asar: true,
icon: 'iyuu.png',
extraResource: [
'run/',
'iyuu/'
]
},
rebuildConfig: {},
makers: [

2
iyuu

@ -1 +1 @@
Subproject commit 64e149b2debcf38fe0b8c8d6003cf5e71dedf1e7
Subproject commit f7eed461a0d812a3b5c1adb96047a09021d87857

BIN
iyuu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

13
main.js
View File

@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu } = require('electron')
const { app, BrowserWindow } = require('electron')
const path = require('node:path')
const server = require('./server/server');
@ -18,11 +18,14 @@ const createWindow = () => {
app.whenReady().then(() => {
server.startServer()
createWindow()
console.log("[About] 新疆萌森软件开发工作室提供技术支持");
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
setTimeout(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
}, 5000)
})
app.on('window-all-closed', () => {

View File

@ -32,4 +32,4 @@
"electron-squirrel-startup": "^1.0.1",
"tree-kill": "^1.2.2"
}
}
}

View File

@ -1,14 +1,15 @@
const { spawn } = require('child_process');
const os = require('os');
const fs = require('fs');
const path = require('path');
const treeKill = require('tree-kill');
function getCmdPath() {
function getCmdPath(resourcePath) {
const arch = os.arch();
if (arch === 'x64') {
return "./run/php-8.3.8-x64/php.exe";
return path.join(resourcePath, 'run', 'php-8.3.8-x64', 'php.exe');
} else if (arch === 'ia32') {
return "./run/php-8.3.8-x86/php.exe";
return path.join(resourcePath, 'run', 'php-8.3.8-x86', 'php.exe');
} else {
console.error("Unsupported architecture:", arch);
process.exit(1);
@ -18,9 +19,14 @@ function getCmdPath() {
let serverProcess = null;
function startServer() {
const cmdPath = getCmdPath();
const args = ['./iyuu/windows.php'];
const workingDirectory = path.resolve(__dirname, '..');
let resourcePath = process.resourcesPath;
if (resourcePath.includes('node_modules')) {
resourcePath = process.cwd();
}
const cmdPath = getCmdPath(resourcePath);
const args = [path.join(resourcePath, 'iyuu', 'windows.php')];
const workingDirectory = path.resolve(resourcePath);
const env = { ...process.env };
const phpDir = path.dirname(cmdPath);
@ -29,16 +35,17 @@ function startServer() {
serverProcess = spawn(cmdPath, args, {
cwd: workingDirectory,
stdio: ['inherit', 'pipe', 'inherit'],
env: env
env: env,
windowsHide: true
});
serverProcess.stdout.setEncoding('utf8');
serverProcess.stdout.on("data", function (data) {
console.log("启动服务器成功! stdout:" + data);
console.log("[IYUU] 服务启动成功");
});
serverProcess.on("close", function (code) {
console.log("out code:" + code);
console.log("[IYUU] 服务退出:" + code);
});
}