@@ -382,11 +382,27 @@ ipcMain.handle('pick-image', async () => {
382382 const { canceled, filePaths } = await dialog . showOpenDialog ( {
383383 title : 'Select cover art' ,
384384 properties : [ 'openFile' ] ,
385- filters : [ { name : 'JPG' , extensions : [ 'jpg' ] } ]
385+ filters : [
386+ {
387+ name : 'Image Files' ,
388+ extensions : [ 'jpg' , 'jpeg' , 'png' , 'webp' ]
389+ } ,
390+ {
391+ name : 'JPEG Images' ,
392+ extensions : [ 'jpg' , 'jpeg' ]
393+ } ,
394+ {
395+ name : 'PNG Images' ,
396+ extensions : [ 'png' ]
397+ } ,
398+ {
399+ name : 'WebP Images' ,
400+ extensions : [ 'webp' ]
401+ }
402+ ]
386403 } ) ;
387404 return canceled ? null : filePaths [ 0 ] ;
388405} ) ;
389-
390406// copy to covers directory
391407ipcMain . handle ( 'save-cover' , async ( _event , src , dest ) => {
392408 return new Promise ( resolve => {
@@ -685,45 +701,67 @@ ipcMain.on('run-command', (event, data) => {
685701 date : new Date ( ) . toISOString ( )
686702 } ;
687703
688- const command = `${ emulator } ${ emulatorArgs || "" } "${ filePath } "` ;
689-
704+ // --- recents handling unchanged ---
690705 const recentFilePath = getUserConfigFile ( 'recently_played.json' ) ;
691706 let recents = [ ] ;
692707
693708 if ( fsSync . existsSync ( recentFilePath ) ) {
694709 try {
695- const fileData = fsSync . readFileSync ( recentFilePath , 'utf8' ) ;
696- recents = JSON . parse ( fileData ) ;
697- } catch ( readErr ) {
698- console . error ( "Error reading recently_played.json:" , readErr ) ;
699- recents = [ ] ;
710+ recents = JSON . parse ( fsSync . readFileSync ( recentFilePath , 'utf8' ) ) ;
711+ } catch ( err ) {
712+ console . error ( "Error reading recently_played.json:" , err ) ;
700713 }
701714 }
702715
703- // Check if an entry already exists with the same fileName.
704716 const existingIndex = recents . findIndex ( entry => entry . fileName === fileName ) ;
705-
706717 if ( existingIndex >= 0 ) {
707- recents [ existingIndex ] = {
708- ...recents [ existingIndex ] ,
709- date : recentEntry . date
710- } ;
718+ recents [ existingIndex ] . date = recentEntry . date ;
711719 } else {
712720 recents . push ( recentEntry ) ;
713721 }
714722
715723 try {
716- fsSync . writeFileSync ( recentFilePath , JSON . stringify ( recents , null , 4 ) , 'utf8' ) ;
717- } catch ( writeErr ) {
718- console . error ( "Error writing recently_played.json:" , writeErr ) ;
724+ fsSync . writeFileSync ( recentFilePath , JSON . stringify ( recents , null , 4 ) ) ;
725+ } catch ( err ) {
726+ console . error ( "Error writing recently_played.json:" , err ) ;
719727 }
720728
721- const child = spawn ( command , {
722- shell : true ,
729+ // --- command building (FIXED PART) ---
730+
731+ const romDir = path . dirname ( filePath ) ;
732+
733+ let cmd ;
734+ let args = [ ] ;
735+
736+ const emulatorParts = emulator . split ( / \s + / ) ;
737+
738+ if ( emulatorParts [ 0 ] === "flatpak" && emulatorParts [ 1 ] === "run" ) {
739+ cmd = "flatpak" ;
740+
741+ args = [
742+ "run" ,
743+ `--filesystem=${ romDir } :ro` ,
744+ ...emulatorParts . slice ( 2 ) // app id + flatpak args
745+ ] ;
746+ } else {
747+ cmd = emulatorParts [ 0 ] ;
748+ args = emulatorParts . slice ( 1 ) ;
749+ }
750+
751+ if ( emulatorArgs ) {
752+ args . push ( ...emulatorArgs . split ( / \s + / ) ) ;
753+ }
754+
755+ args . push ( filePath ) ;
756+
757+ console . log ( "cmd, args: " , cmd , args ) ;
758+
759+ const child = spawn ( cmd , args , {
723760 detached : true ,
724761 stdio : 'ignore'
725762 } ) ;
726763
764+ child . unref ( ) ;
727765 childProcesses . set ( child . pid , child ) ;
728766
729767 child . on ( 'exit' , ( ) => {
0 commit comments