| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import { app, BrowserWindow,screen } from 'electron'
- import express from "express"
- const electron = require('electron')
- const ipc = electron.ipcMain
- /**
- * Set `__static` path to static files in production
- * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
- */
- if (process.env.NODE_ENV !== 'development') {
- global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
- }
- let mainWindow
- const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080` : `http://localhost:8888/index.html`
- app.commandLine.appendSwitch('ppapi-flash-path',app.getPath('pepperFlashSystemPlugin'))
- function createWindow () {
- let size = screen.getPrimaryDisplay().workAreaSize
- let width = parseInt(size.width)
- let height = parseInt(size.height)
- /**
- * Initial window options
- */
- mainWindow = new BrowserWindow({
- width: width,
- height: height,
- show:false,
- titleBarStyle:'hiddenInset',
- autoHideMenuBar: true,
- webPreferences: {
- // 使用插件
- plugins: true,
- // 允许跨域
- webSecurity: false,
- // 渲染进程是否使用node
- nodeIntegration: true
- },
- })
- mainWindow.loadURL(winURL)
- //进入软件即开启全屏
- mainWindow.setFullScreen(true)
- // 打开开发者工具
- // mainWindow.webContents.openDevTools();
- mainWindow.once('ready-to-show', () => {
- mainWindow.show()
- })
- mainWindow.on('closed', () => {
- mainWindow = null
- })
- if (process.env.NODE_ENV === "production") {
- localServer()
- }
- }
- app.on('ready', createWindow)
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit()
- }
- })
- app.on('activate', () => {
- if (mainWindow === null) {
- createWindow()
- }
- })
- // 最小化窗口
- ipc.on('window-min',function(){
- mainWindow.minimize()
- })
- // 关闭窗口
- ipc.on('window-close',function() {
- mainWindow.close()
- })
- function localServer() {
- let server = express()
- server.use(express.static(__dirname))
- server.listen(8888)
- }
|