feat:项目打包成Electron
This commit is contained in:
45
desktop/main/window.ts
Normal file
45
desktop/main/window.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// ============================================================
|
||||
// BrowserWindow 创建与配置
|
||||
// 职责:窗口属性、加载策略(开发/生产)、快捷键
|
||||
// ============================================================
|
||||
|
||||
import { app, BrowserWindow, screen } from 'electron'
|
||||
import { join } from 'path'
|
||||
|
||||
// 判断是否为开发模式
|
||||
const isDev = process.env.NODE_ENV === 'development' || !app.isPackaged
|
||||
|
||||
// 前端路径配置
|
||||
const FRONTEND_DEV_URL = 'http://localhost:5173'
|
||||
const FRONTEND_DIST_PATH = '../frontend/dist/index.html'
|
||||
|
||||
export function createMainWindow(): BrowserWindow {
|
||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
||||
|
||||
const win = new BrowserWindow({
|
||||
width: Math.min(1400, width),
|
||||
height: Math.min(900, height),
|
||||
minWidth: 800,
|
||||
minHeight: 600,
|
||||
title: 'CamTalk',
|
||||
titleBarStyle: process.platform === 'darwin' ? 'hiddenInset' : 'default',
|
||||
backgroundColor: '#1a1a2e',
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
// 允许加载 http 资源(连接远程后端时需要)
|
||||
webSecurity: false,
|
||||
},
|
||||
})
|
||||
|
||||
// 加载前端内容
|
||||
if (isDev) {
|
||||
win.loadURL(FRONTEND_DEV_URL)
|
||||
win.webContents.openDevTools({ mode: 'detach' })
|
||||
} else {
|
||||
win.loadFile(join(__dirname, FRONTEND_DIST_PATH))
|
||||
}
|
||||
|
||||
return win
|
||||
}
|
||||
Reference in New Issue
Block a user