diff --git a/.gitignore b/.gitignore index 21f1ff6..4ec7f25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ package-lock.json -node_modules/* \ No newline at end of file +node_modules/* +out/* \ No newline at end of file diff --git a/forge.config.js b/forge.config.js index fa4a113..573de68 100644 --- a/forge.config.js +++ b/forge.config.js @@ -4,6 +4,11 @@ const { FuseV1Options, FuseVersion } = require('@electron/fuses'); module.exports = { packagerConfig: { asar: true, + icon: 'iyuu.png', + extraResource: [ + 'run/', + 'iyuu/' + ] }, rebuildConfig: {}, makers: [ diff --git a/iyuu b/iyuu index 64e149b..f7eed46 160000 --- a/iyuu +++ b/iyuu @@ -1 +1 @@ -Subproject commit 64e149b2debcf38fe0b8c8d6003cf5e71dedf1e7 +Subproject commit f7eed461a0d812a3b5c1adb96047a09021d87857 diff --git a/iyuu.png b/iyuu.png new file mode 100644 index 0000000..1904a7d Binary files /dev/null and b/iyuu.png differ diff --git a/main.js b/main.js index 43ee731..412d1f5 100644 --- a/main.js +++ b/main.js @@ -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', () => { diff --git a/package.json b/package.json index 1fae29d..c8c82ba 100644 --- a/package.json +++ b/package.json @@ -32,4 +32,4 @@ "electron-squirrel-startup": "^1.0.1", "tree-kill": "^1.2.2" } -} +} \ No newline at end of file diff --git a/server/server.js b/server/server.js index 9cd9556..82315a5 100644 --- a/server/server.js +++ b/server/server.js @@ -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); }); }