akashnimare
12/25/2016 - 7:20 PM

Adding auto-updates to electron apps

Adding auto-updates to electron apps

const electron = require('electron');
const {app} = require('electron');
const isDev = require('electron-is-dev');  // this is required to check if the app is running in development mode. 
const {appUpdater} = require('./autoupdater');

/* Handling squirrel.windows events on windows 
only required if you have build the windows with target squirrel. For NSIS target you don't need it. */
if (require('electron-squirrel-startup')) {
	app.quit();
}

let mainWindow;

// Funtion to check the current OS. As of now there is no proper method to add auto-updates to linux platform.
function isWindowsOrmacOS() {
	return process.platform === 'darwin' || process.platform === 'win32';
}

app.on('ready', () => {
  mainWindow = new BrowserWindow({
      height: 600,
      width: 600
  });

  mainWindow.loadURL("https://github.com");
	
  const page = mainWindow.webContents;
  
  page.once('did-frame-finish-load', () => {
    const checkOS = isWindowsOrmacOS();
    if (checkOS && !isDev) {
      // Initate auto-updates on macOs and windows
      appUpdater();
    }});
});