@@ -47,13 +47,14 @@ import {
4747import { type ScreenSize } from "./run-def" ;
4848import { viewTransitionNameForDisk } from "./view-transitions" ;
4949import { DrawersContainer } from "./controls/Drawer" ;
50- import { MacLibrary } from "./MacLibrary" ;
50+ import { handleLibraryURL , MacLibrary } from "./MacLibrary" ;
5151
5252export type MacProps = {
5353 disks : SystemDiskDef [ ] ;
5454 includeInfiniteHD : boolean ;
5555 includeSavedHD : boolean ;
5656 includeLibrary : boolean ;
57+ libraryDownloadURLs : string [ ] ;
5758 diskFiles : DiskFile [ ] ;
5859 cdroms : EmulatorCDROM [ ] ;
5960 initialErrorText ?: string ;
@@ -75,6 +76,7 @@ export default function Mac({
7576 includeInfiniteHD,
7677 includeSavedHD,
7778 includeLibrary,
79+ libraryDownloadURLs,
7880 diskFiles,
7981 cdroms,
8082 initialErrorText,
@@ -138,6 +140,35 @@ export default function Mac({
138140
139141 const hasSavedHD = includeSavedHD && canSaveDisks ( ) ;
140142
143+ const handleMacLibraryProgress = useCallback (
144+ ( name : string , fraction : number ) => {
145+ setEmulatorFileLoadingProgress ( {
146+ name,
147+ fraction,
148+ } ) ;
149+ } ,
150+ [ ]
151+ ) ;
152+ const handleMacLibraryRun = useCallback ( ( file : File ) => {
153+ const emulator = emulatorRef . current ;
154+ if ( emulator ) {
155+ setEmulatorFileLoadingProgress ( {
156+ name : file . name ,
157+ fraction : 1.0 ,
158+ linger : true ,
159+ } ) ;
160+ uploadFiles ( emulator , [ file ] , undefined , true ) ;
161+ setTimeout (
162+ ( ) =>
163+ setEmulatorFileLoadingProgress ( {
164+ name : file . name ,
165+ fraction : 1.0 ,
166+ } ) ,
167+ 1000
168+ ) ;
169+ }
170+ } , [ ] ) ;
171+
141172 useEffect ( ( ) => {
142173 const emulatorDisks : EmulatorDiskDef [ ] = [ ...disks ] ;
143174 const delayedDisks : EmulatorDiskDef [ ] = [ ] ;
@@ -199,6 +230,15 @@ export default function Mac({
199230 emulatorDidFinishLoading ( emulator : Emulator ) {
200231 setEmulatorLoaded ( true ) ;
201232 emulator . refreshSettings ( ) ;
233+ if ( emulatorSupportsDownloadsFolder ( machine . emulatorType ) ) {
234+ libraryDownloadURLs . forEach ( url =>
235+ handleLibraryURL (
236+ url ,
237+ handleMacLibraryRun ,
238+ handleMacLibraryProgress
239+ )
240+ ) ;
241+ }
202242 } ,
203243 emulatorDidMakeLoadingProgress (
204244 emulator : Emulator ,
@@ -721,36 +761,8 @@ export default function Mac({
721761 ) && (
722762 < MacLibrary
723763 appearance = { appearance }
724- onLoadProgress = { ( name , fraction ) => {
725- setEmulatorFileLoadingProgress ( {
726- name,
727- fraction,
728- } ) ;
729- } }
730- onRun = { file => {
731- const emulator = emulatorRef . current ;
732- if ( emulator ) {
733- setEmulatorFileLoadingProgress ( {
734- name : file . name ,
735- fraction : 1.0 ,
736- linger : true ,
737- } ) ;
738- uploadFiles (
739- emulator ,
740- [ file ] ,
741- undefined ,
742- true
743- ) ;
744- setTimeout (
745- ( ) =>
746- setEmulatorFileLoadingProgress ( {
747- name : file . name ,
748- fraction : 1.0 ,
749- } ) ,
750- 1000
751- ) ;
752- }
753- } }
764+ onLoadProgress = { handleMacLibraryProgress }
765+ onRun = { handleMacLibraryRun }
754766 />
755767 ) }
756768 </ DrawersContainer >
0 commit comments