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

Code before:
}

app.on('new-window-for-tab', () => {
  log.debug('app.new-window-for-tab');
  if (mainWindow) {
    mainWindow.emit('new-tab');
  }
});

app.on('login', (event, webContents, request, authInfo, callback) => {
  log.debug('app.login', { event, request });
  // for http authentication
  event.preventDefault();

  if (appArgs.basicAuthUsername && appArgs.basicAuthPassword) {
    callback(appArgs.basicAuthUsername, appArgs.basicAuthPassword);
  } else {
    createLoginWindow(callback, mainWindow).catch((err) =>
      log.error('createLoginWindow ERROR', err),
    );
  }
});

async function onReady(): Promise<void> {
  mainWindow = await createMainWindow(appArgs, setDockBadge);

  createTrayIcon(appArgs, mainWindow);

  // 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 &&

Review comment (suggestion):
```suggestion
  // Warning: `mainWindow` below is the *global* unique `mainWindow`, created at init time
  mainWindow = await createMainWindow(appArgs, setDockBadge);  
```

Code after:
}

app.on('new-window-for-tab', () => {
  log.debug('app.new-window-for-tab');
  if (mainWindow) {
    mainWindow.emit('new-tab');
  }
});

app.on('login', (event, webContents, request, authInfo, callback) => {
  log.debug('app.login', { event, request });
  // for http authentication
  event.preventDefault();

  if (appArgs.basicAuthUsername && appArgs.basicAuthPassword) {
    callback(appArgs.basicAuthUsername, appArgs.basicAuthPassword);
  } else {
    createLoginWindow(callback, mainWindow).catch((err) =>
      log.error('createLoginWindow ERROR', err),
    );
  }
});

async function onReady(): Promise<void> {
  // Warning: `mainWindow` below is the *global* unique `mainWindow`, created at init time
  mainWindow = await createMainWindow(appArgs, setDockBadge);

  createTrayIcon(appArgs, mainWindow);

  // 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 (