2023-12-18 19:39:36 +08:00
|
|
|
const { app, BrowserWindow, ipcMain } = require('electron')
|
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
|
const win = new BrowserWindow({
|
|
|
|
|
width: 1280,
|
|
|
|
|
height: 900,
|
|
|
|
|
frame: false,
|
|
|
|
|
webPreferences: {
|
|
|
|
|
nodeIntegration: true,
|
2023-12-18 23:07:44 +08:00
|
|
|
preload: path.join(__dirname, '/electron/preload.js'),
|
2023-12-18 19:39:36 +08:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
win.setMinimumSize(1280, 900);
|
|
|
|
|
|
2023-12-18 23:07:44 +08:00
|
|
|
if (process.env.NODE_ENV === 'dev') {
|
|
|
|
|
win.loadURL('http://localhost:4678/')
|
|
|
|
|
win.webContents.openDevTools({ mode: 'detach' })
|
|
|
|
|
} else {
|
|
|
|
|
win.loadURL(`file://${__dirname}/dist/index.html`)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-18 19:39:36 +08:00
|
|
|
|
|
|
|
|
app.whenReady().then(createWindow)
|
|
|
|
|
|
|
|
|
|
ipcMain.on('minimize-window', (event) => {
|
|
|
|
|
const win = BrowserWindow.fromWebContents(event.sender)
|
|
|
|
|
win.minimize()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ipcMain.on('maximize-window', (event) => {
|
|
|
|
|
const win = BrowserWindow.fromWebContents(event.sender)
|
|
|
|
|
if (win.isMaximized()) {
|
|
|
|
|
win.unmaximize()
|
|
|
|
|
} else {
|
|
|
|
|
win.maximize()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ipcMain.on('close-window', (event) => {
|
|
|
|
|
const win = BrowserWindow.fromWebContents(event.sender)
|
|
|
|
|
win.close()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ipcMain.on('drag-start', (event, data) => {
|
|
|
|
|
const win = BrowserWindow.fromWebContents(event.sender)
|
|
|
|
|
win.webContents.beginFrameSubscription((frameBuffer) => {
|
|
|
|
|
event.reply('frame-buffer', frameBuffer)
|
|
|
|
|
})
|
|
|
|
|
})
|