import { app , dialog , ipcMain } from 'electron' ; import * as os from 'os' ; import * as path from 'path' ; import { UserConfigs } from './config' ; import { LoadExtension } from './extension/extension' ; import { Global , InitGlobal , Logger } from './global' ; import i18n from './i18n' ; import { LoadResourcePack } from './resourcepack/resourcepack' ; import { ListenServer , LoadServer } from './server' ; import { LoadTool } from './tool/tool' ; import bossKey from './utilities/bossKey' ; import openFile from './utilities/openFile' ; import sandbox from './utilities/sandbox' ; import screenshot from './utilities/screenshot' ; import { initPlayer , AudioPlayer } from './windows/audioPlayer' ; import { GameWindows , initGameWindow } from './windows/game' ; import { initManagerWindow , ManagerWindow } from './windows/manager' ; import { initToolManager } from './windows/tool' ; InitGlobal ( ) ; LoadResourcePack ( ) ; LoadExtension ( ) ; LoadTool ( ) ; if ( UserConfigs . chromium . proxyUrl !== '' ) { if ( UserConfigs . chromium . proxyUrl !== 'system-proxy' ) { app . commandLine . appendSwitch ( 'proxy-server' , UserConfigs . chromium . proxyUrl ) ; } } else { app . commandLine . appendArgument ( 'no-proxy-server' ) ; } if ( UserConfigs . chromium . isInProcessGpuOn ) { const osplatform = os . platform ( ) ; switch ( osplatform ) { case 'darwin' : case 'win32' : app . commandLine . appendSwitch ( 'in-process-gpu' ) ; break ; case 'aix' : case 'android' : case 'cygwin' : case 'freebsd' : case 'openbsd' : case 'sunos' : default : break ; } } if ( UserConfigs . chromium . isIgnoreGpuBlacklist ) { app . commandLine . appendArgument ( 'ignore-gpu-blacklist' ) ; } if ( UserConfigs . chromium . isHardwareAccelerationDisable ) { app . disableHardwareAcceleration ( ) ; } if ( os . platform ( ) === 'win32' ) { app . commandLine . appendSwitch ( 'disable-direct-composition' ) ; } process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ; app . commandLine . appendSwitch ( 'ignore-certificate-errors' , 'true' ) ; app . commandLine . appendSwitch ( 'allow-insecure-localhost' , 'true' ) ; app . commandLine . appendSwitch ( 'autoplay-policy' , 'no-user-gesture-required' ) ; app . on ( 'window-all-closed' , app . quit ) ; app . on ( 'certificate-error' , ( event , webContents , url , error , certificate , callback ) => { if ( certificate . fingerprint === 'sha256/UMNIGcBbbIcru/0L2e1idl+aQS7PUHqsZDcrETqdMsc=' ) { event . preventDefault ( ) ; callback ( true ) ; } else { callback ( false ) ; } } ) ; app . requestSingleInstanceLock ( ) ; app . on ( 'second-instance' , ( event , argv , directory ) => { if ( ManagerWindow && ! ManagerWindow . isDestroyed ( ) ) { if ( argv . length > 2 + Number ( process . env . NODE_ENV === 'development' ) ) { const upath = path . resolve ( process . argv [ 1 + Number ( process . env . NODE_ENV === 'development' ) ] ) ; openFile . setPath ( upath ) ; openFile . register ( ) ; ManagerWindow . webContents . send ( 'refresh-all' ) ; } } else { if ( argv . length > 2 + Number ( process . env . NODE_ENV === 'development' ) ) { dialog . showMessageBox ( AudioPlayer , { type : 'info' , title : i18n . text . main . programName ( ) , message : '游戏界面中无法导入雀魂 Plus 拓展!' , buttons : [ 'OK' ] } ) ; } } } ) ; app . on ( 'will-finish-launching' , ( ) => { app . on ( 'open-file' , ( event , path ) => { event . preventDefault ( ) ; openFile . setPath ( path ) ; openFile . register ( ) ; } ) ; } ) ; app . on ( 'ready' , ( ) => { initGameWindow ( ) ; ipcMain . on ( 'start-game' , ( ) => { LoadServer ( ) ; ListenServer ( Global . ServerPort ) ; if ( ! process . env . SERVER_ONLY ) { GameWindows . newWindow ( ) ; } else { initPlayer ( ) ; } ManagerWindow . close ( ) ; } ) ; bossKey . register ( ) ; screenshot . register ( ) ; sandbox . register ( ) ; if ( process . platform !== 'darwin' ) { openFile . register ( ) ; } initManagerWindow ( ) ; initToolManager ( ) ; } ) ; app . on ( 'gpu-process-crashed' , ( event , killed ) => { Logger . error ( `gpu-process-crashed, killed: ${ killed }` ) ; } ) ; process . on ( 'uncaughtException' , err => { Logger . error ( `uncaughtException ${ err . name }: ${ err . message }` ) ; } ) ;