52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
const { app, BrowserWindow, ipcMain, Menu, globalShortcut } = require('electron')
|
|
const { platform } = require('node:process')
|
|
const path = require('path')
|
|
|
|
console.log(`This platform is ${platform}`);
|
|
|
|
const createWindow = () => {
|
|
// 创建窗口
|
|
const mainWindow = new BrowserWindow({
|
|
width: 1080,
|
|
minWidth: 760,
|
|
height: 720,
|
|
minHeight: 480,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.js')
|
|
},
|
|
})
|
|
|
|
// 加载 HTML
|
|
mainWindow.loadFile('html/index.html')
|
|
|
|
// 隐藏菜单栏
|
|
// let menu = Menu.getApplicationMenu()
|
|
Menu.setApplicationMenu(null)
|
|
|
|
// 全屏逻辑
|
|
// mainWindow.fullScreen = true;
|
|
ipcMain.on('toggle-fullscreen', () => {
|
|
mainWindow.setFullScreen(!mainWindow.isFullScreen())
|
|
})
|
|
|
|
// 配置ESC键退出全屏
|
|
globalShortcut.register('ESC', () => {
|
|
mainWindow.setFullScreen(false);
|
|
})
|
|
|
|
// 调试窗口
|
|
// mainWindow.webContents.openDevTools()
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
createWindow()
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
})
|
|
})
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit()
|
|
})
|