import { BrowserWindow , Menu , nativeImage , shell } from "electron" ; import isDev from "electron-is-dev" ; import path from "path" ; import URL from "url" ; let openWindows = [ ] ; import * as protocolHandler from "./protocol-handler" ; import { Messages } from "./shared/ipc" ; export function createMainWindow ( ) { if ( process . platform !== "darwin" ) { Menu . setApplicationMenu ( null ) ; } const window = new BrowserWindow ( { width : 800 , height : 600 , minWidth : 400 , minHeight : 300 , title : "Solar Wallet" , icon : nativeImage . createFromPath ( path . join ( __dirname , "../build/icon.png" ) ) , backgroundColor : "#0196E8" , titleBarStyle : process . platform === "darwin" ? "hidden" : "default" , webPreferences : { contextIsolation : true , disableBlinkFeatures : "Auxclick" , enableRemoteModule : false , nodeIntegration : false , nodeIntegrationInWorker : false , preload : isDev ? path . join ( __dirname , ".." , "lib" , "preload.js" ) : path . join ( __dirname , "preload.js" ) , sandbox : true , webviewTag : false } } ) ; window . removeMenu ( ) ; const pathname = isDev ? path . join ( __dirname , "../../dist/index.dev.html" ) : path . join ( __dirname , "../../dist/index.prod.html" ) ; const webappURL = URL . format ( { pathname , protocol : "file:" , slashes : true } ) ; window . loadURL ( webappURL ) ; window . webContents . session . setPermissionRequestHandler ( ( webContents , permission , callback ) => { if ( ! webContents . getURL ( ) . startsWith ( "file://" ) && ( permission === "media" || permission === "openExternal" ) ) { return callback ( false ) ; } else { return callback ( true ) ; } } ) ; window . webContents . on ( "new-window" , ( event , url ) => { event . preventDefault ( ) ; if ( window . webContents . getURL ( ) . startsWith ( "file://" ) ) { shell . openExternal ( url ) ; } } ) ; window . webContents . on ( "will-redirect" , ( event , url ) => { if ( ! window . webContents . getURL ( ) . startsWith ( "file://" ) ) { event . preventDefault ( ) ; } } ) ; const unsubscribe = protocolHandler . subscribe ( url => { window . webContents . send ( Messages . DeepLinkURL , url ) ; if ( process . platform === "linux" ) { window . minimize ( ) ; window . restore ( ) ; window . focus ( ) ; } window . show ( ) ; } ) ; window . on ( "closed" , ( ) => { protocolHandler . windowDestroyed ( ) ; unsubscribe ( ) ; } ) ; window . webContents . on ( "did-finish-load" , ( ) => { protocolHandler . windowReady ( ) ; } ) ; return window ; } export function getOpenWindows ( ) { return openWindows ; } export function trackWindow ( window ) { openWindows . push ( window ) ; window . on ( "closed" , ( ) => { openWindows = openWindows . filter ( someWindow => someWindow !== window ) ; } ) ; return window ; }