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

Code before:
      submitURL: appArgs.crashReporter,
      uploadToServer: true,
    });
  });
}

// quit if singleInstance mode and there's already another instance running
const shouldQuit = appArgs.singleInstance && !app.requestSingleInstanceLock();
if (shouldQuit) {
  app.quit();
} else {
  app.on('second-instance', () => {
    if (mainWindow) {
      if (!mainWindow.isVisible()) {
        // try
        mainWindow.show();
      }
      if (mainWindow.isMinimized()) {
        // minimized
        mainWindow.restore();
      }
      mainWindow.focus();
    }
  });

  if (appArgs.widevine !== undefined) {
    // @ts-ignore This event only appear on the widevine version of electron, which we'd see at runtime
    app.on('widevine-ready', (version, lastVersion) => {
      console.log('widevine-ready', version, lastVersion);
      onReady();
    });

    // @ts-ignore This event only appear on the widevine version of electron, which we'd see at runtime
    app.on('widevine-update-pending', (currentVersion, pendingVersion) => {
      console.log(
        `Widevine ${currentVersion} is ready to be upgraded to ${pendingVersion}`,
      );
    });

    // @ts-ignore This event only appear on the widevine version of electron, which we'd see at runtime
    app.on('widevine-error', (error) => {
      console.error('WIDEVINE ERROR: ', error);
    });
  } else {
    app.on('ready', () => {
      console.log('ready');
      onReady();
    });
  }
}


Review comment (suggestion):
This condition was excessive in a normal (non-widevine) build. In a normal build, appArgs.widevine is `false` (which is `!== undefined`). So, this widevine branch was taken even in a non-widevine build, and since `widevine-ready` isn't called here, `onReady` was never called and the main window was never created.

Code after:
      submitURL: appArgs.crashReporter,
      uploadToServer: true,
    });
  });
}

// quit if singleInstance mode and there's already another instance running
const shouldQuit = appArgs.singleInstance && !app.requestSingleInstanceLock();
if (shouldQuit) {
  app.quit();
} else {
  app.on('second-instance', () => {
    if (mainWindow) {
      if (!mainWindow.isVisible()) {
        // try
        mainWindow.show();
      }
      if (mainWindow.isMinimized()) {
        // minimized
        mainWindow.restore();
      }
      mainWindow.focus();
    }
  });

  if (appArgs.widevine) {
    // @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
    app.on('widevine-ready', (version: string, lastVersion: string) => {
      console.log('widevine-ready', version, lastVersion);
      onReady();
    });

    app.on(
      // @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
      'widevine-update-pending',
      (currentVersion: string, pendingVersion: string) => {
        console.log(
          `Widevine ${currentVersion} is ready to be upgraded to ${pendingVersion}`,
        );
      },
    );

    // @ts-ignore This event only appears on the widevine version of electron, which we'd see at runtime
    app.on('widevine-error', (error: any) => {
      console.error('WIDEVINE ERROR: ', error);
    });
  } else {
    app.on('ready', () => {
      console.log('ready');
      onReady();
    });