Migrate to private class properties/methods
This commit is contained in:
@@ -47,7 +47,7 @@ export type AppOptionsType = Readonly<{
|
||||
const WAIT_FOR_EVENT_TIMEOUT = 30 * SECOND;
|
||||
|
||||
export class App extends EventEmitter {
|
||||
private privApp: ElectronApplication | undefined;
|
||||
#privApp: ElectronApplication | undefined;
|
||||
|
||||
constructor(private readonly options: AppOptionsType) {
|
||||
super();
|
||||
@@ -56,7 +56,7 @@ export class App extends EventEmitter {
|
||||
public async start(): Promise<void> {
|
||||
try {
|
||||
// launch the electron processs
|
||||
this.privApp = await electron.launch({
|
||||
this.#privApp = await electron.launch({
|
||||
executablePath: this.options.main,
|
||||
args: this.options.args.slice(),
|
||||
env: {
|
||||
@@ -84,53 +84,53 @@ export class App extends EventEmitter {
|
||||
20 * SECOND
|
||||
);
|
||||
} catch (e) {
|
||||
this.privApp?.process().kill('SIGKILL');
|
||||
this.#privApp?.process().kill('SIGKILL');
|
||||
throw e;
|
||||
}
|
||||
|
||||
this.privApp.on('close', () => this.emit('close'));
|
||||
this.#privApp.on('close', () => this.emit('close'));
|
||||
|
||||
drop(this.printLoop());
|
||||
drop(this.#printLoop());
|
||||
}
|
||||
|
||||
public async waitForProvisionURL(): Promise<string> {
|
||||
return this.waitForEvent('provisioning-url');
|
||||
return this.#waitForEvent('provisioning-url');
|
||||
}
|
||||
|
||||
public async waitForDbInitialized(): Promise<void> {
|
||||
return this.waitForEvent('db-initialized');
|
||||
return this.#waitForEvent('db-initialized');
|
||||
}
|
||||
|
||||
public async waitUntilLoaded(): Promise<AppLoadedInfoType> {
|
||||
return this.waitForEvent('app-loaded');
|
||||
return this.#waitForEvent('app-loaded');
|
||||
}
|
||||
|
||||
public async waitForContactSync(): Promise<void> {
|
||||
return this.waitForEvent('contactSync');
|
||||
return this.#waitForEvent('contactSync');
|
||||
}
|
||||
|
||||
public async waitForBackupImportComplete(): Promise<{ duration: number }> {
|
||||
return this.waitForEvent('backupImportComplete');
|
||||
return this.#waitForEvent('backupImportComplete');
|
||||
}
|
||||
|
||||
public async waitForMessageSend(): Promise<MessageSendInfoType> {
|
||||
return this.waitForEvent('message:send-complete');
|
||||
return this.#waitForEvent('message:send-complete');
|
||||
}
|
||||
|
||||
public async waitForConversationOpen(): Promise<ConversationOpenInfoType> {
|
||||
return this.waitForEvent('conversation:open');
|
||||
return this.#waitForEvent('conversation:open');
|
||||
}
|
||||
|
||||
public async waitForChallenge(): Promise<ChallengeRequestType> {
|
||||
return this.waitForEvent('challenge');
|
||||
return this.#waitForEvent('challenge');
|
||||
}
|
||||
|
||||
public async waitForReceipts(): Promise<ReceiptsInfoType> {
|
||||
return this.waitForEvent('receipts');
|
||||
return this.#waitForEvent('receipts');
|
||||
}
|
||||
|
||||
public async waitForStorageService(): Promise<StorageServiceInfoType> {
|
||||
return this.waitForEvent('storageServiceComplete');
|
||||
return this.#waitForEvent('storageServiceComplete');
|
||||
}
|
||||
|
||||
public async waitForManifestVersion(version: number): Promise<void> {
|
||||
@@ -152,28 +152,28 @@ export class App extends EventEmitter {
|
||||
);
|
||||
}
|
||||
|
||||
private async checkForFatalTestErrors(): Promise<void> {
|
||||
async #checkForFatalTestErrors(): Promise<void> {
|
||||
const count = await this.getPendingEventCount('fatalTestError');
|
||||
if (count === 0) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < count; i += 1) {
|
||||
// eslint-disable-next-line no-await-in-loop, no-console
|
||||
console.error(await this.waitForEvent('fatalTestError'));
|
||||
console.error(await this.#waitForEvent('fatalTestError'));
|
||||
}
|
||||
throw new Error('App had fatal test errors');
|
||||
}
|
||||
|
||||
public async close(): Promise<void> {
|
||||
try {
|
||||
await this.checkForFatalTestErrors();
|
||||
await this.#checkForFatalTestErrors();
|
||||
} finally {
|
||||
await this.app.close();
|
||||
await this.#app.close();
|
||||
}
|
||||
}
|
||||
|
||||
public async getWindow(): Promise<Page> {
|
||||
return this.app.firstWindow();
|
||||
return this.#app.firstWindow();
|
||||
}
|
||||
|
||||
public async openSignalRoute(url: URL | string): Promise<void> {
|
||||
@@ -206,11 +206,11 @@ export class App extends EventEmitter {
|
||||
}
|
||||
|
||||
public async waitForUnlink(): Promise<void> {
|
||||
return this.waitForEvent('unlinkCleanupComplete');
|
||||
return this.#waitForEvent('unlinkCleanupComplete');
|
||||
}
|
||||
|
||||
public async waitForConversationOpenComplete(): Promise<void> {
|
||||
return this.waitForEvent('conversationOpenComplete');
|
||||
return this.#waitForEvent('conversationOpenComplete');
|
||||
}
|
||||
|
||||
// EventEmitter types
|
||||
@@ -245,7 +245,7 @@ export class App extends EventEmitter {
|
||||
// Private
|
||||
//
|
||||
|
||||
private async waitForEvent<T>(
|
||||
async #waitForEvent<T>(
|
||||
event: string,
|
||||
timeout = WAIT_FOR_EVENT_TIMEOUT
|
||||
): Promise<T> {
|
||||
@@ -259,15 +259,15 @@ export class App extends EventEmitter {
|
||||
return result as T;
|
||||
}
|
||||
|
||||
private get app(): ElectronApplication {
|
||||
if (!this.privApp) {
|
||||
get #app(): ElectronApplication {
|
||||
if (!this.#privApp) {
|
||||
throw new Error('Call ElectronWrap.start() first');
|
||||
}
|
||||
|
||||
return this.privApp;
|
||||
return this.#privApp;
|
||||
}
|
||||
|
||||
private async printLoop(): Promise<void> {
|
||||
async #printLoop(): Promise<void> {
|
||||
const kClosed: unique symbol = Symbol('kClosed');
|
||||
const onClose = (async (): Promise<typeof kClosed> => {
|
||||
try {
|
||||
@@ -283,7 +283,7 @@ export class App extends EventEmitter {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const value = await Promise.race([
|
||||
this.waitForEvent<string>('print', 0),
|
||||
this.#waitForEvent<string>('print', 0),
|
||||
onClose,
|
||||
]);
|
||||
|
||||
|
Reference in New Issue
Block a user