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

Code before:
          'MediaPlayPause',
          'MediaNextTrack',
          'MediaPreviousTrack',
          'MediaStop',
        ];
        const globalShortcutsKeys = appArgs.globalShortcuts.map((g) => g.key);
        const mediaKeyWasSet =
          globalShortcutsKeys.filter((g) => mediaKeys.includes(g)).length > 0;
        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', 'Never Ask Me 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, APP_ARGS_FILE_PATH);
              break;
            // User clicked No
            default:
              break;
          }
        }
      }
    }
    if (
      !appArgs.disableOldBuildWarning &&
      new Date().getTime() - appArgs.buildDate > OLD_BUILD_WARNING_THRESHOLD_MS
    ) {
      // eslint-disable-next-line @typescript-eslint/no-floating-promises
      dialog.showMessageBox(null, {
        type: 'warning',

Review comment (bug):
**My main concern here**:

I'd rather have a simple `Yes` / `Not now` dialog, without this "Never ask me again" option, and an extra line that says something like:

```
If you don't want to / cannot grant ${appArgs.name} Accessibility permissions, please delete the global shortcuts using media keys to not be prompted again.
```

A macOS user who wants to use a media key in a global shortcut has no choice but to comply to grant accessibility permissions, correct?

So, why this new `no-accessibility-prompt` flag, and the need to persist it?

To me, users confronted to this dialog will fall into two buckets:

1. "Accepters", who want their media key global shortcut and accept to enable it at macOS level
2. "Denyers", who would like their media key global shortcut, but for some reason don't want to enable the accessibility setting, and should then simply remove the shortcut from their shortcut options.

Why make things more complex with a third bucket, a new flag, and more persistence needed? You don't want to enable the accessibility thing, alright, we tell you why you can't use your global shortcut. Want us to stop telling you? A. do the OS requirement, or B. get rid of the binding (which at that point was broken anyway). Simple and doesn't need an extra flag, of which Nativefier already has waaaaaaaaaaaaaay too many 😄.

Am I missing something?

Code after:
      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:
              break;
          }
        }
      }
    }
    if (
      !appArgs.disableOldBuildWarning &&
      new Date().getTime() - appArgs.buildDate > OLD_BUILD_WARNING_THRESHOLD_MS
    ) {
      // eslint-disable-next-line @typescript-eslint/no-floating-promises