@@ -402,9 +402,74 @@ - (void)setDefaultJSBundle
402402 NSAlert *alert = [NSAlert new ];
403403 [alert setMessageText: @" Change packager location" ];
404404 [alert setInformativeText: @" Input packager IP, port and entrypoint" ];
405- [alert addButtonWithTitle: @" Use bundled JS" ];
405+
406+ // Create accessory view with text fields
407+ NSView *accessoryView = [[NSView alloc ] initWithFrame: NSMakeRect (0.0 , 0.0 , 300.0 , 90.0 )];
408+
409+ // IP Address text field
410+ NSTextField *ipTextField = [[NSTextField alloc ] initWithFrame: NSMakeRect (0.0 , 60.0 , 300.0 , 22.0 )];
411+ ipTextField.placeholderString = @" 0.0.0.0" ;
412+ ipTextField.cell .scrollable = YES ;
413+ [accessoryView addSubview: ipTextField];
414+
415+ // Port text field
416+ NSTextField *portTextField =
417+ [[NSTextField alloc ] initWithFrame: NSMakeRect (0.0 , 30.0 , 300.0 , 22.0 )];
418+ portTextField.placeholderString = @" 8081" ;
419+ portTextField.cell .scrollable = YES ;
420+ [accessoryView addSubview: portTextField];
421+
422+ // Entrypoint text field
423+ NSTextField *entrypointTextField =
424+ [[NSTextField alloc ] initWithFrame: NSMakeRect (0.0 , 0.0 , 300.0 , 22.0 )];
425+ entrypointTextField.placeholderString = @" index" ;
426+ entrypointTextField.cell .scrollable = YES ;
427+ [accessoryView addSubview: entrypointTextField];
428+
429+ alert.accessoryView = accessoryView;
430+
431+ [alert addButtonWithTitle: @" Apply Changes" ];
432+ [alert addButtonWithTitle: @" Reset to Default" ];
433+ [alert addButtonWithTitle: @" Cancel" ];
406434 [alert setAlertStyle: NSAlertStyleWarning];
407- [alert beginSheetModalForWindow: [NSApp keyWindow ] completionHandler: nil ];
435+
436+ [alert beginSheetModalForWindow: [NSApp keyWindow ]
437+ completionHandler: ^(NSModalResponse response) {
438+ if (response == NSAlertFirstButtonReturn ) {
439+ // Apply Changes
440+ NSString *ipAddress = ipTextField.stringValue ;
441+ NSString *port = portTextField.stringValue ;
442+ NSString *bundleRoot = entrypointTextField.stringValue ;
443+
444+ if (ipAddress.length == 0 && port.length == 0 ) {
445+ [weakSelf setDefaultJSBundle ];
446+ return ;
447+ }
448+
449+ NSNumberFormatter *formatter = [NSNumberFormatter new ];
450+ formatter.numberStyle = NSNumberFormatterDecimalStyle;
451+ NSNumber *portNumber = [formatter numberFromString: port];
452+ if (portNumber == nil ) {
453+ portNumber = [NSNumber numberWithInt: RCT_METRO_PORT];
454+ }
455+
456+ [RCTBundleURLProvider sharedSettings ].jsLocation =
457+ [NSString stringWithFormat: @" %@ :%d " , ipAddress, portNumber.intValue];
458+
459+ if (bundleRoot.length == 0 ) {
460+ [bundleManager resetBundleURL ];
461+ } else {
462+ bundleManager.bundleURL = [[RCTBundleURLProvider sharedSettings ]
463+ jsBundleURLForBundleRoot: bundleRoot];
464+ }
465+
466+ RCTTriggerReloadCommandListeners (@" Dev menu - apply changes" );
467+ } else if (response == NSAlertSecondButtonReturn ) {
468+ // Reset to Default
469+ [weakSelf setDefaultJSBundle ];
470+ }
471+ // Cancel - do nothing
472+ }];
408473#endif // macOS]
409474 }]];
410475
@@ -452,7 +517,15 @@ - (void)setDefaultJSBundle
452517#else // [macOS
453518 NSMenu *menu = [self menu ];
454519 NSWindow *window = [NSApp keyWindow ];
455- NSEvent *event = [NSEvent mouseEventWithType: NSEventTypeLeftMouseUp location: CGPointMake (0 , 0 ) modifierFlags: 0 timestamp: NSTimeIntervalSince1970 windowNumber: [window windowNumber ] context: nil eventNumber: 0 clickCount: 0 pressure: 0.1 ];
520+ NSEvent *event = [NSEvent mouseEventWithType: NSEventTypeLeftMouseUp
521+ location: CGPointMake (0 , 0 )
522+ modifierFlags: 0
523+ timestamp: NSTimeIntervalSince1970
524+ windowNumber: [window windowNumber ]
525+ context: nil
526+ eventNumber: 0
527+ clickCount: 0
528+ pressure: 0.1 ];
456529 [NSMenu popUpContextMenu: menu withEvent: event forView: [window contentView ]];
457530#endif // macOS]
458531
@@ -484,8 +557,9 @@ - (NSMenu *)menu
484557
485558 menu = [NSMenu new ];
486559
487- NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc ]initWithString:title];
488- [attributedTitle setAttributes: @{ NSFontAttributeName : [NSFont menuFontOfSize: 0 ] } range: NSMakeRange (0 , [attributedTitle length ])];
560+ NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc ] initWithString: title];
561+ [attributedTitle setAttributes: @{NSFontAttributeName : [NSFont menuFontOfSize: 0 ]}
562+ range: NSMakeRange (0 , [attributedTitle length ])];
489563 NSMenuItem *titleItem = [NSMenuItem new ];
490564 [titleItem setAttributedTitle: attributedTitle];
491565 [menu addItem: titleItem];
@@ -494,7 +568,9 @@ - (NSMenu *)menu
494568
495569 NSArray <RCTDevMenuItem *> *items = [self _menuItemsToPresent ];
496570 for (RCTDevMenuItem *item in items) {
497- NSMenuItem *menuItem = [[NSMenuItem alloc ] initWithTitle: [item title ] action: @selector (menuItemSelected: ) keyEquivalent: @" " ];
571+ NSMenuItem *menuItem = [[NSMenuItem alloc ] initWithTitle: [item title ]
572+ action: @selector (menuItemSelected: )
573+ keyEquivalent: @" " ];
498574 [menuItem setTarget: self ];
499575 [menuItem setRepresentedObject: item];
500576 [menu addItem: menuItem];
@@ -505,7 +581,7 @@ - (NSMenu *)menu
505581 return nil ;
506582}
507583
508- -(void )menuItemSelected : (id )sender
584+ - (void )menuItemSelected : (id )sender
509585{
510586 NSMenuItem *menuItem = (NSMenuItem *)sender;
511587 RCTDevMenuItem *item = (RCTDevMenuItem *)[menuItem representedObject ];
0 commit comments