Skip to content

Commit 52778da

Browse files
committed
TS: some minor cleaning up.
1 parent 097d022 commit 52778da

24 files changed

+191
-203
lines changed

src/extern/corsProxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
const url = new URL(request.url);
99
const targetUrl = url.searchParams.get('url');
1010

11-
if (targetUrl === null) {
11+
if (!targetUrl) {
1212
return new Response('Missing "url" query parameter.', { status: 400 });
1313
}
1414

src/main/MainMenu.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ let hasFiles = false;
1313
export function enableDisableMainMenu(enable: boolean): void {
1414
// Build our menu, if needed.
1515

16-
if (enable && enabledMenu !== null) {
16+
if (enable && enabledMenu) {
1717
electron.Menu.setApplicationMenu(enabledMenu);
18-
} else if (!enable && disabledMenu !== null) {
18+
} else if (!enable && disabledMenu) {
1919
electron.Menu.setApplicationMenu(disabledMenu);
2020
} else {
2121
// Some common menu items.
@@ -58,7 +58,7 @@ export function enableDisableMainMenu(enable: boolean): void {
5858
if (enable) {
5959
appSubMenu.push(aboutOpencorMenuItem);
6060

61-
if (checkForUpdatesMenuItem !== null) {
61+
if (checkForUpdatesMenuItem) {
6262
appSubMenu.push({ type: 'separator' });
6363
appSubMenu.push(checkForUpdatesMenuItem);
6464
}
@@ -129,7 +129,7 @@ export function enableDisableMainMenu(enable: boolean): void {
129129
enabled: recentFilePaths.length > 0
130130
});
131131

132-
if (recentFilePaths.length > 0) {
132+
if (recentFilePaths.length) {
133133
fileReopenSubMenu.push({ type: 'separator' });
134134

135135
recentFilePaths.forEach((filePath: string) => {
@@ -258,7 +258,7 @@ export function enableDisableMainMenu(enable: boolean): void {
258258
});
259259

260260
if (!isMacOs()) {
261-
if (checkForUpdatesMenuItem !== null) {
261+
if (checkForUpdatesMenuItem) {
262262
helpSubMenu.push({ type: 'separator' });
263263
helpSubMenu.push(checkForUpdatesMenuItem);
264264
}
@@ -298,13 +298,13 @@ export function enableDisableMainMenu(enable: boolean): void {
298298
}
299299

300300
export function enableDisableFileCloseAndCloseAllMenuItems(enable: boolean): void {
301-
if (enabledMenu !== null) {
301+
if (enabledMenu) {
302302
hasFiles = enable;
303303

304304
const fileCloseMenu = enabledMenu.getMenuItemById('fileClose');
305305
const fileCloseAllMenu = enabledMenu.getMenuItemById('fileCloseAll');
306306

307-
if (fileCloseMenu !== null && fileCloseAllMenu !== null) {
307+
if (fileCloseMenu && fileCloseAllMenu) {
308308
fileCloseMenu.enabled = hasFiles;
309309
fileCloseAllMenu.enabled = hasFiles;
310310
}

src/main/MainWindow.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ let openedFilePaths: string[] = [];
123123
export function filesOpened(filePaths: string[]): void {
124124
openedFilePaths = filePaths;
125125

126-
if (filePaths.length === 0) {
126+
if (!filePaths.length) {
127127
selectedFilePath = null;
128128
}
129129
}
@@ -201,7 +201,7 @@ export class MainWindow extends ApplicationWindow {
201201
// case we filter out all null entries.
202202

203203
recentFilePaths = (electronConf.get('app.files.recent') as string[]).filter(
204-
(filePath: string | null) => filePath !== null
204+
(filePath: string | null) => filePath
205205
);
206206

207207
updateReopenMenu(recentFilePaths);
@@ -222,7 +222,7 @@ export class MainWindow extends ApplicationWindow {
222222

223223
commandLine.shift();
224224

225-
if (!isPackaged() && commandLine.length > 0) {
225+
if (!isPackaged() && commandLine.length) {
226226
commandLine.shift();
227227
}
228228
}
@@ -352,19 +352,19 @@ export class MainWindow extends ApplicationWindow {
352352
// reopen. So, we need to wait for the file to be reopened before reopening the next one.
353353

354354
reopenFilePathsAndSelectFilePath(): void {
355-
if (this._openedFilePaths.length > 0) {
355+
if (this._openedFilePaths.length) {
356356
const filePath = this._openedFilePaths[0];
357357

358358
this.webContents.send('open', filePath);
359359

360360
this._openedFilePaths = this._openedFilePaths.slice(1);
361361

362-
if (this._openedFilePaths.length > 0) {
362+
if (this._openedFilePaths.length) {
363363
return;
364364
}
365365
}
366366

367-
if (this._selectedFilePath !== '') {
367+
if (this._selectedFilePath) {
368368
this.webContents.send('select', this._selectedFilePath);
369369

370370
this._selectedFilePath = '';
@@ -374,15 +374,15 @@ export class MainWindow extends ApplicationWindow {
374374
// Handle our command line arguments.
375375

376376
isAction(argument: string | undefined): boolean {
377-
if (argument === undefined) {
377+
if (!argument) {
378378
return false;
379379
}
380380

381381
return argument.startsWith(FULL_URI_SCHEME);
382382
}
383383

384384
handleArguments(commandLine: string[]): void {
385-
if (commandLine.length === 0) {
385+
if (!commandLine.length) {
386386
return;
387387
}
388388

src/main/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ if (!electron.app.requestSingleInstanceLock()) {
7373
export let mainWindow: MainWindow | null = null;
7474

7575
electron.app.on('second-instance', (_event, argv) => {
76-
if (mainWindow !== null) {
76+
if (mainWindow) {
7777
if (mainWindow.isMinimized()) {
7878
mainWindow.restore();
7979
}
@@ -123,7 +123,7 @@ MimeType=x-scheme-handler/${URI_SCHEME}`
123123
// Update the desktop database.
124124

125125
nodeChildProcess.exec('update-desktop-database ~/.local/share/applications', (error) => {
126-
if (error !== null) {
126+
if (error) {
127127
console.error('Failed to update the desktop database:', error);
128128
}
129129
});
@@ -271,11 +271,9 @@ electron.app
271271
// triggering URL.
272272

273273
mainWindow = new MainWindow(
274-
triggeringUrl !== null ? [triggeringUrl] : process.argv,
274+
triggeringUrl ? [triggeringUrl] : process.argv,
275275
splashScreenWindow,
276-
process.env.ELECTRON_RENDERER_URL !== undefined
277-
? process.env.ELECTRON_RENDERER_URL
278-
: await startRendererServer()
276+
process.env.ELECTRON_RENDERER_URL ?? (await startRendererServer())
279277
);
280278
}, SHORT_DELAY);
281279
});

src/renderer/src/common/common.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,24 @@ export function formatTime(time: number): string {
7979
const d = Math.floor((time / (1000 * 60 * 60 * 24)) % 24);
8080
let res = '';
8181

82-
if (d !== 0 || ((h !== 0 || m !== 0 || s !== 0 || ms !== 0) && res !== '')) {
83-
res += `${res === '' ? '' : ' '}${String(d)}d`;
82+
if (d) {
83+
res += `${String(d)}d`;
8484
}
8585

86-
if (h !== 0 || ((m !== 0 || s !== 0 || ms !== 0) && res !== '')) {
87-
res += `${res === '' ? '' : ' '}${String(h)}h`;
86+
if (h || ((m || s || ms) && res)) {
87+
res += `${res ? ' ' : ''}${String(h)}h`;
8888
}
8989

90-
if (m !== 0 || ((s !== 0 || ms !== 0) && res !== '')) {
91-
res += `${res === '' ? '' : ' '}${String(m)}m`;
90+
if (m || ((s || ms) && res)) {
91+
res += `${res ? ' ' : ''}${String(m)}m`;
9292
}
9393

94-
if (s !== 0 || (ms !== 0 && res !== '')) {
95-
res += `${res === '' ? '' : ' '}${String(s)}s`;
94+
if (s || (ms && res)) {
95+
res += `${res ? ' ' : ''}${String(s)}s`;
9696
}
9797

98-
if (ms !== 0 || res === '') {
99-
res += `${res === '' ? '' : ' '}${String(ms)}ms`;
98+
if (ms || !res) {
99+
res += `${res ? ' ' : ''}${String(ms)}ms`;
100100
}
101101

102102
return res;

src/renderer/src/common/firebaseConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const firebaseEnvVarMap = {
1818

1919
export function missingFirebaseKeys(): string[] {
2020
function missingFirebaseKey(firebaseValue: unknown): boolean {
21-
return firebaseValue === undefined || firebaseValue === null || firebaseValue === '';
21+
return !firebaseValue;
2222
}
2323

2424
return (Object.entries(firebaseEnvVarMap) as Array<[keyof typeof firebaseEnvVarMap, string]>)

src/renderer/src/common/gitHubIntegration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function gitHubAccessTokenEntry(): AsyncEntry | null {
4444
export async function deleteGitHubAccessToken(): Promise<boolean> {
4545
const entry = gitHubAccessTokenEntry();
4646

47-
if (entry === null) {
47+
if (!entry) {
4848
return false;
4949
}
5050

@@ -60,7 +60,7 @@ export async function deleteGitHubAccessToken(): Promise<boolean> {
6060
export async function loadGitHubAccessToken(): Promise<string | null> {
6161
const entry = gitHubAccessTokenEntry();
6262

63-
if (entry === null) {
63+
if (!entry) {
6464
return null;
6565
}
6666

@@ -76,15 +76,15 @@ export async function loadGitHubAccessToken(): Promise<string | null> {
7676
}
7777

7878
export async function saveGitHubAccessToken(token: string): Promise<boolean> {
79-
if (token.trim() === '') {
79+
if (!token.trim()) {
8080
console.warn('Ignoring request to store an empty GitHub access token.');
8181

8282
return false;
8383
}
8484

8585
const entry = gitHubAccessTokenEntry();
8686

87-
if (entry === null) {
87+
if (!entry) {
8888
return false;
8989
}
9090

src/renderer/src/common/locCommon.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function isRemoteFilePath(filePath: string): boolean {
1111

1212
export function filePath(fileFilePathOrFileContents: string | Uint8Array | File): string {
1313
return fileFilePathOrFileContents instanceof File
14-
? electronApi !== undefined
14+
? electronApi
1515
? electronApi.filePath(fileFilePathOrFileContents)
1616
: fileFilePathOrFileContents.name
1717
: typeof fileFilePathOrFileContents === 'string'
@@ -65,7 +65,7 @@ export function file(fileFilePathOrFileContents: string | Uint8Array | File): Pr
6565
}
6666

6767
return new Promise((resolve, reject) => {
68-
if (electronApi !== undefined) {
68+
if (electronApi) {
6969
resolve(new locApi.File(filePath(fileFilePathOrFileContents)));
7070
} else {
7171
reject(new Error('Local files cannot be opened.'));
@@ -111,7 +111,7 @@ export interface ISimulationDataInfo {
111111
}
112112

113113
export function simulationDataInfo(instanceTask: locApi.SedInstanceTask, name: string): ISimulationDataInfo {
114-
if (name === '') {
114+
if (!name) {
115115
return {
116116
type: ESimulationDataInfoType.UNKNOWN,
117117
index: -1

src/renderer/src/common/rendererServer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let rendererBaseUrl: string | null = null;
1414
export async function startRendererServer(): Promise<string> {
1515
// If we already have a base URL then return it.
1616

17-
if (rendererBaseUrl !== null) {
17+
if (rendererBaseUrl) {
1818
return rendererBaseUrl;
1919
}
2020

@@ -74,7 +74,7 @@ export async function startRendererServer(): Promise<string> {
7474
rendererServer?.listen(0, rendererHost, () => {
7575
const addressInfo = rendererServer?.address() as AddressInfo | null;
7676

77-
if (addressInfo?.port !== undefined) {
77+
if (addressInfo?.port) {
7878
rendererBaseUrl = `http://${rendererHost}:${addressInfo.port}`;
7979

8080
resolve();
@@ -84,7 +84,7 @@ export async function startRendererServer(): Promise<string> {
8484
});
8585
});
8686

87-
if (rendererBaseUrl === null) {
87+
if (!rendererBaseUrl) {
8888
throw new Error('Failed to initialise the renderer server.');
8989
}
9090

@@ -94,7 +94,7 @@ export async function startRendererServer(): Promise<string> {
9494
export async function stopRendererServer(): Promise<void> {
9595
// Make sure that we have a server to stop.
9696

97-
if (rendererServer === null) {
97+
if (!rendererServer) {
9898
return;
9999
}
100100

src/renderer/src/common/settings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Settings {
4242
}
4343

4444
load(): void {
45-
if (electronApi !== undefined) {
45+
if (electronApi) {
4646
void electronApi.loadSettings().then((settings: ISettings) => {
4747
this._settings = settings;
4848

@@ -52,7 +52,7 @@ class Settings {
5252
try {
5353
const raw = window.localStorage.getItem('settings');
5454

55-
if (raw !== null) {
55+
if (raw) {
5656
this._settings = JSON.parse(raw);
5757
}
5858
} catch (error: unknown) {
@@ -66,7 +66,7 @@ class Settings {
6666
}
6767

6868
save(): void {
69-
if (electronApi !== undefined) {
69+
if (electronApi) {
7070
electronApi.saveSettings(this._settings);
7171
} else {
7272
try {

0 commit comments

Comments
 (0)