From 2675b16ceefcf0303706502f41f4e939cb45160b Mon Sep 17 00:00:00 2001 From: nyomansutralia-jubelio Date: Mon, 25 Nov 2024 01:24:53 +0700 Subject: [PATCH] fix: setup server web --- apps/server-web/src/main/main.ts | 19 ++++++++++++------- package.json | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/server-web/src/main/main.ts b/apps/server-web/src/main/main.ts index 6558c75f3..2fdea3a4f 100644 --- a/apps/server-web/src/main/main.ts +++ b/apps/server-web/src/main/main.ts @@ -197,6 +197,8 @@ const createWindow = async (type: 'SETTING_WINDOW' | 'LOG_WINDOW' | 'SETUP_WINDO url = resolveHtmlPath('index.html', 'setup'); setupWindow?.loadURL(url); mainBindings(ipcMain, setupWindow, fs); + setupWindow?.setMenuBarVisibility(false); + Menu.setApplicationMenu(Menu.buildFromTemplate([])); setupWindow.on('closed', () => { setupWindow = null; }) @@ -267,11 +269,6 @@ const onInitApplication = () => { Menu.setApplicationMenu(appMenu.buildDefaultTemplate(appMenuItems, i18nextMainBackend)) } }, 250)); - eventEmitter.on(EventLists.webServerStart, async () => { - updateTrayMenu('SERVER_START', { enabled: false }, eventEmitter, tray, trayMenuItems, i18nextMainBackend); - isServerRun = true; - await runServer(); - }) eventEmitter.on(EventLists.webServerStop, async () => { await stopServer(); @@ -397,6 +394,7 @@ const onInitApplication = () => { eventEmitter.on(EventLists.SERVER_WINDOW, async () => { if (!logWindow) { + initTrayMenu() await createWindow('LOG_WINDOW'); } const serverSetting = LocalStore.getStore('config'); @@ -441,6 +439,15 @@ const initTrayMenu = () => { console.error('Failed to initialize application:', error); dialog.showErrorBox('Initialization Error', 'Failed to initialize application'); } + + eventEmitter.on(EventLists.webServerStart, async () => { + updateTrayMenu('SERVER_START', { enabled: false }, eventEmitter, tray, trayMenuItems, i18nextMainBackend); + isServerRun = true; + await runServer(); + }) + + trayMenuItems = trayMenuItems.length ? trayMenuItems : defaultTrayMenuItem(eventEmitter); + updateTrayMenu('none', {}, eventEmitter, tray, trayMenuItems, i18nextMainBackend); } (async () => { @@ -448,7 +455,6 @@ const initTrayMenu = () => { const storeConfig:WebServer = LocalStore.getStore('config'); onInitApplication(); if (storeConfig?.general?.setup) { - initTrayMenu() eventEmitter.emit(EventLists.SERVER_WINDOW); } else { if (!setupWindow) { @@ -500,7 +506,6 @@ ipcMain.on(IPC_TYPES.SETTING_PAGE, async (event, arg) => { } }); setupWindow?.close(); - onInitApplication(); eventEmitter.emit(EventLists.SERVER_WINDOW); } else { event.sender.send(IPC_TYPES.SETTING_PAGE, { diff --git a/package.json b/package.json index 4948aeb7a..e1d99a5f5 100644 --- a/package.json +++ b/package.json @@ -81,12 +81,13 @@ "spell": "cspell . --config .cspell.json", "spellcheck": "cspell .", "config:electron": "yarn ts-node ./.scripts/electron.env.ts", + "config:electron:web:build": "yarn ts-node ./.scripts/configure.electron.ts", "pack": "yarn ts-node .scripts/electron-package-utils/package-util.ts", "pack:server-web": "yarn run pack --desktop=server-web", "config:server-web": "yarn run config:electron -- --environment=prod --desktop=server-web", "dev:server-web": "cross-env NODE_ENV=production yarn prepare:config:server-web && yarn build:web:desktop && yarn run prepare:server-web && yarn copy:build:web && yarn run start:server-web", - "build:web:desktop": "cross-env NEXT_BUILD_OUTPUT_TYPE=standalone NEXT_SHARP_PATH=/temp/node_modules/sharp yarn build:web", - "copy:build:web": "pwd && cp -r apps/web/.next/standalone apps/server-web/release/app/dist && cp -r apps/web/.next/static apps/server-web/release/app/dist/standalone/apps/web/.next && cp -r apps/web/public apps/server-web/release/app/dist/standalone/apps/web/", + "build:web:desktop": "yarn config:electron:web:build -- --type=constant && cross-env NEXT_BUILD_OUTPUT_TYPE=standalone NEXT_SHARP_PATH=/tmp/node_modules/sharp yarn build:web", + "copy:build:web": "pwd && cp -r apps/web/.next/standalone apps/server-web/release/app/dist && cp -r apps/web/.next/static apps/server-web/release/app/dist/standalone/apps/web/.next && cp -r apps/web/public apps/server-web/release/app/dist/standalone/apps/web/ && yarn config:electron:web:build -- --type=server", "start:server-web": "cd apps/server-web && yarn run start", "prepare:server-web": "cd apps/server-web && yarn run prepare:electron && yarn run build", "pack:server-web:mac": "cd apps/server-web && yarn run pack:mac",