Skip to content

Commit cc82611

Browse files
committed
refactor: Move globals, import types, add return types
1 parent 7b67bd8 commit cc82611

21 files changed

Lines changed: 172 additions & 249 deletions
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
*
1818
*/
1919

20-
import {DesktopCapturer} from 'electron';
20+
import type {DesktopCapturer} from 'electron';
2121
import type {WebAppEvents} from '@wireapp/webapp-events';
22-
import {Data as OpenGraphResult} from 'open-graph';
22+
import type {Data as OpenGraphResult} from 'open-graph';
2323

24-
import * as EnvironmentUtil from '../runtime/EnvironmentUtil';
25-
import {i18nStrings} from './locale';
26-
import {Schemata} from './main';
24+
import type * as EnvironmentUtil from './runtime/EnvironmentUtil';
25+
import type {i18nStrings} from './locale/locale';
2726

2827
declare global {
2928
interface Window {
@@ -57,7 +56,7 @@ declare global {
5756

5857
namespace NodeJS {
5958
interface Global {
60-
_ConfigurationPersistence: Schemata;
59+
_ConfigurationPersistence: Record<string, any>;
6160
desktopCapturer: DesktopCapturer;
6261
environment: typeof EnvironmentUtil;
6362
openGraphAsync(url: string): Promise<OpenGraphResult>;

‎electron/src/interfaces/index.ts‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎electron/src/interfaces/locale.ts‎

Lines changed: 0 additions & 113 deletions
This file was deleted.

‎electron/src/interfaces/main.ts‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎electron/src/lib/CertificateVerifyProcManager.ts‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,31 @@ interface DisplayCertificateErrorOptions {
3535
}
3636

3737
enum CertificateVerificationResult {
38-
SUCCESS = 0, // Indicates success and disables Certificate Transparency verification
38+
/** Indicates success and disables Certificate Transparency verification */
39+
SUCCESS = 0,
3940
FAILURE = -2,
4041
USE_CHROMIUM_VALIDATION = -3,
4142
}
4243

44+
enum CHROMIUM_ERRORS {
45+
CERT_AUTHORITY_INVALID = -202,
46+
CERT_COMMON_NAME_INVALID = -200,
47+
}
48+
49+
enum RESPONSE {
50+
GO_BACK = 0,
51+
RETRY = 0,
52+
SAVE_CERTIFICATE = 1,
53+
SHOW_DETAILS = 1,
54+
}
55+
4356
class CertificateVerifyProcManager {
4457
private static bypassCertificatePinning = false;
4558
private static isDialogLocked = false;
4659
public static mainWindow: BrowserWindow;
4760

4861
private static readonly dialogUnlockTimeout = 6000;
4962

50-
public static readonly CHROMIUM_ERRORS = {
51-
CERT_AUTHORITY_INVALID: -202,
52-
CERT_COMMON_NAME_INVALID: -200,
53-
};
54-
55-
private static readonly RESPONSE = {
56-
GO_BACK: 0,
57-
RETRY: 0,
58-
SAVE_CERTIFICATE: 1,
59-
SHOW_DETAILS: 1,
60-
};
61-
6263
private static readonly LOCALE = {
6364
RETRY: getText('certificateVerifyProcManagerRetry'),
6465
SHOW_DETAILS: getText('certificateVerifyProcManagerShowDetails'),
@@ -78,7 +79,7 @@ class CertificateVerifyProcManager {
7879
certificate: Certificate,
7980
options: DisplayCertificateErrorOptions,
8081
): Promise<void> {
81-
const goBack = async () => {
82+
const goBack = async (): Promise<void> => {
8283
// Go back to the dialog
8384
await this.displayCertificateError(hostname, certificate, {
8485
...options,
@@ -101,13 +102,13 @@ class CertificateVerifyProcManager {
101102
// For Linux and Windows, use a message box with the ability to save the certificate
102103
const {response} = await dialog.showMessageBox(this.mainWindow, {
103104
buttons: [this.LOCALE.SHOW_DETAILS_GO_BACK, this.LOCALE.SHOW_DETAILS_SAVE_CERTIFICATE],
104-
cancelId: this.RESPONSE.GO_BACK,
105+
cancelId: RESPONSE.GO_BACK,
105106
detail: textDetails,
106107
message: this.LOCALE.SHOW_DETAILS_TITLE,
107108
type: 'info',
108109
});
109110
switch (response) {
110-
case this.RESPONSE.SAVE_CERTIFICATE: {
111+
case RESPONSE.SAVE_CERTIFICATE: {
111112
const {filePath: chosenPath} = await dialog.showSaveDialog(this.mainWindow, {
112113
defaultPath: `${hostname}.pem`,
113114
});
@@ -118,7 +119,7 @@ class CertificateVerifyProcManager {
118119
await this.displayCertificateDetails(hostname, certificate, options);
119120
break;
120121
}
121-
case this.RESPONSE.GO_BACK: {
122+
case RESPONSE.GO_BACK: {
122123
await goBack();
123124
break;
124125
}
@@ -152,16 +153,16 @@ class CertificateVerifyProcManager {
152153

153154
const {checkboxChecked, response} = await dialog.showMessageBox(this.mainWindow, {
154155
buttons: [this.LOCALE.RETRY, this.LOCALE.SHOW_DETAILS],
155-
cancelId: this.RESPONSE.RETRY,
156+
cancelId: RESPONSE.RETRY,
156157
checkboxChecked: isChromiumError ? undefined : isCheckboxChecked,
157158
checkboxLabel: isChromiumError ? undefined : this.LOCALE.WARNING_BYPASS,
158-
defaultId: this.RESPONSE.RETRY,
159+
defaultId: RESPONSE.RETRY,
159160
detail: isChromiumError ? this.LOCALE.WARNING_TEXT_CHROMIUM : this.LOCALE.WARNING_TEXT_PINNING,
160161
message: this.LOCALE.WARNING_TITLE,
161162
type: 'warning',
162163
});
163164
switch (response) {
164-
case this.RESPONSE.RETRY: {
165+
case RESPONSE.RETRY: {
165166
if (!isChromiumError) {
166167
this.bypassCertificatePinning = checkboxChecked;
167168
if (this.bypassCertificatePinning) {
@@ -174,7 +175,7 @@ class CertificateVerifyProcManager {
174175
break;
175176
}
176177

177-
case this.RESPONSE.SHOW_DETAILS: {
178+
case RESPONSE.SHOW_DETAILS: {
178179
await this.displayCertificateDetails(hostname, certificate, {
179180
bypassDialogLock,
180181
isCheckboxChecked: checkboxChecked,
@@ -186,14 +187,14 @@ class CertificateVerifyProcManager {
186187
}
187188
}
188189

189-
export const attachTo = (main: BrowserWindow) => {
190+
export const attachTo = (main: BrowserWindow): void => {
190191
CertificateVerifyProcManager.mainWindow = main;
191192
};
192193

193194
export const setCertificateVerifyProc = async (
194195
request: CertificateVerifyProcProcRequest,
195196
cb: (verificationResult: number) => void,
196-
) => {
197+
): Promise<void> => {
197198
const {hostname, validatedCertificate, verificationResult, errorCode} = request;
198199
// Check browser results
199200
if (verificationResult !== 'net::OK') {
@@ -202,8 +203,7 @@ export const setCertificateVerifyProc = async (
202203
);
203204

204205
const isCommonCertificateError =
205-
errorCode === CertificateVerifyProcManager.CHROMIUM_ERRORS.CERT_COMMON_NAME_INVALID ||
206-
errorCode === CertificateVerifyProcManager.CHROMIUM_ERRORS.CERT_AUTHORITY_INVALID;
206+
errorCode === CHROMIUM_ERRORS.CERT_COMMON_NAME_INVALID || errorCode === CHROMIUM_ERRORS.CERT_AUTHORITY_INVALID;
207207
if (isCommonCertificateError) {
208208
await CertificateVerifyProcManager.displayCertificateChromiumError(hostname, validatedCertificate);
209209
}

‎electron/src/lib/download.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import {DateUtil} from '@wireapp/commons';
2121
import {dialog, SaveDialogOptions} from 'electron';
22-
import * as fs from 'fs-extra';
2322
import imageType from 'image-type';
23+
import * as fs from 'fs-extra';
2424
import * as path from 'path';
2525

2626
import {getLogger} from '../logging/getLogger';
@@ -40,7 +40,7 @@ export const downloadLogs = async (bytes: Uint8Array, timestamp: Date = new Date
4040
return downloadFile(bytes, filename, options);
4141
};
4242

43-
export const downloadImage = async (bytes: Uint8Array, timestamp?: string) => {
43+
export const downloadImage = async (bytes: Uint8Array, timestamp?: string): Promise<void> => {
4444
const type = imageType(bytes);
4545
const options: SaveDialogOptions = {};
4646

@@ -59,7 +59,7 @@ export const downloadImage = async (bytes: Uint8Array, timestamp?: string) => {
5959
return downloadFile(bytes, filename, options);
6060
};
6161

62-
export const downloadFile = async (bytes: Uint8Array, filename: string, options?: SaveDialogOptions) => {
62+
export const downloadFile = async (bytes: Uint8Array, filename: string, options?: SaveDialogOptions): Promise<void> => {
6363
try {
6464
const {filePath: chosenPath} = await dialog.showSaveDialog({defaultPath: filename, ...options});
6565
if (chosenPath) {
@@ -70,7 +70,7 @@ export const downloadFile = async (bytes: Uint8Array, filename: string, options?
7070
}
7171
};
7272

73-
export const suggestFileName = (timestamp?: string) => {
73+
export const suggestFileName = (timestamp?: string): string => {
7474
const imageDate = timestamp ? new Date(Number(timestamp)) : new Date();
7575
const {date: formattedDate, time: formattedTime} = DateUtil.isoFormat(imageDate);
7676
return `Wire ${formattedDate} at ${formattedTime}`.replace(/:/g, '-');

‎electron/src/lib/openGraph.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {parse as parseContentType, ParsedMediaType} from 'content-type';
2222
import {IncomingMessage} from 'http';
2323
import {decode as iconvDecode} from 'iconv-lite';
2424
import {Data as OpenGraphResult, parse as openGraphParse} from 'open-graph';
25-
import * as path from 'path';
2625
import {parse as parseUrl} from 'url';
26+
import * as path from 'path';
2727

2828
import {getLogger} from '../logging/getLogger';
2929
import {config} from '../settings/config';

0 commit comments

Comments
 (0)