import { app , BrowserWindow , ipcMain , globalShortcut } from 'electron' ; import * as os from 'os' ; import * as path from 'path' ; import * as url from 'url' ; import createTray from './tray' ; import createMainWindow from './window' ; import registerShortcuts from './shortcuts' ; import positioner from './positioner' ; import electronStore from 'electron-store' ; import electronLog from 'electron-log' ; let mainWindow ; let tray ; let isDialogOpen = false ; electronLog . transports . file . level = 'warn' ; let store = new electronStore ( { name : 'settings' , } ) ; function createWindow ( ) { mainWindow = createMainWindow ( ) ; tray = createTray ( mainWindow ) ; registerShortcuts ( mainWindow ) ; if ( ! store . has ( 'system.unobtrusive' ) || store . get ( 'system.unobtrusive' ) === true ) { mainWindow . on ( 'show' , ( ) => { positioner ( mainWindow , tray . getBounds ( ) ) ; } ) ; mainWindow . on ( 'blur' , ( ) => { if ( ! isDialogOpen ) { mainWindow . hide ( ) ; } } ) ; } } app . on ( 'ready' , createWindow ) ; app . on ( 'window-all-closed' , ( ) => { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'will-quit' , ( ) => { globalShortcut . unregisterAll ( ) ; } ) ; app . on ( 'activate' , ( ) => { if ( mainWindow === null ) { createWindow ( ) ; } } ) ; ipcMain . on ( 'WINDOW_QUIT' , ( ) => { app . quit ( ) ; } ) ; ipcMain . on ( 'WINDOW_MINIMIZE' , ( ) => { if ( mainWindow ) { mainWindow . minimize ( ) ; } } ) ; ipcMain . on ( 'WINDOW_MAXIMIZE' , ( ) => { if ( mainWindow ) { mainWindow . isMaximized ( ) ? mainWindow . unmaximize ( ) : mainWindow . maximize ( ) ; } } ) ; ipcMain . on ( 'SET_DIALOG_SHOW' , ( event , arg ) => { if ( store . get ( 'system.unobtrusive' ) === false ) { return ; } mainWindow . setAlwaysOnTop ( ! arg ) ; isDialogOpen = arg ; } ) ;