Skip to content

Commit

Permalink
fix: make sure classes in lib correctly implement Electron interfaces (
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak authored and MrHuangJser committed Dec 11, 2023
1 parent 395f201 commit 3c0d491
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/api/crash-reporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ longer than the maximum length will be truncated.

### `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;
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.
Expand Down
4 changes: 2 additions & 2 deletions lib/browser/api/auto-updater/auto-updater-win.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { app } from 'electron/main';
import { EventEmitter } from 'events';
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;
updateURL: string | null = null;

Expand All @@ -15,7 +15,7 @@ class AutoUpdater extends EventEmitter {
}

getFeedURL () {
return this.updateURL;
return this.updateURL ?? '';
}

setFeedURL (options: { url: string } | string) {
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/api/crash-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as deprecate from '@electron/internal/common/deprecate';

const binding = process._linkedBinding('electron_browser_crash_reporter');

class CrashReporter {
class CrashReporter implements Electron.CrashReporter {
start (options: Electron.CrashReporterStartOptions) {
const {
productName = app.name,
Expand Down
4 changes: 3 additions & 1 deletion lib/browser/api/message-channel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { MessagePortMain } from '@electron/internal/browser/message-port-main';
import { EventEmitter } from 'events';
const { createPair } = process._linkedBinding('electron_browser_message_port');

export default class MessageChannelMain {
export default class MessageChannelMain extends EventEmitter implements Electron.MessageChannelMain {
port1: MessagePortMain;
port2: MessagePortMain;
constructor () {
super();
const { port1, port2 } = createPair();
this.port1 = new MessagePortMain(port1);
this.port2 = new MessagePortMain(port2);
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/api/power-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
isOnBatteryPower
} = process._linkedBinding('electron_browser_power_monitor');

class PowerMonitor extends EventEmitter {
class PowerMonitor extends EventEmitter implements Electron.PowerMonitor {
constructor () {
super();
// Don't start the event source until both a) the app is ready and b)
Expand Down
4 changes: 3 additions & 1 deletion lib/browser/api/share-menu.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { BrowserWindow, Menu, SharingItem, PopupOptions } from 'electron/main';
import { EventEmitter } from 'events';

class ShareMenu {
class ShareMenu extends EventEmitter implements Electron.ShareMenu {
private menu: Menu;

constructor (sharingItem: SharingItem) {
super();
this.menu = new (Menu as any)({ sharingItem });
}

Expand Down
2 changes: 1 addition & 1 deletion lib/browser/api/utility-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Socket } from 'net';
import { MessagePortMain } from '@electron/internal/browser/message-port-main';
const { _fork } = process._linkedBinding('electron_browser_utility_process');

class ForkUtilityProcess extends EventEmitter {
class ForkUtilityProcess extends EventEmitter implements Electron.UtilityProcess {
#handle: ElectronInternal.UtilityProcessWrapper | null;
#stdout: Duplex | null = null;
#stderr: Duplex | null = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/ipc-main-impl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter } from 'events';
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();

constructor () {
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/message-port-main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'events';

export class MessagePortMain extends EventEmitter {
export class MessagePortMain extends EventEmitter implements Electron.MessagePortMain {
_internalPort: any;
constructor (internalPort: any) {
super();
Expand Down
2 changes: 1 addition & 1 deletion lib/utility/parent-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
import { MessagePortMain } from '@electron/internal/browser/message-port-main';
const { createParentPort } = process._linkedBinding('electron_utility_parent_port');

export class ParentPort extends EventEmitter {
export class ParentPort extends EventEmitter implements Electron.ParentPort {
#port: ParentPort;
constructor () {
super();
Expand Down
10 changes: 5 additions & 5 deletions spec/api-autoupdater-darwin-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,11 @@ ifdescribe(process.platform === 'darwin' && !(process.env.CI && process.arch ===
});

it('should compare version numbers correctly', () => {
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.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', '0.32.0')).to.equal(false);
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.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', '0.32.0')).to.equal(false);
});
});

Expand Down
2 changes: 1 addition & 1 deletion typings/internal-electron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ declare namespace Electron {
}

interface AutoUpdater {
isVersionAllowedForUpdate(currentVersion: string, targetVersion: string): boolean;
isVersionAllowedForUpdate?(currentVersion: string, targetVersion: string): boolean;
}

type TouchBarItemType = NonNullable<Electron.TouchBarConstructorOptions['items']>[0];
Expand Down

0 comments on commit 3c0d491

Please sign in to comment.