import 'babel-polyfill' ; import { app , BrowserWindow , shell , Menu , protocol , webFrame , ipcMain } from 'electron' ; import { autoUpdater } from 'electron-updater' ; import * as url from 'url' ; import * as path from 'path' ; import { initialize } from './lib/ledger' ; app . setAsDefaultProtocolClient ( 'xrb' ) ; initialize ( ) ; let mainWindow ; function createWindow ( ) { mainWindow = new BrowserWindow ( { width : 1000 , height : 600 , webPreferences : { webSecurity : false , devTools : true } } ) ; mainWindow . loadURL ( url . format ( { pathname : path . join ( __dirname , '../../dist/index.html' ) , protocol : 'file:' , slashes : true } ) ) ; mainWindow . on ( 'closed' , function ( ) { mainWindow = null ; } ) ; mainWindow . webContents . on ( 'new-window' , function ( e , url ) { e . preventDefault ( ) ; shell . openExternal ( url ) ; } ) ; const menuTemplate = getApplicationMenu ( ) ; Menu . setApplicationMenu ( Menu . buildFromTemplate ( menuTemplate ) ) ; } app . on ( 'ready' , ( ) => { createWindow ( ) ; app . on ( 'open-url' , ( event , path ) => { if ( ! mainWindow ) { createWindow ( ) ; } if ( ! mainWindow . webContents . isLoading ( ) ) { mainWindow . webContents . executeJavaScript ( `window.dispatchEvent(new CustomEvent('protocol-load', { detail: '${ path }' }));` ) ; } mainWindow . webContents . once ( 'did-finish-load' , ( ) => { mainWindow . webContents . executeJavaScript ( `window.dispatchEvent(new CustomEvent('protocol-load', { detail: '${ path }' }));` ) ; } ) ; event . preventDefault ( ) ; } ) ; checkForUpdates ( ) ; } ) ; app . on ( 'window-all-closed' , function ( ) { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'activate' , function ( ) { if ( mainWindow === null ) { createWindow ( ) ; } } ) ; function checkForUpdates ( ) { autoUpdater . checkForUpdatesAndNotify ( ) . then ( ( ) => { } ) . catch ( console . log ) ; } function getApplicationMenu ( ) { const template = [ { label : 'Edit' , submenu : [ { role : 'undo' } , { role : 'redo' } , { type : 'separator' } , { role : 'cut' } , { role : 'copy' } , { role : 'paste' } , { role : 'pasteandmatchstyle' } , { role : 'delete' } , { role : 'selectall' } ] } , { label : 'View' , submenu : [ { role : 'reload' } , { role : 'forcereload' } , { role : 'toggledevtools' } , { type : 'separator' } , { role : 'resetzoom' } , { role : 'zoomin' } , { role : 'zoomout' } , { type : 'separator' } , { role : 'togglefullscreen' } ] } , { role : 'window' , submenu : [ { role : 'minimize' } , { role : 'close' } ] } , { role : 'help' , submenu : [ { label : 'View GitHub' , click ( ) { loadExternal ( 'https://github.com/cronoh/nanovault' ) ; } } , { label : 'Submit Issue' , click ( ) { loadExternal ( 'https://github.com/cronoh/nanovault/issues/new' ) ; } } , { type : 'separator' } , { type : 'normal' , label : `NanoVault Version: ${ autoUpdater . currentVersion }` , } , { label : 'View Latest Updates' , click ( ) { loadExternal ( 'https://github.com/cronoh/nanovault/releases' ) ; } } , { type : 'separator' } , { label : `Check for Updates...` , click ( menuItem , browserWindow ) { checkForUpdates ( ) ; } } , ] } ] ; if ( process . platform === 'darwin' ) { template . unshift ( { label : 'NanoVault' , submenu : [ { role : 'about' } , { type : 'separator' } , { label : `Check for Updates...` , click ( menuItem , browserWindow ) { checkForUpdates ( ) ; } } , { type : 'separator' } , { role : 'hide' } , { role : 'hideothers' } , { role : 'unhide' } , { type : 'separator' } , { role : 'quit' } ] } ) ; template [ 1 ] . submenu . push ( { type : 'separator' } , { label : 'Speech' , submenu : [ { role : 'startspeaking' } , { role : 'stopspeaking' } ] } ) ; template [ 3 ] . submenu = [ { role : 'close' } , { role : 'minimize' } , { role : 'zoom' } , { type : 'separator' } , { role : 'front' } ] ; } return template ; } function loadExternal ( url ) { shell . openExternal ( url ) ; }