| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-02-27 12:12:19 |
| 4 | * @LastEditTime: 2025-02-27 16:38:08 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: |
| 7 | */ |
| 8 | import { BrowserWindow } from 'electron'; |
| 9 | import path from 'node:path'; |
| 10 | import { VITE_DEV_SERVER_URL, RENDERER_DIST } from './index'; |
| 11 | |
| 12 | export class SplashWindow { |
| 13 | private window: BrowserWindow | null = null; |
| 14 | |
| 15 | create() { |
| 16 | this.window = new BrowserWindow({ |
| 17 | width: 400, |
| 18 | height: 400, |
| 19 | transparent: true, |
| 20 | frame: false, |
| 21 | alwaysOnTop: true, |
| 22 | skipTaskbar: true, |
| 23 | center: true, |
| 24 | // backgroundColor: 'var(--whiteColor1)', // 添加背景色 |
| 25 | webPreferences: { |
| 26 | nodeIntegration: true, |
| 27 | contextIsolation: false, |
| 28 | }, |
| 29 | }); |
| 30 | |
| 31 | // 根据开发环境和生产环境使用不同的加载方式 |
| 32 | const splashPath = VITE_DEV_SERVER_URL |
| 33 | ? path.join(process.env.VITE_PUBLIC!, 'splash.html') |
| 34 | : path.join(RENDERER_DIST, 'splash.html'); |
| 35 | |
| 36 | console.log('Splash path:', splashPath); // 调试路径 |
| 37 | |
| 38 | this.window.loadFile(splashPath).catch((err) => { |
| 39 | console.error('Failed to load splash window:', err); |
| 40 | }); |
| 41 | |
| 42 | // 只在开发环境打印日志 |
| 43 | if (VITE_DEV_SERVER_URL) { |
| 44 | this.window.webContents.on('did-finish-load', () => { |
| 45 | console.log('Splash window loaded'); |
| 46 | }); |
| 47 | |
| 48 | this.window.webContents.on('did-fail-load', (_, code, description) => { |
| 49 | console.error('Splash window failed to load:', code, description); |
| 50 | }); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | close() { |
| 55 | if (this.window) { |
| 56 | this.window.close(); |
| 57 | this.window = null; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |