'use strict' ; import { app , protocol , BrowserWindow , ipcMain , clipboard , shell , Menu , } from 'electron' ; import * as path from 'path' ; import { format as formatUrl } from 'url' ; import { createProtocol , installVueDevtools , } from 'vue-cli-plugin-electron-builder/lib' ; import './updator' ; const isDevelopment = process . env . NODE_ENV !== 'production' ; if ( isDevelopment ) { require ( 'module' ) . globalPaths . push ( process . env . NODE_MODULES_PATH ) ; } let mainWindow ; protocol . registerStandardSchemes ( [ 'app' ] , { secure : true } ) ; function createMainWindow ( ) { const window = new BrowserWindow ( { width : 600 , height : 400 , titleBarStyle : 'hidden' , alwaysOnTop : false , } ) ; if ( isDevelopment ) { window . loadURL ( process . env . WEBPACK_DEV_SERVER_URL as string ) ; } else { createProtocol ( 'app' ) ; window . loadURL ( formatUrl ( { pathname : path . join ( __dirname , 'index.html' ) , protocol : 'file' , slashes : true , } ) ) ; } window . on ( 'closed' , ( ) => { mainWindow = null ; } ) ; window . webContents . on ( 'devtools-opened' , ( ) => { window . focus ( ) ; setImmediate ( ( ) => { window . focus ( ) ; } ) ; } ) ; window . webContents . on ( 'new-window' , ( event , url ) => { event . preventDefault ( ) ; shell . openExternal ( url ) ; } ) ; const menuTemplate = [ ] ; if ( process . platform === 'darwin' ) { menuTemplate . push ( { label : app . getName ( ) , submenu : [ { label : 'Preferences' , accelerator : 'CmdOrCtrl+,' , click : ( ) => { if ( mainWindow ) mainWindow . webContents . send ( 'preferences' ) ; } , } , { type : 'separator' , } , { role : 'quit' , } , ] , } , { label : 'View' , submenu : [ { label : 'Reload' , accelerator : 'Command+R' , click : function ( ) { mainWindow . reload ( ) ; } , } , { label : 'Close' , accelerator : 'Command+W' , click : function ( ) { mainWindow . close ( ) ; } , } , { label : 'Toggle Full Screen' , accelerator : 'Ctrl+Command+F' , click : function ( ) { mainWindow . setFullScreen ( ! mainWindow . isFullScreen ( ) ) ; } , } , { label : 'Toggle Developer Tools' , accelerator : 'Alt+Command+I' , click : function ( ) { mainWindow . toggleDevTools ( ) ; } , } , ] , } ) ; } Menu . setApplicationMenu ( Menu . buildFromTemplate ( menuTemplate ) ) ; return window ; } app . on ( 'window-all-closed' , ( ) => { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'activate' , ( ) => { if ( mainWindow === null ) { mainWindow = createMainWindow ( ) ; } } ) ; app . on ( 'ready' , async ( ) => { if ( isDevelopment && ! process . env . IS_TEST ) { await installVueDevtools ( ) ; } mainWindow = createMainWindow ( ) ; } ) ; ipcMain . on ( 'alwaysOnTop' , ( event , arg ) => { mainWindow . setAlwaysOnTop ( arg ) ; } ) ; ipcMain . on ( 'copy' , ( event , arg ) => { setTimeout ( ( ) => { clipboard . writeText ( arg ) ; } , 200 ) ; } ) ;