Skip to content

Commit 8571e1a

Browse files
authored
No more enums (#84)
* Proof of concept for the no-more-TS-enums thing * Migrated a couple more shared enums * No more enums at all
1 parent f1e0004 commit 8571e1a

File tree

15 files changed

+292
-254
lines changed

15 files changed

+292
-254
lines changed

electron/CommsSetup.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IsOnlyMetadata } from '@freik/audiodb';
22
import { Comms, Shell } from '@freik/electron-main';
3-
import { IpcId, isIgnoreItemFn, isXcodeInfo } from '@freik/emp-shared';
3+
import { IpcId, isIgnoreItem, isXcodeInfo } from '@freik/emp-shared';
44
import { MakeLog } from '@freik/logger';
55
import { MediaKey } from '@freik/media-core';
66
import {
@@ -184,10 +184,6 @@ export function CommsSetup(): void {
184184

185185
// Ignore list stuff:
186186
Comms.registerChannel(IpcId.GetIgnoreList, GetIgnoreList, isVoid);
187-
Comms.registerChannel(IpcId.AddIgnoreItem, AddIgnoreItem, isIgnoreItemFn);
188-
Comms.registerChannel(
189-
IpcId.RemoveIgnoreItem,
190-
RemoveIgnoreItem,
191-
isIgnoreItemFn,
192-
);
187+
Comms.registerChannel(IpcId.AddIgnoreItem, AddIgnoreItem, isIgnoreItem);
188+
Comms.registerChannel(IpcId.RemoveIgnoreItem, RemoveIgnoreItem, isIgnoreItem);
193189
}

electron/SendToUI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Comms } from '@freik/electron-main';
2-
import { IpcId } from '@freik/emp-shared';
2+
import { IpcIdEnum } from '@freik/emp-shared';
33
import { MakeLog } from '@freik/logger';
44

55
const { log } = MakeLog('EMP:main:SendToUI');
66

77
// This is for one-way comms to the UI process
88

9-
export function SendToUI<T>(name: IpcId, data: T) {
9+
export function SendToUI<T>(name: IpcIdEnum, data: T) {
1010
const obj: { [key: string]: T } = {};
1111
obj[name] = data;
1212
log(`Sending ${name} with data:`);

electron/Transcoding.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
IpcId,
33
TranscodeInfo,
4-
TranscodeSourceType,
4+
TranscodeSource,
55
TranscodeState,
66
} from '@freik/emp-shared';
77
import { MakeLog } from '@freik/logger';
@@ -44,23 +44,22 @@ function reQuote(str: string): { [key: string]: string } {
4444
return JSON.parse(res) as { [key: string]: string };
4545
}
4646

47-
/// vvvv Hurray for a Typescript compiler bug
48-
49-
enum XcodeResCode {
50-
alreadyExists,
51-
mediaInfoFailure,
52-
encodeFailure,
53-
unknownError,
54-
alreadyLowBitRate,
55-
success,
56-
}
47+
const XcodeResCode = Object.freeze({
48+
alreadyExists: 0,
49+
mediaInfoFailure: 1,
50+
encodeFailure: 2,
51+
unknownError: 3,
52+
alreadyLowBitRate: 4,
53+
success: 5,
54+
} as const);
55+
type XcodeResCodeEnum = (typeof XcodeResCode)[keyof typeof XcodeResCode];
5756

5857
type TranscodeResult = {
59-
code: XcodeResCode;
58+
code: XcodeResCodeEnum;
6059
message: string;
6160
};
6261

63-
const tr = (code: XcodeResCode, message: string) => ({ code, message });
62+
const tr = (code: XcodeResCodeEnum, message: string) => ({ code, message });
6463
let bitrate = 163840;
6564

6665
export async function toMp4Async(
@@ -246,7 +245,7 @@ async function getFullSongPathFromSettings(
246245
settings: TranscodeInfo,
247246
file: string,
248247
): Promise<[string, string] | void> {
249-
if (settings.source.type === TranscodeSourceType.Disk) {
248+
if (settings.source.type === TranscodeSource.Disk) {
250249
const srcdir = settings.source.loc;
251250
if (!path.normalize(file).startsWith(srcdir)) {
252251
reportFailure(file, `${file} doesn't match ${srcdir}`);
@@ -505,29 +504,29 @@ export async function startTranscode(settings: TranscodeInfo): Promise<void> {
505504
startStatusReporting();
506505
try {
507506
const workQueue: string[] = [];
508-
if (settings.source.type === TranscodeSourceType.Disk) {
507+
if (settings.source.type === TranscodeSource.Disk) {
509508
await ScanSourceFromDisk(settings, workQueue);
510509
} else {
511510
// TODO: Handle artwork for this stuff
512511
const db = await GetAudioDB();
513512
switch (settings.source.type) {
514-
case TranscodeSourceType.Album: {
513+
case TranscodeSource.Album: {
515514
const album = db.getAlbum(settings.source.loc);
516515
if (album) {
517516
workQueue.push(...album.songs);
518517
}
519518
// TODO: Report no such album
520519
break;
521520
}
522-
case TranscodeSourceType.Artist: {
521+
case TranscodeSource.Artist: {
523522
const artist = db.getArtist(settings.source.loc);
524523
if (artist) {
525524
workQueue.push(...artist.songs);
526525
}
527526
// TODO: Report no such album
528527
break;
529528
}
530-
case TranscodeSourceType.Playlist:
529+
case TranscodeSource.Playlist:
531530
workQueue.push(...(await LoadPlaylist(settings.source.loc)));
532531
break;
533532
}

0 commit comments

Comments
 (0)