Skip to content

Commit

Permalink
No more enums (#84)
Browse files Browse the repository at this point in the history
* Proof of concept for the no-more-TS-enums thing

* Migrated a couple more shared enums

* No more enums at all
  • Loading branch information
kevinfrei authored Jul 14, 2024
1 parent f1e0004 commit 8571e1a
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 254 deletions.
10 changes: 3 additions & 7 deletions electron/CommsSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsOnlyMetadata } from '@freik/audiodb';
import { Comms, Shell } from '@freik/electron-main';
import { IpcId, isIgnoreItemFn, isXcodeInfo } from '@freik/emp-shared';
import { IpcId, isIgnoreItem, isXcodeInfo } from '@freik/emp-shared';
import { MakeLog } from '@freik/logger';
import { MediaKey } from '@freik/media-core';
import {
Expand Down Expand Up @@ -184,10 +184,6 @@ export function CommsSetup(): void {

// Ignore list stuff:
Comms.registerChannel(IpcId.GetIgnoreList, GetIgnoreList, isVoid);
Comms.registerChannel(IpcId.AddIgnoreItem, AddIgnoreItem, isIgnoreItemFn);
Comms.registerChannel(
IpcId.RemoveIgnoreItem,
RemoveIgnoreItem,
isIgnoreItemFn,
);
Comms.registerChannel(IpcId.AddIgnoreItem, AddIgnoreItem, isIgnoreItem);
Comms.registerChannel(IpcId.RemoveIgnoreItem, RemoveIgnoreItem, isIgnoreItem);
}
4 changes: 2 additions & 2 deletions electron/SendToUI.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Comms } from '@freik/electron-main';
import { IpcId } from '@freik/emp-shared';
import { IpcIdEnum } from '@freik/emp-shared';
import { MakeLog } from '@freik/logger';

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

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

export function SendToUI<T>(name: IpcId, data: T) {
export function SendToUI<T>(name: IpcIdEnum, data: T) {
const obj: { [key: string]: T } = {};
obj[name] = data;
log(`Sending ${name} with data:`);
Expand Down
35 changes: 17 additions & 18 deletions electron/Transcoding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
IpcId,
TranscodeInfo,
TranscodeSourceType,
TranscodeSource,
TranscodeState,
} from '@freik/emp-shared';
import { MakeLog } from '@freik/logger';
Expand Down Expand Up @@ -44,23 +44,22 @@ function reQuote(str: string): { [key: string]: string } {
return JSON.parse(res) as { [key: string]: string };
}

/// vvvv Hurray for a Typescript compiler bug

enum XcodeResCode {
alreadyExists,
mediaInfoFailure,
encodeFailure,
unknownError,
alreadyLowBitRate,
success,
}
const XcodeResCode = Object.freeze({
alreadyExists: 0,
mediaInfoFailure: 1,
encodeFailure: 2,
unknownError: 3,
alreadyLowBitRate: 4,
success: 5,
} as const);
type XcodeResCodeEnum = (typeof XcodeResCode)[keyof typeof XcodeResCode];

type TranscodeResult = {
code: XcodeResCode;
code: XcodeResCodeEnum;
message: string;
};

const tr = (code: XcodeResCode, message: string) => ({ code, message });
const tr = (code: XcodeResCodeEnum, message: string) => ({ code, message });
let bitrate = 163840;

export async function toMp4Async(
Expand Down Expand Up @@ -246,7 +245,7 @@ async function getFullSongPathFromSettings(
settings: TranscodeInfo,
file: string,
): Promise<[string, string] | void> {
if (settings.source.type === TranscodeSourceType.Disk) {
if (settings.source.type === TranscodeSource.Disk) {
const srcdir = settings.source.loc;
if (!path.normalize(file).startsWith(srcdir)) {
reportFailure(file, `${file} doesn't match ${srcdir}`);
Expand Down Expand Up @@ -505,29 +504,29 @@ export async function startTranscode(settings: TranscodeInfo): Promise<void> {
startStatusReporting();
try {
const workQueue: string[] = [];
if (settings.source.type === TranscodeSourceType.Disk) {
if (settings.source.type === TranscodeSource.Disk) {
await ScanSourceFromDisk(settings, workQueue);
} else {
// TODO: Handle artwork for this stuff
const db = await GetAudioDB();
switch (settings.source.type) {
case TranscodeSourceType.Album: {
case TranscodeSource.Album: {
const album = db.getAlbum(settings.source.loc);
if (album) {
workQueue.push(...album.songs);
}
// TODO: Report no such album
break;
}
case TranscodeSourceType.Artist: {
case TranscodeSource.Artist: {
const artist = db.getArtist(settings.source.loc);
if (artist) {
workQueue.push(...artist.songs);
}
// TODO: Report no such album
break;
}
case TranscodeSourceType.Playlist:
case TranscodeSource.Playlist:
workQueue.push(...(await LoadPlaylist(settings.source.loc)));
break;
}
Expand Down
Loading

0 comments on commit 8571e1a

Please sign in to comment.