From 6bcbf1e1f241016b4b8d7d54083d536e73adb11c Mon Sep 17 00:00:00 2001 From: meetqy Date: Mon, 19 Jun 2023 15:43:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=89=98=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #224 --- apps/electron/main/index.ts | 28 +++++++++-------------- apps/electron/main/src/createWebServer.ts | 5 +++- apps/electron/main/src/menu.ts | 1 - turbo.json | 4 ++-- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/apps/electron/main/index.ts b/apps/electron/main/index.ts index a58a9df3..acfc5f3c 100644 --- a/apps/electron/main/index.ts +++ b/apps/electron/main/index.ts @@ -1,4 +1,4 @@ -import { Menu, MenuItem, app, ipcMain, nativeTheme, shell, type IpcMain, type Tray } from "electron"; +import { app, ipcMain, nativeTheme, shell, type IpcMain, type Tray } from "electron"; import "./security-restrictions"; import type cp from "child_process"; @@ -40,17 +40,11 @@ app.disableHardwareAcceleration(); * Shout down background process if all windows was closed */ app.on("window-all-closed", () => { - console.log("window-all-closed"); if (process.platform !== "darwin") { app.quit(); } }); -// app.on("will-quit", (e) => { -// e.preventDefault(); -// app.hide(); -// }); - app.on("quit", () => { closeAssetsServer(); nextjsWebChild?.kill(); @@ -70,8 +64,10 @@ app.on("activate", () => { }); let tray: Tray; -// create menu +// 创建菜单 createMenu(); +// 隐藏 docker +app.dock.hide(); /** * Create the application window when the background process is ready. @@ -80,9 +76,15 @@ app .whenReady() .then(() => { restoreOrCreateWindow() - .then(() => { + .then(async () => { // 托盘图标 tray = createTray(); + + // 创建 Web/Assets 服务 + nextjsWebChild = await createWebServer(); + if (!nextjsWebChild) { + throw Error("NextJS child process was not created, exiting..."); + } }) .catch((err) => { throw err; @@ -165,12 +167,4 @@ async function resolveIPCResponse(opts: IPCRequestOptions) { app.on("ready", () => { createIPCHandler({ ipcMain }); - - void (async () => { - nextjsWebChild = await createWebServer(); - - if (!nextjsWebChild) { - throw Error("NextJS child process was not created, exiting..."); - } - })(); }); diff --git a/apps/electron/main/src/createWebServer.ts b/apps/electron/main/src/createWebServer.ts index 4a7db3ec..c370fbc5 100644 --- a/apps/electron/main/src/createWebServer.ts +++ b/apps/electron/main/src/createWebServer.ts @@ -6,6 +6,9 @@ import ip from "ip"; import { createSqlite } from "@acme/db"; +/** + * 创建 Web/Assets 服务 + */ export const createWebServer = async (preNextChild?: cp.ChildProcess) => { let nextjsChild: cp.ChildProcess; @@ -20,7 +23,7 @@ export const createWebServer = async (preNextChild?: cp.ChildProcess) => { process.env["WEB_PORT"] = _web_port; process.env["ASSETS_PORT"] = _assets_port; - if (app.isPackaged) { + if (isPackaged) { preNextChild?.kill(); // app config production // dev 在 watchDesktop.ts 中指定 diff --git a/apps/electron/main/src/menu.ts b/apps/electron/main/src/menu.ts index 7476ee04..a72c432d 100644 --- a/apps/electron/main/src/menu.ts +++ b/apps/electron/main/src/menu.ts @@ -18,7 +18,6 @@ const createMenu = () => { ], }, ]); - Menu.setApplicationMenu(menu); }; diff --git a/turbo.json b/turbo.json index 13eed56d..2ea8ef11 100644 --- a/turbo.json +++ b/turbo.json @@ -2,13 +2,13 @@ "$schema": "https://turborepo.org/schema.json", "globalDependencies": ["**/.env"], "pipeline": { - "db:reset": { "inputs": ["prisma/schema.prisma"] }, + "db:reset": { "inputs": ["prisma/schema.prisma"], "cache": false }, "dev": { "persistent": true, "cache": false }, "build": { - "outputs": ["./.next/standalone/**", "!.next/cache/**", "electron/**/dist/**"], + "outputs": ["nextjs/.next/standalone", "!nextjs/.next/cache", "electron/**/dist"], "dependsOn": ["^build"] }, "compile": {