From febb105682620b24ebf473e4b20b9a20d85bc8a2 Mon Sep 17 00:00:00 2001 From: mozzie Date: Sun, 11 Aug 2024 21:02:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BB=E9=A2=98=E8=89=B2=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=9C=A8=E4=B8=BB=E8=BF=9B=E7=A8=8B=E4=B8=AD=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/ipcMainHandlers.ts | 4 ++++ electron/main.ts | 11 ++++++++++- src/App.tsx | 11 ++++++++--- src/components/theme-provider.tsx | 2 +- src/main.tsx | 3 ++- src/style/global.css | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/electron/ipcMainHandlers.ts b/electron/ipcMainHandlers.ts index 860edd4..c20e4ee 100644 --- a/electron/ipcMainHandlers.ts +++ b/electron/ipcMainHandlers.ts @@ -13,6 +13,10 @@ import { EVENT_PARSE_DICOM } from "./ipcEvent"; const registerIpcMainHandlers = (mainWindow: Electron.BrowserWindow | null) => { if (!mainWindow) return; + ipcMain.handleOnce('ipc-loaded', () => { + mainWindow.show() + }) + ipcMain.on(EVENT_PARSE_DICOM, async (event, file: string) => { const dirDialog = await dialog.showOpenDialog(mainWindow, { properties: ["openDirectory"], diff --git a/electron/main.ts b/electron/main.ts index d815339..9473007 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -27,14 +27,22 @@ process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL let win: BrowserWindow | null; let tray: Tray | null = null; +const theme: 'dark' | 'light' = 'dark' + +const themeTitleBarStyles = { + dark: { color: "rgb(32,32,32)", symbolColor: '#fff' }, + light: {} +} + function createWindow() { win = new BrowserWindow({ width: 1280, height: 800, + show: false, // 先隐藏。等待渲染完成,防止闪烁 icon: path.join(process.env.VITE_PUBLIC, "AI.png"), // frame: false, titleBarStyle: "hidden", // customButtonsOnHover || hidden || hiddenInset - titleBarOverlay: { height: 36, color: "rgb(32,32,32)",symbolColor:'#fff' }, // 渲染进程发消息动态改变这个 + titleBarOverlay: { height: 36, ...themeTitleBarStyles[theme] }, // 渲染进程发消息动态改变这个 webPreferences: { preload: path.join(__dirname, "preload.mjs"), }, @@ -44,6 +52,7 @@ function createWindow() { win.webContents.on("did-finish-load", () => { win?.webContents.send("main-process-message", { platform: process.platform === "darwin" ? "macos" : "windows", + theme }); }); diff --git a/src/App.tsx b/src/App.tsx index b438e99..ff438f2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,17 +2,22 @@ import { ThemeProvider } from "@/components/theme-provider"; import LayoutMain from "@/pages/Layout"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import Aorta from "@/pages/Aorta"; -import Dockview from "@/pages/Dock"; import { Setting } from "./pages/Setting"; +import { useEffect } from "react"; function App() { + const theme = document.querySelector('html')!.getAttribute('theme') as 'dark' | 'light' + + useEffect(() => { + window.ipcRenderer.invoke('ipc-loaded') + }, []) + return ( - + }> } /> - } /> } /> diff --git a/src/components/theme-provider.tsx b/src/components/theme-provider.tsx index 7b9eeb2..e292000 100644 --- a/src/components/theme-provider.tsx +++ b/src/components/theme-provider.tsx @@ -14,7 +14,7 @@ type ThemeProviderState = { }; const initialState: ThemeProviderState = { - theme: "system", + theme: "dark", setTheme: () => null, }; diff --git a/src/main.tsx b/src/main.tsx index b24b892..a13a138 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -3,8 +3,9 @@ import App from "./App.tsx"; import "@/style/global.css"; window.ipcRenderer.on("main-process-message", (_event, message) => { - const { platform } = message + const { platform, theme } = message document.querySelector('html')?.setAttribute('platform', platform) + document.querySelector('html')?.setAttribute('theme', theme) ReactDOM.createRoot(document.getElementById("root")!).render(); }); diff --git a/src/style/global.css b/src/style/global.css index cc6082d..db0acf5 100644 --- a/src/style/global.css +++ b/src/style/global.css @@ -12,7 +12,7 @@ body, @layer base { :root { - --background: 0 0% 97.25%; + --background: 0 0% 94.12%; --foreground: 240 10% 3.9%; --card: 0 0% 100%; --card-foreground: 240 10% 3.9%;