import { app , BrowserWindow , dialog } from 'electron' ; import { i18n } from '../common/i18n' ; import { logger } from '../common/logger' ; import { CloudConfigDataTypes , config } from './config-handler' ; import { ICustomBrowserWindow , windowHandler } from './window-handler' ; import { windowExists } from './window-utils' ; let currentAuthURL ; let tries = 0 ; app . on ( 'login' , ( event , webContents , request , authInfo , callback ) => { event . preventDefault ( ) ; if ( currentAuthURL !== request . url ) { currentAuthURL = request . url ; tries = 0 ; } else { tries ++ ; } const hostname = authInfo . host || authInfo . realm ; const browserWin = BrowserWindow . fromWebContents ( webContents ) as ICustomBrowserWindow ; /**
     * Method that resets currentAuthURL and tries
     * if user closes the auth window
     */ const clearSettings = ( ) => { currentAuthURL = '' ; tries = 0 ; } ; /**
     * Opens an electron modal window in which
     * user can enter credentials fot the host
     */ windowHandler . createBasicAuthWindow ( browserWin , hostname , tries === 0 , clearSettings , callback ) ; } ) ; let ignoreAllCertErrors = false ; /**
 * If certificate error occurs allow user to deny or allow particular certificate
 * error.  If user selects 'Ignore All', then all subsequent certificate errors
 * will ignored during this session.
 *
 * Note: the dialog is synchronous so further processing is blocked until
 * user provides a response.
 */ app . on ( 'certificate-error' , async ( event , webContents , url , error , _certificate , callback ) => { if ( ignoreAllCertErrors ) { event . preventDefault ( ) ; callback ( true ) ; return ; } logger . warn ( `Certificate error: ${ error } for url: ${ url }` ) ; event . preventDefault ( ) ; const browserWin = BrowserWindow . fromWebContents ( webContents ) ; if ( browserWin && windowExists ( browserWin ) ) { const { response } = await dialog . showMessageBox ( browserWin , { type : 'warning' , buttons : [ i18n . t ( 'Allow' ) ( ) , i18n . t ( 'Deny' ) ( ) , i18n . t ( 'Ignore All' ) ( ) ] , defaultId : 1 , cancelId : 1 , noLink : true , title : i18n . t ( 'Certificate Error' ) ( ) , message : `${ i18n . t ( 'Certificate Error' ) ( ) }: ${ error }\nURL: ${ url }` , } ) ; if ( response === 2 ) { ignoreAllCertErrors = true ; } callback ( response !== 1 ) ; } } ) ; param browserWindow { BrowserWindow } param url { String } param errorDesc { String } param errorCode { Number } param retryCallback { function } param showDialog { Boolean } export const showLoadFailure = async ( browserWindow , url , errorDesc , errorCode , retryCallback , showDialog ) : Promise < void > => { let message = url ? `${ i18n . t ( 'Error loading URL' ) ( ) }:\n${ url }` : i18n . t ( 'Error loading window' ) ( ) ; if ( errorDesc ) { message += `\n\n${ errorDesc }` ; } if ( errorCode ) { message += `\n\nError Code: ${ errorCode }` ; } if ( showDialog ) { const { response } = await dialog . showMessageBox ( browserWindow , { type : 'error' , buttons : [ i18n . t ( 'Reload' ) ( ) , i18n . t ( 'Ignore' ) ( ) ] , defaultId : 0 , cancelId : 1 , noLink : true , title : i18n . t ( 'Loading Error' ) ( ) , message , } ) ; if ( response === 0 && typeof retryCallback === 'function' ) { retryCallback ( ) ; } } logger . warn ( `Load failure msg: ${ errorDesc } errorCode: ${ errorCode } for url: ${ url }` ) ; } ; param browserWindow { BrowserWindow } param url { String } param retryCallback { function } export const showNetworkConnectivityError = ( browserWindow , url = '' , retryCallback ) : void => { const errorDesc = i18n . t ( 'Network connectivity has been lost. Check your internet connection.' ) ( ) ; showLoadFailure ( browserWindow , url , errorDesc , 0 , retryCallback , true ) ; } ; param isNativeStyle { boolean } export const titleBarChangeDialog = async ( isNativeStyle ) => { const focusedWindow = BrowserWindow . getFocusedWindow ( ) ; if ( ! focusedWindow || ! windowExists ( focusedWindow ) ) { return ; } const options = { type : 'question' , title : i18n . t ( 'Relaunch Application' ) ( ) , message : i18n . t ( 'Updating Title bar style requires Symphony to relaunch.' ) ( ) , detail : i18n . t ( 'Note: When Hamburger menu is disabled, you can trigger the main menu by pressing the Alt key.' ) ( ) , buttons : [ i18n . t ( 'Relaunch' ) ( ) , i18n . t ( 'Cancel' ) ( ) ] , cancelId : 1 , } ; const { response } = await dialog . showMessageBox ( focusedWindow , options ) ; if ( response === 0 ) { logger . error ( `test` , isNativeStyle ) ; await config . updateUserConfig ( { isCustomTitleBar : isNativeStyle } ) ; app . relaunch ( ) ; app . exit ( ) ; } } ; param disableGpu export const gpuRestartDialog = async ( disableGpu ) => { const focusedWindow = BrowserWindow . getFocusedWindow ( ) ; if ( ! focusedWindow || ! windowExists ( focusedWindow ) ) { return ; } const options = { type : 'question' , title : i18n . t ( 'Relaunch Application' ) ( ) , message : i18n . t ( 'Would you like to restart and apply these new settings now?' ) ( ) , buttons : [ i18n . t ( 'Restart' ) ( ) , i18n . t ( 'Later' ) ( ) ] , cancelId : 1 , } ; const { response } = await dialog . showMessageBox ( focusedWindow , options ) ; await config . updateUserConfig ( { disableGpu } ) ; if ( response === 0 ) { app . relaunch ( ) ; app . exit ( ) ; } } ;