import { BrowserWindow , App , BrowserView , Menu , dialog , ipcMain } from 'electron' ; import { resolve , join } from 'path' ; import { ViewManager } from '~/electron/view-manager' ; import { getMainMenu } from '~/electron/mainmenu' ; import { AppUpdater } from '~/electron/app-updater' ; import { Store } from '~/electron/store/datastore' ; export default class Main { static mainWindow : BrowserWindow ; static application : App ; static viewManager : ViewManager ; private static onWindowAllClosed ( ) { Main . application . quit ( ) ; } private static onClose ( ) { Main . mainWindow = null ; } private static async onReady ( ) { Main . mainWindow = new BrowserWindow ( { frame : false , minWidth : 400 , minHeight : 450 , width : 1200 , height : 700 , titleBarStyle : 'hiddenInset' , webPreferences : { plugins : true , nodeIntegration : true , contextIsolation : false , javascript : true , } } ) ; this . viewManager = new ViewManager ( Main . mainWindow ) ; Menu . setApplicationMenu ( getMainMenu ( this . viewManager ) ) ; const store = new Store ( { configName : 'settings-data' , defaults : { settings : { domainResolutionMethod : 'UnstoppableAPI' , ipfsContentMethod : 'CloudflareCDN' } } } ) ; ipcMain . on ( 'load-settings' , ( event ) => { let settings = store . get ( 'settings' ) ; console . log ( "Settings loaded " + JSON . stringify ( settings ) ) ; event . returnValue = settings ; } ) ; ipcMain . on ( 'save-settings' , ( event , settings ) => { console . log ( "Saving settings " + JSON . stringify ( settings ) ) ; store . set ( 'settings' , settings ) ; } ) ; ipcMain . on ( 'save-bookmarks' , ( event , bookmarks ) => { console . log ( "Saving bookmarks " , JSON . stringify ( bookmarks ) ) ; store . set ( 'bookmarks' , bookmarks ) ; } ) ; ipcMain . on ( 'load-bookmarks' , ( event ) => { let bookmarks = store . get ( 'bookmarks' ) ; console . log ( "Bookmarks loaded " + JSON . stringify ( bookmarks ) ) ; event . returnValue = bookmarks ; } ) ; ipcMain . on ( `window-toggle-maximize` , ( ) => { if ( Main . mainWindow . isMaximized ( ) ) { Main . mainWindow . unmaximize ( ) ; } else { Main . mainWindow . maximize ( ) ; } } ) ; ipcMain . on ( `window-minimize` , ( ) => { Main . mainWindow . minimize ( ) ; } ) ; ipcMain . on ( `window-close` , ( ) => { Main . mainWindow . close ( ) ; } ) ; Main . mainWindow . on ( 'closed' , Main . onClose ) ; if ( process . env . ENV === 'dev' ) { Main . mainWindow . loadURL ( 'http://localhost:3001/app.html' ) ; Main . mainWindow . webContents . openDevTools ( { mode : 'detach' } ) ; } else { Main . mainWindow . loadURL ( join ( 'file://' , Main . application . getAppPath ( ) , 'build/app.html' ) ) ; } Main . mainWindow . webContents . on ( 'dom-ready' , ( ) => { let updater = new AppUpdater ( Main . mainWindow ) ; console . log ( "dom-ready -> checkForUpdates() called" ) ; updater . checkForUpdates ( true ) ; } ) ; } static main ( app , browserWindow ) { Main . application = app ; Main . application . on ( 'window-all-closed' , Main . onWindowAllClosed ) ; Main . application . on ( 'ready' , Main . onReady ) ; } }