import { app , BrowserWindow , ipcMain } from 'electron' ; import MenuBuilder from './menu' ; import AppDb from './appDb' ; let mainWindow = null ; const defaults = { configName : 'user-data' , width : 800 , height : 600 , savedConnections : [ ] , theme : 'default' } ; const appDb = new AppDb ( defaults ) ; if ( process . env . NODE_ENV === 'production' ) { const sourceMapSupport = require ( 'source-map-support' ) ; sourceMapSupport . install ( ) ; } if ( process . env . NODE_ENV === 'development' || process . env . DEBUG_PROD === 'true' ) { process . env . ELECTRON_DISABLE_SECURITY_WARNINGS = 'true' ; require ( 'electron-debug' ) ( ) ; } const installExtensions = async ( ) => { const installer = require ( 'electron-devtools-installer' ) ; const forceDownload = ! ! process . env . UPGRADE_EXTENSIONS ; const extensions = [ 'REACT_DEVELOPER_TOOLS' , 'REDUX_DEVTOOLS' ] ; return Promise . all ( extensions . map ( name => installer . default ( installer [ name ] , forceDownload ) ) ) . catch ( console . log ) ; } ; app . setAboutPanelOptions ( { applicationName : 'SeeQL' , applicationVersion : '1.0.0-beta' , version : '1.0.0-beta' } ) ; app . on ( 'ready' , async ( ) => { if ( process . env . NODE_ENV === 'development' || process . env . DEBUG_PROD === 'true' ) { await installExtensions ( ) ; } mainWindow = new BrowserWindow ( { show : true , width : 1200 , height : 800 , minWidth : 600 , minHeight : 500 , titleBarStyle : 'hiddenInset' , center : true , icon : __dirname + '../resources/seeql.png.icns' , webPreferences : { nodeIntegration : true } } ) ; mainWindow . loadURL ( `file://${ __dirname }/app.html` ) ; mainWindow . webContents . on ( 'ready-to-show' , ( ) => { if ( ! mainWindow ) throw new Error ( '"mainWindow" is not defined' ) ; if ( process . env . START_MINIMIZED ) { mainWindow . minimize ( ) ; } else { mainWindow . show ( ) ; mainWindow . focus ( ) ; } } ) ; const menuBuilder = new MenuBuilder ( mainWindow ) ; menuBuilder . buildMenu ( ) ; mainWindow . on ( 'resize' , ( ) => { const { width , height } = mainWindow . getBounds ( ) ; appDb . set ( 'windowBounds' , { width , height } ) ; } ) ; mainWindow . on ( 'closed' , ( ) => { mainWindow = null ; } ) ; console . log ( `\n\n
   ('-').->  ('-')               <-.('-')
  ( OO)_    ( OO).->             __( OO)     <-.
 (_)--\_)  (,------.  ,------.  '-'---\_)  ,--. )
 /    _ /   |  .---'  |  .---' |  .-.  |   |  ('-')
 \_..'--.  (|  '--.   |  '--.  |  | |  |   |  |OO )
 .-._)   \  |  .--'   |  .--'  |  | |  |  (|  '__ |
 \       /  |  '---.  |  '---. '  '-'  '-. |     |'
  '-----'   '------'  '------'  '-----'--' '-----'

              Have a question?
    Contact us on github.com/oslabs-beta/seeql
\n\n
` ) ; } ) ; app . on ( 'window-all-closed' , ( ) => { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ;