import { openExternalUrl } from "@nteract/mythic-windowing" ; import { KernelspecInfo } from "@nteract/types" ; import { BrowserWindow , Menu } from "electron" ; import * as path from "path" ; import { loadFullMenu } from "./menu" ; let launchIpynb ; export function deferURL ( event , url ) { event . preventDefault ( ) ; if ( ! url . startsWith ( "file:" ) ) { global . store . dispatch ( openExternalUrl . create ( url ) ) ; } else if ( url . endsWith ( ".ipynb" ) ) { launchIpynb ( url ) ; } } const iconPath = path . join ( __dirname , ".." , "static" , "icon.png" ) ; export function launch ( filename ? ) { const win = new BrowserWindow ( { width : 800 , height : 1000 , icon : iconPath , title : "nteract" , show : false , webPreferences : { nodeIntegration : true , enableRemoteModule : true , contextIsolation : false } } ) ; win . once ( "ready-to-show" , ( ) => { win . show ( ) ; } ) ; const index = path . join ( __dirname , ".." , "static" , "index.html" ) ; win . loadURL ( `file://${ index }` ) ; win . webContents . on ( "did-finish-load" , ( ) => { const menu = loadFullMenu ( ) ; Menu . setApplicationMenu ( menu ) ; if ( filename !== undefined ) { win . webContents . send ( "main:load" , filename ) ; } win . webContents . send ( "main:load-config" ) ; } ) ; win . webContents . on ( "will-navigate" , deferURL ) ; win . on ( "focus" , ( ) => { const menu = loadFullMenu ( ) ; Menu . setApplicationMenu ( menu ) ; } ) ; win . on ( "show" , ( ) => { const menu = loadFullMenu ( ) ; Menu . setApplicationMenu ( menu ) ; } ) ; win . on ( "closed" , ( ) => { const menu = loadFullMenu ( ) ; Menu . setApplicationMenu ( menu ) ; } ) ; return win ; } launchIpynb = launch ; export function launchNewNotebook ( filepath , kernelSpec ) { const win = launch ( ) ; win . webContents . on ( "did-finish-load" , ( ) => { win . webContents . send ( "main:new" , filepath , kernelSpec ) ; } ) ; return win ; }