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.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', '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);
              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 (security):
Here's my try to make the consequences of each choice fully explicit (and staying concise, which isn't easy).

```suggestion
              `${appArgs.name} needs macOS permissions to enable your Global Shortcuts using media keys (Start, Stop, Next/Previous track).\n\n` +
              `- "Yes" will open macOS' Accessibility Settings, where we need you to check ${appArgs.name}. Please then restart the app, and your Global Shortcuts will work.\n\n` +
              `- "No" will skip this setup for now. Your Global Shortcuts using media keys will not work, and you will be prompted next time the app starts.\n\n` +
              `- "No and never ask again" will never bother you again about it. Your Global Shortcuts using media keys will not work.`,
```

Code after:
          '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
      dialog.showMessageBox(null, {
        type: 'warning',