Repository: jiahaog/nativefier
File: app/src/main.ts (TypeScript)

Code before:
    // Register global shortcuts
    if (appArgs.globalShortcuts) {
      appArgs.globalShortcuts.forEach((shortcut) => {
        globalShortcut.register(shortcut.key, () => {
          shortcut.inputEvents.forEach((inputEvent) => {
            mainWindow.webContents.sendInputEvent(inputEvent);
          });
        });
      });

      if (isOSX() && appArgs.accessibilityPrompt) {
        const mediaKeys = [
          'MediaPlayPause',
          'MediaNextTrack',
          'MediaPreviousTrack',
          'MediaStop',
        ];
        const globalShortcutsKeys = appArgs.globalShortcuts.map((g) => g.key);
        const mediaKeyWasSet = globalShortcutsKeys.find((g) =>
          mediaKeys.includes(g),
        );
        if (
          mediaKeyWasSet &&
          !systemPreferences.isTrustedAccessibilityClient(false)
        ) {
          // Since we're tryig to set global keyboard shortcuts for media keys, we need to prompt
          // the user for permission on Mac.
          // For reference:
          // https://www.electronjs.org/docs/api/global-shortcut?q=MediaPlayPause#globalshortcutregisteraccelerator-callback
          const accessibilityPromptResult = dialog.showMessageBoxSync(null, {
            type: 'question',
            message: 'Accessibility Permissions Needed',
            buttons: ['Yes', 'No', 'No and never ask again'],
            defaultId: 0,
            detail:
              `${appArgs.name} would like to use one or more of your keyboard's media keys (start, stop, next track, or previous track) to control it.\n\n` +
              `Would you like Mac OS to ask for your permission to do so?\n\n` +
              `If so, you will need to restart ${appArgs.name} after granting permissions for these keyboard shortcuts to begin working.`,
          });
          switch (accessibilityPromptResult) {
            // User clicked Yes, prompt for accessibility
            case 0:
              systemPreferences.isTrustedAccessibilityClient(true);
              break;
            // User cliecked Never Ask Me Again, save that info
            case 2:
              appArgs.accessibilityPrompt = false;
              saveAppArgs(appArgs);
              break;
            // User clicked No
            default:

Review comment (suggestion):
```suggestion
          // Since we're trying to set global keyboard shortcuts for media keys, we need to prompt
```

Code after:
    // Register global shortcuts
    if (appArgs.globalShortcuts) {
      appArgs.globalShortcuts.forEach((shortcut) => {
        globalShortcut.register(shortcut.key, () => {
          shortcut.inputEvents.forEach((inputEvent) => {
            mainWindow.webContents.sendInputEvent(inputEvent);
          });
        });
      });

      if (isOSX() && appArgs.accessibilityPrompt) {
        const mediaKeys = [
          'MediaPlayPause',
          'MediaNextTrack',
          'MediaPreviousTrack',
          'MediaStop',
        ];
        const globalShortcutsKeys = appArgs.globalShortcuts.map((g) => g.key);
        const mediaKeyWasSet = globalShortcutsKeys.find((g) =>
          mediaKeys.includes(g),
        );
        if (
          mediaKeyWasSet &&
          !systemPreferences.isTrustedAccessibilityClient(false)
        ) {
          // Since we're trying to set global keyboard shortcuts for media keys, we need to prompt
          // the user for permission on Mac.
          // For reference:
          // https://www.electronjs.org/docs/api/global-shortcut?q=MediaPlayPause#globalshortcutregisteraccelerator-callback
          const accessibilityPromptResult = dialog.showMessageBoxSync(null, {
            type: 'question',
            message: 'Accessibility Permissions Needed',
            buttons: ['Yes', 'No', 'No and never ask again'],
            defaultId: 0,
            detail:
              `${appArgs.name} would like to use one or more of your keyboard's media keys (start, stop, next track, or previous track) to control it.\n\n` +
              `Would you like Mac OS to ask for your permission to do so?\n\n` +
              `If so, you will need to restart ${appArgs.name} after granting permissions for these keyboard shortcuts to begin working.`,
          });
          switch (accessibilityPromptResult) {
            // User clicked Yes, prompt for accessibility
            case 0:
              systemPreferences.isTrustedAccessibilityClient(true);
              break;
            // User cliecked Never Ask Me Again, save that info
            case 2:
              appArgs.accessibilityPrompt = false;
              saveAppArgs(appArgs);
              break;
            // User clicked No
            default: