import { app , BrowserWindow , ipcMain , Menu , shell , dialog } from 'electron' ; import installExtension , { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer' ; import { enableLiveReload } from 'electron-compile' ; import processFonts from './process-fonts' ; import * as path from 'path' ; const checkUpdates = require ( './checkupdates' ) ; let mainWindow = null ; const isDevMode = process . execPath . match ( /[\\/]electron/ ) ; if ( isDevMode ) { enableLiveReload ( { strategy : 'react-hmr' } ) ; } const createWindow = async ( ) => { mainWindow = new BrowserWindow ( { width : isDevMode ? 800 : 200 , height : isDevMode ? 800 : 200 , resizable : ! ! isDevMode , show : false , backgroundColor : '#000' , titleBarStyle : 'hiddenInset' , fullscreen : false , fullscreenable : false , maximizable : false , icon : path . join ( __dirname , 'src/fontplop-app-icon.png' ) } ) ; mainWindow . loadURL ( `file://${ __dirname }/index.html` ) ; if ( isDevMode ) { await installExtension ( REACT_DEVELOPER_TOOLS ) ; mainWindow . webContents . openDevTools ( ) ; } mainWindow . once ( 'ready-to-show' , ( ) => { if ( mainWindow ) { mainWindow . show ( ) ; } } ) ; mainWindow . on ( 'closed' , ( ) => { mainWindow = null ; } ) ; mainWindow . webContents . on ( 'did-frame-finish-load' , ( ) => { if ( ! isDevMode ) { checkUpdates ( ) ; } } ) ; const showOpen = function ( ) { dialog . showOpenDialog ( { properties : [ 'openFile' , 'openDirectory' , 'multiSelections' ] , filters : [ { name : 'fontplop' , extensions : [ 'ttf' , 'otf' ] } ] } , ( filePaths ) => { processFonts ( filePaths ) ; } ) ; } ; const menu = Menu . buildFromTemplate ( [ { submenu : [ { label : 'About fontplop' , click : ( ) => { shell . openExternal ( 'http://www.fontplop.com' ) ; } } , { label : 'Check for Updates...' , click : ( ) => checkUpdates ( { forceCheck : true } ) } , { type : 'separator' } , { role : 'quit' } ] } , { label : 'File' , submenu : [ { label : 'Open' , click : function ( ) { showOpen ( ) ; } } ] } ] ) ; Menu . setApplicationMenu ( menu ) ; } ; app . on ( 'ready' , createWindow ) ; app . on ( 'window-all-closed' , ( ) => { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'activate' , ( ) => { if ( mainWindow === null ) { createWindow ( ) ; } } ) ; ipcMain . on ( 'process-fonts' , ( event , files ) => { event . preventDefault ( ) ; processFonts ( files ) ; } ) ; app . on ( 'open-file' , function ( event , filePaths ) { event . preventDefault ( ) ; if ( app . isReady ( ) ) { processFonts ( filePaths ) ; } else { app . once ( 'ready' , ( ) => { processFonts ( filePaths ) ; } ) ; } } ) ;