Skip to content

Commit 91f6ee2

Browse files
committed
fix: Update deprecated electron methods
1 parent f644185 commit 91f6ee2

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/main/Main.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { APP_TITLE } from '@shared/constants';
88
import { CustomIPC, WindowIPC } from '@shared/interfaces';
99
import { ChildProcess, fork } from 'child_process';
1010
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';
1212
import { REACT_DEVELOPER_TOOLS, installExtension } from 'electron-extension-installer';
1313
import { AppPreferencesData } from 'flashpoint-launcher';
1414
import * as fs from 'fs-extra';
1515
import * as path from 'path';
1616
import { argv } from 'process';
17-
import * as WebSocket from 'ws';
17+
import WebSocket from 'ws';
1818
import * as Util from './Util';
1919
import { Init } from './types';
2020

@@ -373,7 +373,7 @@ export function main(init: Init): void {
373373
}
374374
}
375375

376-
function onAppWillQuit(event: Event): void {
376+
function onAppWillQuit(event: Electron.Event): void {
377377
if (!init.args['connect-remote'] && !state.isQuitting && state.socket.client.socket) { // (Local back)
378378
state.socket.send(BackIn.QUIT);
379379
event.preventDefault();
@@ -383,8 +383,16 @@ export function main(init: Init): void {
383383
function onAppWebContentsCreated(event: Electron.Event, webContents: Electron.WebContents): void {
384384
// Open links to web pages in the OS-es default browser
385385
// (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+
});
388396

389397
webContents.session.setPermissionRequestHandler((webContents, permission, requestingOrigin, details) => {
390398
if (permission === 'fullscreen') {
@@ -399,8 +407,7 @@ export function main(init: Init): void {
399407
proxyBypassRules: '<local>,*.unstable.life,*.flashpointarchive.org',
400408
});
401409

402-
function onNewPage(event: Electron.Event, navigationUrl: string): void {
403-
event.preventDefault();
410+
function onNewPage(navigationUrl: string): void {
404411
shell.openExternal(navigationUrl);
405412
}
406413
}
@@ -499,11 +506,11 @@ export function main(init: Init): void {
499506
window.maximize();
500507
}
501508
// 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);
504511
});
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);
507514
});
508515
// Replay window's move event to the renderer
509516
window.on('move', () => {
@@ -604,12 +611,3 @@ export function main(init: Init): void {
604611

605612
function noop() { /* Do nothing. */ }
606613
}
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

Comments
 (0)