fix: make sure classes in lib correctly implement Electron interfaces (#40291)

This commit is contained in:
Milan Burda 2023-10-25 14:02:15 -04:00 committed by GitHub
parent 514a9319b9
commit f66d4c7ee0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 21 additions and 17 deletions

View file

@ -100,7 +100,7 @@ longer than the maximum length will be truncated.
### `crashReporter.getLastCrashReport()` ### `crashReporter.getLastCrashReport()`
Returns [`CrashReport`](structures/crash-report.md) - The date and ID of the Returns [`CrashReport | null`](structures/crash-report.md) - The date and ID of the
last crash report. Only crash reports that have been uploaded will be returned; last crash report. Only crash reports that have been uploaded will be returned;
even if a crash report is present on disk it will not be returned until it is even if a crash report is present on disk it will not be returned until it is
uploaded. In the case that there are no uploaded reports, `null` is returned. uploaded. In the case that there are no uploaded reports, `null` is returned.

View file

@ -2,7 +2,7 @@ import { app } from 'electron/main';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import * as squirrelUpdate from '@electron/internal/browser/api/auto-updater/squirrel-update-win'; import * as squirrelUpdate from '@electron/internal/browser/api/auto-updater/squirrel-update-win';
class AutoUpdater extends EventEmitter { class AutoUpdater extends EventEmitter implements Electron.AutoUpdater {
updateAvailable: boolean = false; updateAvailable: boolean = false;
updateURL: string | null = null; updateURL: string | null = null;
@ -15,7 +15,7 @@ class AutoUpdater extends EventEmitter {
} }
getFeedURL () { getFeedURL () {
return this.updateURL; return this.updateURL ?? '';
} }
setFeedURL (options: { url: string } | string) { setFeedURL (options: { url: string } | string) {

View file

@ -3,7 +3,7 @@ import * as deprecate from '@electron/internal/common/deprecate';
const binding = process._linkedBinding('electron_browser_crash_reporter'); const binding = process._linkedBinding('electron_browser_crash_reporter');
class CrashReporter { class CrashReporter implements Electron.CrashReporter {
start (options: Electron.CrashReporterStartOptions) { start (options: Electron.CrashReporterStartOptions) {
const { const {
productName = app.name, productName = app.name,

View file

@ -1,10 +1,12 @@
import { MessagePortMain } from '@electron/internal/browser/message-port-main'; import { MessagePortMain } from '@electron/internal/browser/message-port-main';
import { EventEmitter } from 'events';
const { createPair } = process._linkedBinding('electron_browser_message_port'); const { createPair } = process._linkedBinding('electron_browser_message_port');
export default class MessageChannelMain { export default class MessageChannelMain extends EventEmitter implements Electron.MessageChannelMain {
port1: MessagePortMain; port1: MessagePortMain;
port2: MessagePortMain; port2: MessagePortMain;
constructor () { constructor () {
super();
const { port1, port2 } = createPair(); const { port1, port2 } = createPair();
this.port1 = new MessagePortMain(port1); this.port1 = new MessagePortMain(port1);
this.port2 = new MessagePortMain(port2); this.port2 = new MessagePortMain(port2);

View file

@ -8,7 +8,7 @@ const {
isOnBatteryPower isOnBatteryPower
} = process._linkedBinding('electron_browser_power_monitor'); } = process._linkedBinding('electron_browser_power_monitor');
class PowerMonitor extends EventEmitter { class PowerMonitor extends EventEmitter implements Electron.PowerMonitor {
constructor () { constructor () {
super(); super();
// Don't start the event source until both a) the app is ready and b) // Don't start the event source until both a) the app is ready and b)

View file

@ -1,9 +1,11 @@
import { BrowserWindow, Menu, SharingItem, PopupOptions } from 'electron/main'; import { BrowserWindow, Menu, SharingItem, PopupOptions } from 'electron/main';
import { EventEmitter } from 'events';
class ShareMenu { class ShareMenu extends EventEmitter implements Electron.ShareMenu {
private menu: Menu; private menu: Menu;
constructor (sharingItem: SharingItem) { constructor (sharingItem: SharingItem) {
super();
this.menu = new (Menu as any)({ sharingItem }); this.menu = new (Menu as any)({ sharingItem });
} }

View file

@ -4,7 +4,7 @@ import { Socket } from 'net';
import { MessagePortMain } from '@electron/internal/browser/message-port-main'; import { MessagePortMain } from '@electron/internal/browser/message-port-main';
const { _fork } = process._linkedBinding('electron_browser_utility_process'); const { _fork } = process._linkedBinding('electron_browser_utility_process');
class ForkUtilityProcess extends EventEmitter { class ForkUtilityProcess extends EventEmitter implements Electron.UtilityProcess {
#handle: ElectronInternal.UtilityProcessWrapper | null; #handle: ElectronInternal.UtilityProcessWrapper | null;
#stdout: Duplex | null = null; #stdout: Duplex | null = null;
#stderr: Duplex | null = null; #stderr: Duplex | null = null;

View file

@ -1,7 +1,7 @@
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { IpcMainInvokeEvent } from 'electron/main'; import { IpcMainInvokeEvent } from 'electron/main';
export class IpcMainImpl extends EventEmitter { export class IpcMainImpl extends EventEmitter implements Electron.IpcMain {
private _invokeHandlers: Map<string, (e: IpcMainInvokeEvent, ...args: any[]) => void> = new Map(); private _invokeHandlers: Map<string, (e: IpcMainInvokeEvent, ...args: any[]) => void> = new Map();
constructor () { constructor () {

View file

@ -1,6 +1,6 @@
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
export class MessagePortMain extends EventEmitter { export class MessagePortMain extends EventEmitter implements Electron.MessagePortMain {
_internalPort: any; _internalPort: any;
constructor (internalPort: any) { constructor (internalPort: any) {
super(); super();

View file

@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
import { MessagePortMain } from '@electron/internal/browser/message-port-main'; import { MessagePortMain } from '@electron/internal/browser/message-port-main';
const { createParentPort } = process._linkedBinding('electron_utility_parent_port'); const { createParentPort } = process._linkedBinding('electron_utility_parent_port');
export class ParentPort extends EventEmitter { export class ParentPort extends EventEmitter implements Electron.ParentPort {
#port: ParentPort; #port: ParentPort;
constructor () { constructor () {
super(); super();

View file

@ -564,11 +564,11 @@ ifdescribe(process.platform === 'darwin' && !(process.env.CI && process.arch ===
}); });
it('should compare version numbers correctly', () => { it('should compare version numbers correctly', () => {
expect(autoUpdater.isVersionAllowedForUpdate('1.0.0', '2.0.0')).to.equal(true); expect(autoUpdater.isVersionAllowedForUpdate!('1.0.0', '2.0.0')).to.equal(true);
expect(autoUpdater.isVersionAllowedForUpdate('1.0.1', '1.0.10')).to.equal(true); expect(autoUpdater.isVersionAllowedForUpdate!('1.0.1', '1.0.10')).to.equal(true);
expect(autoUpdater.isVersionAllowedForUpdate('1.0.10', '1.0.1')).to.equal(false); expect(autoUpdater.isVersionAllowedForUpdate!('1.0.10', '1.0.1')).to.equal(false);
expect(autoUpdater.isVersionAllowedForUpdate('1.31.1', '1.32.0')).to.equal(true); expect(autoUpdater.isVersionAllowedForUpdate!('1.31.1', '1.32.0')).to.equal(true);
expect(autoUpdater.isVersionAllowedForUpdate('1.31.1', '0.32.0')).to.equal(false); expect(autoUpdater.isVersionAllowedForUpdate!('1.31.1', '0.32.0')).to.equal(false);
}); });
}); });

View file

@ -20,7 +20,7 @@ declare namespace Electron {
} }
interface AutoUpdater { interface AutoUpdater {
isVersionAllowedForUpdate(currentVersion: string, targetVersion: string): boolean; isVersionAllowedForUpdate?(currentVersion: string, targetVersion: string): boolean;
} }
type TouchBarItemType = NonNullable<Electron.TouchBarConstructorOptions['items']>[0]; type TouchBarItemType = NonNullable<Electron.TouchBarConstructorOptions['items']>[0];