-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathRunDefMac.tsx
64 lines (61 loc) · 1.96 KB
/
RunDefMac.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {useEffect, useState} from "react";
import {
type EmulatorCDROMLibrary,
type EmulatorCDROM,
} from "./emulator/emulator-common";
import {fetchCDROMInfo} from "./cdroms";
import cdromsManifest from "./Data/CD-ROMs.json";
import {type RunDef} from "./run-def";
import Mac from "./Mac";
export default function RunDefMac({
runDef,
onDone,
}: {
runDef: RunDef;
onDone: () => void;
}) {
const [cdroms, setCDROMs] = useState<EmulatorCDROM[] | undefined>(
runDef.cdromURLs.length ? undefined : []
);
const [cdromErrorText, setCDROMErrorText] = useState<string | undefined>(
undefined
);
useEffect(() => {
if (runDef.cdromURLs.length) {
Promise.all(runDef.cdromURLs.map(getCDROMInfo))
.then(setCDROMs)
.catch(error => {
setCDROMErrorText(`Could not load the CD-ROM: ${error}`);
setCDROMs([]);
});
}
}, [runDef.cdromURLs]);
runDef.disks.forEach(disk => disk.generatedSpec()); // Prefetch the disk definition
return cdroms ? (
<Mac
disks={runDef.disks}
includeInfiniteHD={runDef.includeInfiniteHD}
cdroms={cdroms}
initialErrorText={cdromErrorText}
machine={runDef.machine}
ramSize={runDef.ramSize}
ethernetProvider={runDef.ethernetProvider}
debugFallback={runDef.debugFallback}
debugAudio={runDef.debugAudio}
cdromLibrary={cdromLibrary}
onDone={onDone}
/>
) : (
<div style={{color: "#aaa"}}>Loading CD-ROM Metadata…</div>
);
}
const cdromLibrary: EmulatorCDROMLibrary = cdromsManifest as any;
async function getCDROMInfo(url: string): Promise<EmulatorCDROM> {
const libraryCDROM = Object.values(cdromLibrary).find(
cdrom => cdrom.srcUrl === url
);
if (libraryCDROM) {
return libraryCDROM;
}
return fetchCDROMInfo(url);
}