Skip to content

Commit

Permalink
feat: 🎸 系统托盘
Browse files Browse the repository at this point in the history
Closes: #224
  • Loading branch information
meetqy committed Jun 19, 2023
1 parent 07af740 commit 6bcbf1e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
28 changes: 11 additions & 17 deletions apps/electron/main/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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();
Expand All @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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...");
}
})();
});
5 changes: 4 additions & 1 deletion apps/electron/main/src/createWebServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 中指定
Expand Down
1 change: 0 additions & 1 deletion apps/electron/main/src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const createMenu = () => {
],
},
]);

Menu.setApplicationMenu(menu);
};

Expand Down
4 changes: 2 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 6bcbf1e

Please sign in to comment.