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

Code before:
import 'source-map-support/register';

import fs from 'fs';
import path from 'path';

import {
  app,
  crashReporter,
  globalShortcut,
  BrowserWindow,
  dialog,
} from 'electron';
import electronDownload from 'electron-dl';

import latestVersion from 'latest-version';

import { createLoginWindow } from './components/loginWindow';
import { createMainWindow } from './components/mainWindow';
import { createTrayIcon } from './components/trayIcon';
import { isOSX } from './helpers/helpers';
import { inferFlashPath } from './helpers/inferFlash';

// Entrypoint for Squirrel, a windows update framework. See https://github.com/jiahaog/nativefier/pull/744
if (require('electron-squirrel-startup')) {
  app.exit();
}

const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));

const fileDownloadOptions = { ...appArgs.fileDownloadOptions };
electronDownload(fileDownloadOptions);

if (appArgs.processEnvs) {
  // This is compatibility if just a string was passed.
  if (typeof appArgs.processEnvs === 'string') {
    process.env.processEnvs = appArgs.processEnvs;
  } else {
    Object.keys(appArgs.processEnvs).forEach((key) => {
      /* eslint-env node */

Review comment (security):
Please refrain from adding extra dependencies to Nativefier. Packages get abandoned / insecure all the time, I only accept new dependencies if they're absolutely critical to new important functionality. Here, the new dep is unnecessary.

Also, using the logic you're suggesting would be very  noisy / frequently cumbersome: new Electron versions are published all the time, many without security issues for which it's not worthwhile to bother users. See https://github.com/jiahaog/nativefier/issues/556 for my suggestion, or feel free to suggest something better:

> *"Could be as simple as writing the build date, and checking at runtime if Date() > buildDate + a few months."*

Code after:
import 'source-map-support/register';

import fs from 'fs';
import path from 'path';

import {
  app,
  crashReporter,
  globalShortcut,
  BrowserWindow,
  dialog,
} from 'electron';
import electronDownload from 'electron-dl';

import { createLoginWindow } from './components/loginWindow';
import { createMainWindow } from './components/mainWindow';
import { createTrayIcon } from './components/trayIcon';
import { isOSX } from './helpers/helpers';
import { inferFlashPath } from './helpers/inferFlash';

// Entrypoint for Squirrel, a windows update framework. See https://github.com/jiahaog/nativefier/pull/744
if (require('electron-squirrel-startup')) {
  app.exit();
}

const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));

const OLD_BUILD_WARNING_THRESHOLD_DAYS = 60;
const OLD_BUILD_WARNING_THRESHOLD_MS =
  OLD_BUILD_WARNING_THRESHOLD_DAYS * 24 * 60 * 60 * 1000;

const fileDownloadOptions = { ...appArgs.fileDownloadOptions };
electronDownload(fileDownloadOptions);

if (appArgs.processEnvs) {
  // This is compatibility if just a string was passed.
  if (typeof appArgs.processEnvs === 'string') {
    process.env.processEnvs = appArgs.processEnvs;
  } else {