import { ipcListen } from './ipcEvent' ; const electron = require ( 'electron' ) ; const platform = require ( 'os' ) . platform ( ) ; const version = '0.1.1' ; const app = electron . app ; const BrowserWindow = electron . BrowserWindow ; const Menu = electron . Menu ; const path = require ( 'path' ) ; const url = require ( 'url' ) ; const ipc = electron . ipcMain ; let mainWindow ; ipc . on ( 'app close window' , ( sys , msg ) => { console . log ( sys , msg ) ; mainWindow . close ( ) ; } ) ; const setupMenu = ( ) => { const menu = new Menu ( ) ; mainWindow . setMenu ( menu ) ; const template = [ { label : 'Version' , submenu : [ { label : `版本版本：${ version }` , type : 'normal' } , ] } , ] ; Menu . setApplicationMenu ( Menu . buildFromTemplate ( template ) ) ; } ; function createWindow ( ) { mainWindow = new BrowserWindow ( { width : 1920 , height : 1080 , webPreferences : { nodeIntegration : true , webSecurity : false , contextIsolation : false } , backgroundColor : '#B1FF9D' , icon : path . join ( __dirname , './../../../build/icon/label-app-icon-512.png' ) } ) ; const startUrl = process . env . ELECTRON_START_URL || url . format ( { pathname : path . join ( __dirname , './../../../build/index.html' ) , protocol : 'file:' , slashes : true } ) ; setupMenu ( ) ; mainWindow . loadURL ( startUrl ) ; if ( startUrl . startsWith ( 'http' ) ) { mainWindow . webContents . openDevTools ( ) ; } ipcListen ( mainWindow ) ; electron . protocol . interceptFileProtocol ( 'file' , ( req , callback ) => { const url = req . url . substr ( 8 ) ; let newUrl = url ; try { newUrl = decodeURI ( url ) ; } catch ( e ) { console . error ( e ) ; } callback ( newUrl ) ; } ) ; mainWindow . on ( 'closed' , function ( ) { mainWindow = null ; } ) ; } app . on ( 'ready' , createWindow ) ; app . on ( 'window-all-closed' , function ( ) { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'activate' , function ( ) { if ( mainWindow === null ) { createWindow ( ) ; } } ) ;