@@ -8,13 +8,13 @@ import { APP_TITLE } from '@shared/constants';
8
8
import { CustomIPC , WindowIPC } from '@shared/interfaces' ;
9
9
import { ChildProcess , fork } from 'child_process' ;
10
10
import { randomBytes } from 'crypto' ;
11
- import { BrowserWindow , IpcMainEvent , WebContents , app , dialog , ipcMain , session , shell } from 'electron' ;
11
+ import { BrowserWindow , IpcMainEvent , app , dialog , ipcMain , session , shell } from 'electron' ;
12
12
import { REACT_DEVELOPER_TOOLS , installExtension } from 'electron-extension-installer' ;
13
13
import { AppPreferencesData } from 'flashpoint-launcher' ;
14
14
import * as fs from 'fs-extra' ;
15
15
import * as path from 'path' ;
16
16
import { argv } from 'process' ;
17
- import * as WebSocket from 'ws' ;
17
+ import WebSocket from 'ws' ;
18
18
import * as Util from './Util' ;
19
19
import { Init } from './types' ;
20
20
@@ -373,7 +373,7 @@ export function main(init: Init): void {
373
373
}
374
374
}
375
375
376
- function onAppWillQuit ( event : Event ) : void {
376
+ function onAppWillQuit ( event : Electron . Event ) : void {
377
377
if ( ! init . args [ 'connect-remote' ] && ! state . isQuitting && state . socket . client . socket ) { // (Local back)
378
378
state . socket . send ( BackIn . QUIT ) ;
379
379
event . preventDefault ( ) ;
@@ -383,8 +383,16 @@ export function main(init: Init): void {
383
383
function onAppWebContentsCreated ( event : Electron . Event , webContents : Electron . WebContents ) : void {
384
384
// Open links to web pages in the OS-es default browser
385
385
// (instead of navigating to it with the electron window that opened it)
386
- webContents . on ( 'will-navigate' , onNewPage ) ;
387
- webContents . on ( 'new-window' , onNewPage ) ;
386
+ webContents . on ( 'will-navigate' , ( event , url ) => {
387
+ event . preventDefault ( ) ;
388
+ onNewPage ( url ) ;
389
+ } ) ;
390
+ webContents . setWindowOpenHandler ( ( details ) => {
391
+ onNewPage ( details . url ) ;
392
+ return {
393
+ action : 'deny'
394
+ } ;
395
+ } ) ;
388
396
389
397
webContents . session . setPermissionRequestHandler ( ( webContents , permission , requestingOrigin , details ) => {
390
398
if ( permission === 'fullscreen' ) {
@@ -399,8 +407,7 @@ export function main(init: Init): void {
399
407
proxyBypassRules : '<local>,*.unstable.life,*.flashpointarchive.org' ,
400
408
} ) ;
401
409
402
- function onNewPage ( event : Electron . Event , navigationUrl : string ) : void {
403
- event . preventDefault ( ) ;
410
+ function onNewPage ( navigationUrl : string ) : void {
404
411
shell . openExternal ( navigationUrl ) ;
405
412
}
406
413
}
@@ -499,11 +506,11 @@ export function main(init: Init): void {
499
506
window . maximize ( ) ;
500
507
}
501
508
// Relay window's maximize/unmaximize events to the renderer (as a single event with a flag)
502
- window . on ( 'maximize' , ( event : BrowserWindowEvent ) => {
503
- event . sender . send ( WindowIPC . WINDOW_MAXIMIZE , true ) ;
509
+ window . on ( 'maximize' , ( ) => {
510
+ window . webContents . send ( WindowIPC . WINDOW_MAXIMIZE , true ) ;
504
511
} ) ;
505
- window . on ( 'unmaximize' , ( event : BrowserWindowEvent ) => {
506
- event . sender . send ( WindowIPC . WINDOW_MAXIMIZE , false ) ;
512
+ window . on ( 'unmaximize' , ( ) => {
513
+ window . webContents . send ( WindowIPC . WINDOW_MAXIMIZE , false ) ;
507
514
} ) ;
508
515
// Replay window's move event to the renderer
509
516
window . on ( 'move' , ( ) => {
@@ -604,12 +611,3 @@ export function main(init: Init): void {
604
611
605
612
function noop ( ) { /* Do nothing. */ }
606
613
}
607
-
608
- /**
609
- * Type of the event emitted by BrowserWindow for the "maximize" and "unmaximize" events.
610
- * This type is not defined by Electron, so I guess I have to do it here instead.
611
- */
612
- type BrowserWindowEvent = {
613
- preventDefault : ( ) => void ;
614
- sender : WebContents ;
615
- }
0 commit comments