@@ -19,8 +19,6 @@ let menuState = {
1919 selectedIndex : 1 ,
2020} ;
2121
22- let currentMenuBuild = null ;
23-
2422// Only assign to window if it exists (renderer context)
2523if ( typeof window !== 'undefined' ) {
2624 window . onMenuKeyDown = function onMenuKeyDown ( event ) {
@@ -470,18 +468,12 @@ function buildSettingsMenu() {
470468 return formContainer ;
471469}
472470
473- async function buildPlatformMenuForm ( platformName ) {
471+ function buildPlatformMenuForm ( platformName ) {
474472
475473 if ( platformName === 'settings' ) {
476474 return buildSettingsMenu ( ) ;
477475 }
478476
479- async function checkHostPlatformName ( ) {
480- const hostPlatformName = await ipcRenderer . invoke ( 'get-host-platform' ) ;
481- console . log ( "hostPlatformName: " , hostPlatformName ) ;
482- return hostPlatformName ;
483- }
484-
485477 const formContainer = document . createElement ( 'div' ) ;
486478 formContainer . classList . add ( 'platform-menu-container' ) ;
487479
@@ -492,20 +484,6 @@ async function buildPlatformMenuForm(platformName) {
492484 platformMenuImageCtn . style . backgroundRepeat = 'no-repeat' ;
493485 platformMenuImageCtn . style . backgroundPosition = 'center' ;
494486
495- // // create the <img>
496- // const img = document.createElement('img');
497- // img.src = `file://${path.join(LB.baseDir, 'img', 'platforms', `${platformName}.png`)}`;
498- // img.alt = platformName;
499-
500- // // optionally control sizing via CSS class instead of inline
501- // img.style.display = 'block';
502- // img.style.maxWidth = '100%';
503- // img.style.maxHeight = '100%';
504- // img.style.objectFit = 'contain';
505-
506- // // append image into container
507- // platformMenuImageCtn.appendChild(img);
508-
509487 const statusCheckBox = document . createElement ( 'input' ) ;
510488 statusCheckBox . type = 'checkbox' ;
511489 statusCheckBox . id = 'input-platform-toggle-checkbox' ;
@@ -601,7 +579,9 @@ async function buildPlatformMenuForm(platformName) {
601579 emulatorCtn . appendChild ( emulatorIcon ) ;
602580 emulatorCtn . appendChild ( emulatorInput ) ;
603581
604- if ( ( await checkHostPlatformName ( ) ) === 'linux' ) {
582+ // Check host platform synchronously - we can get this from cached info or make it sync
583+ // For now, assume we can determine this synchronously or default to showing install button
584+ if ( process . platform === 'linux' ) {
605585 emulatorCtn . appendChild ( installEmulatorsButton ) ;
606586 }
607587
@@ -632,15 +612,15 @@ async function buildPlatformMenuForm(platformName) {
632612 const extensionsInputsContainer = document . createElement ( 'div' ) ;
633613 extensionsInputsContainer . classList . add ( 'extensions-inputs-container' ) ;
634614
635- // Helper to enable/disable the “+” button based on row count
615+ // Helper to enable/disable the "+" button based on row count
636616 function updateAddExtensionBtn ( ) {
637617 // Count only the input rows (total children minus the add button itself)
638618 const rowCount = extensionsInputsContainer . children . length - 1 ;
639619 addExtensionBtn . disabled = rowCount >= 3 ;
640620 addExtensionBtn . style . opacity = addExtensionBtn . disabled ? '0.5' : '1' ;
641621 }
642622
643- // Create the “ Select +” button wired to add a new row
623+ // Create the " Select +" button wired to add a new row
644624 const addExtensionBtn = document . createElement ( 'button' ) ;
645625 addExtensionBtn . classList . add ( 'button' , 'extension' ) ;
646626 addExtensionBtn . innerHTML = '<svg class="icon"><use href="#plus"></use></svg>' ;
@@ -652,19 +632,15 @@ async function buildPlatformMenuForm(platformName) {
652632 updateAddExtensionBtn ( ) ;
653633 } ) ;
654634
655- // Load existing extensions from preferences
656- getPreference ( platformName , 'extensions' )
657- . then ( extensions => {
658- const initialExtensions = extensions || [ '.iso' ] ;
659- initialExtensions . forEach ( ( ext , index ) => {
660- const inputRow = _createExtensionInputRow ( ext , index === 0 ) ;
661- extensionsInputsContainer . appendChild ( inputRow ) ;
662- } ) ;
663- // Finally append the add button and update its state
664- extensionsInputsContainer . appendChild ( addExtensionBtn ) ;
665- updateAddExtensionBtn ( ) ;
666- } )
667- . catch ( console . error ) ;
635+ // Load existing extensions from cached preferences
636+ const extensions = LB . preferences [ platformName ] ?. extensions || [ '.iso' ] ;
637+ extensions . forEach ( ( ext , index ) => {
638+ const inputRow = _createExtensionInputRow ( ext , index === 0 ) ;
639+ extensionsInputsContainer . appendChild ( inputRow ) ;
640+ } ) ;
641+ // Finally append the add button and update its state
642+ extensionsInputsContainer . appendChild ( addExtensionBtn ) ;
643+ updateAddExtensionBtn ( ) ;
668644
669645 // Assemble the full group
670646 extensionsCtn . appendChild ( extensionsIcon ) ;
@@ -707,30 +683,16 @@ async function buildPlatformMenuForm(platformName) {
707683 cancelButton . classList . add ( 'button' , 'cancel' ) ;
708684 cancelButton . textContent = 'Cancel' ;
709685
710- getPreference ( platformName , 'gamesDir' )
711- . then ( ( value ) => {
712- gamesDirInput . value = value ;
713- } )
714- . catch ( ( error ) => {
715- console . error ( 'Failed to get platform preference:' , error ) ;
716- } ) ;
717-
718- getPreference ( platformName , 'emulator' )
719- . then ( ( value ) => {
720- emulatorInput . value = value ;
721- } )
722- . catch ( ( error ) => {
723- console . error ( 'Failed to get platform preference:' , error ) ;
724- } ) ;
725-
726- getPreference ( platformName , 'emulatorArgs' )
727- . then ( ( value ) => {
728- emulatorArgsInput . value = value ;
729- } )
730- . catch ( ( error ) => {
731- console . error ( 'Failed to get platform preference:' , error ) ;
732- } ) ;
686+ // Set values from cached preferences
687+ gamesDirInput . value = LB . preferences [ platformName ] ?. gamesDir || '' ;
688+ emulatorInput . value = LB . preferences [ platformName ] ?. emulator || '' ;
689+ emulatorArgsInput . value = LB . preferences [ platformName ] ?. emulatorArgs || '' ;
733690
691+ // Set status checkbox from cached preferences
692+ const isEnabled = LB . preferences [ platformName ] ?. isEnabled || false ;
693+ statusCheckBox . checked = isEnabled ;
694+ statusLabelPlatormStatus . textContent = isEnabled ? 'On' : 'Off' ;
695+ statusLabelPlatormStatus . classList . add ( isEnabled ? 'on' : 'off' ) ;
734696
735697 gamesDirButton . addEventListener ( 'click' , _gamesDirButtonClick ) ;
736698 emulatorButton . addEventListener ( 'click' , _emulatorButtonClick ) ;
@@ -755,7 +717,6 @@ async function buildPlatformMenuForm(platformName) {
755717 formContainer . appendChild ( statusLabel ) ;
756718 formContainer . appendChild ( gamesDirGroup ) ;
757719 formContainer . appendChild ( emulatorGroup ) ;
758- // formContainer.appendChild(batchGroup);
759720 formContainer . appendChild ( emulatorArgsGroup ) ;
760721 formContainer . appendChild ( extensionsGroup ) ;
761722
@@ -764,16 +725,6 @@ async function buildPlatformMenuForm(platformName) {
764725 formContainerButtons . appendChild ( cancelButton ) ;
765726 formContainerButtons . appendChild ( saveButton ) ;
766727
767- getPreference ( platformName , 'isEnabled' )
768- . then ( ( value ) => {
769- statusCheckBox . checked = value ;
770- statusLabelPlatormStatus . textContent = value ? 'On' : 'Off' ;
771- statusLabelPlatormStatus . classList . add ( value ? 'on' : 'off' ) ;
772- } )
773- . catch ( ( error ) => {
774- console . error ( 'Failed to get platform preference:' , error ) ;
775- } ) ;
776-
777728 statusCheckBox . addEventListener ( 'change' , ( event ) => {
778729 const isNotEnablable = ! gamesDirInput . value || ! emulatorInput . value ;
779730 const isEnabling = statusCheckBox . checked ;
@@ -808,13 +759,9 @@ async function buildPlatformMenuForm(platformName) {
808759 cancelButton . addEventListener ( 'click' , closeSettingsOrPlatformMenu ) ;
809760
810761 installEmulatorsButton . addEventListener ( 'click' , ( ) => {
811-
812762 const platform = PLATFORMS . find ( p => p . name === platformName ) ;
813-
814763 console . log ( "platform.emulators: " , platform . emulators ) ;
815-
816764 installEmulatorsDialog ( platform . emulators ) ;
817- // ipcRenderer.invoke('go-to-url', 'https://gitlab.com/yphil/emulsion/-/blob/master/README.md#usage');
818765 } ) ;
819766
820767 saveButton . addEventListener ( 'click' , onPlatformMenuSaveButtonClick ) ;
@@ -855,20 +802,12 @@ async function buildPlatformMenuForm(platformName) {
855802 . filter ( ext => ext . length > 1 ) ;
856803
857804 try {
858- // Fetch current preferences in parallel
859- const [
860- prevEnabled ,
861- prevGamesDir ,
862- prevEmulator ,
863- prevExtensions ,
864- prevArgs
865- ] = await Promise . all ( [
866- getPreference ( platformName , 'isEnabled' ) . catch ( ( ) => false ) ,
867- getPreference ( platformName , 'gamesDir' ) . catch ( ( ) => '' ) ,
868- getPreference ( platformName , 'emulator' ) . catch ( ( ) => '' ) ,
869- getPreference ( platformName , 'extensions' ) . catch ( ( ) => [ ] ) ,
870- getPreference ( platformName , 'emulatorArgs' ) . catch ( ( ) => '' )
871- ] ) ;
805+ // Get current preferences for comparison
806+ const prevEnabled = LB . preferences [ platformName ] ?. isEnabled || false ;
807+ const prevGamesDir = LB . preferences [ platformName ] ?. gamesDir || '' ;
808+ const prevEmulator = LB . preferences [ platformName ] ?. emulator || '' ;
809+ const prevExtensions = LB . preferences [ platformName ] ?. extensions || [ ] ;
810+ const prevArgs = LB . preferences [ platformName ] ?. emulatorArgs || '' ;
872811
873812 const nextEnabled = statusCheckBox . checked ;
874813 const nextGamesDir = gamesDirInput . value . trim ( ) ;
@@ -895,7 +834,7 @@ async function buildPlatformMenuForm(platformName) {
895834 return ;
896835 }
897836
898- // Serialize the updates, not promise all them
837+ // Update preferences and reload
899838 await updatePreference ( platformName , 'isEnabled' , nextEnabled ) ;
900839 await updatePreference ( platformName , 'gamesDir' , nextGamesDir ) ;
901840 await updatePreference ( platformName , 'emulator' , nextEmulator ) ;
@@ -975,12 +914,6 @@ export function openPlatformMenu(platformName, context, eltToFocus) {
975914 platformName = 'settings' ;
976915 }
977916
978- // Prevent multiple concurrent menu builds
979- if ( currentMenuBuild ) {
980- console . log ( "Menu build already in progress, ignoring duplicate call" ) ;
981- return ;
982- }
983-
984917 LB . mode = 'menu' ;
985918 LB . currentPlatform = platformName ;
986919
@@ -994,16 +927,9 @@ export function openPlatformMenu(platformName, context, eltToFocus) {
994927 menu . dataset . menuPlatform = platformName ;
995928 menu . dataset . context = context || null ;
996929
997- currentMenuBuild = buildPlatformMenuForm ( platformName ) . then ( platformMenuForm => {
998- // Only append if this is still the current build
999- if ( currentMenuBuild ) {
1000- menu . appendChild ( platformMenuForm ) ;
1001- currentMenuBuild = null ; // Clear the build reference
1002- }
1003- } ) . catch ( error => {
1004- console . error ( 'Failed to build platform menu:' , error ) ;
1005- currentMenuBuild = null ; // Clear on error too
1006- } ) ;
930+ // Build and append the form synchronously
931+ const platformMenuForm = buildPlatformMenuForm ( platformName ) ;
932+ menu . appendChild ( platformMenuForm ) ;
1007933
1008934 const header = document . getElementById ( 'header' ) ;
1009935
@@ -1048,11 +974,6 @@ async function closeSettingsOrPlatformMenu() {
1048974
1049975 console . log ( "closeSettingsOrPlatformMenu: " ) ;
1050976
1051- // Cancel any ongoing menu build
1052- if ( currentMenuBuild ) {
1053- currentMenuBuild = null ;
1054- }
1055-
1056977 const menu = document . getElementById ( 'menu' ) ;
1057978
1058979 // updateFooterControls('dpad', 'same', 'Browse', 'on');
0 commit comments