feat: macos close

This commit is contained in:
mozzie 2024-08-12 09:36:55 +08:00
parent 5320a5846c
commit 6bf4ec52ec
3 changed files with 17 additions and 14 deletions

View File

@ -13,9 +13,12 @@ import { EVENT_PARSE_DICOM } from "./ipcEvent";
const registerIpcMainHandlers = (mainWindow: Electron.BrowserWindow | null) => {
if (!mainWindow) return;
ipcMain.handleOnce('ipc-loaded', () => {
mainWindow.show()
})
ipcMain.removeAllListeners();
/**
*
*/
ipcMain.on("ipc-loaded", () => mainWindow.show());
ipcMain.on(EVENT_PARSE_DICOM, async (event, file: string) => {
const dirDialog = await dialog.showOpenDialog(mainWindow, {
@ -31,8 +34,6 @@ const registerIpcMainHandlers = (mainWindow: Electron.BrowserWindow | null) => {
event.reply(EVENT_PARSE_DICOM + ":RES", result);
}
});
};
export default registerIpcMainHandlers;

View File

@ -27,12 +27,12 @@ process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL
let win: BrowserWindow | null;
let tray: Tray | null = null;
const theme: 'dark' | 'light' = 'dark'
const theme: "dark" | "light" = "dark";
const themeTitleBarStyles = {
dark: { color: "rgb(32,32,32)", symbolColor: '#fff' },
light: {}
}
dark: { color: "rgb(32,32,32)", symbolColor: "#fff" },
light: {},
};
function createWindow() {
win = new BrowserWindow({
@ -52,7 +52,7 @@ function createWindow() {
win.webContents.on("did-finish-load", () => {
win?.webContents.send("main-process-message", {
platform: process.platform === "darwin" ? "macos" : "windows",
theme
theme,
});
});
@ -61,10 +61,12 @@ function createWindow() {
} else {
win.loadFile(path.join(RENDERER_DIST, "index.html"));
}
registerIpcMainHandlers(win);
}
function createTray() {
if (tray) tray.destroy()
if (tray) tray.destroy();
const iconPath = path.join(process.env.VITE_PUBLIC, "AI.png"); // 使用 PNG 图标
const icon = nativeImage
.createFromPath(iconPath)
@ -98,6 +100,8 @@ function createTray() {
});
}
console.log(process.platform)
function registerGlobalShortcuts() {
// 注册全局快捷键 'CommandOrControl+Shift+S' 来显示应用窗口
globalShortcut.register("Option+N", () => {
@ -124,7 +128,6 @@ app.whenReady().then(() => {
createWindow();
createTray();
registerGlobalShortcuts();
registerIpcMainHandlers(win);
// 设置 Dock 图标
if (process.platform === "darwin") {
@ -137,5 +140,4 @@ app.whenReady().then(() => {
// 注销全局快捷键,当应用退出时
app.on("will-quit", () => {
globalShortcut.unregisterAll();
tray?.destroy()
});

View File

@ -9,7 +9,7 @@ function App() {
const theme = document.querySelector('html')!.getAttribute('theme') as 'dark' | 'light'
useEffect(() => {
window.ipcRenderer.invoke('ipc-loaded')
window.ipcRenderer.send('ipc-loaded')
}, [])
return (