add electron-update to background.ts

This commit is contained in:
riqo 2021-04-13 08:41:40 -05:00
commit 662fc591c3
4 changed files with 60 additions and 30 deletions

View file

@ -5,7 +5,9 @@
"use strict";
import { protocol, autoUpdater, dialog } from "electron";
import { protocol, dialog } from "electron";
const { autoUpdater } = require('electron-updater')
const log = require("electron-log")
import { initApp } from './background/init';
// Scheme must be registered before the app is ready
@ -16,31 +18,55 @@ protocol.registerSchemesAsPrivileged([
// Load environment variable
const isDev = require('electron-is-dev');
// setTimeout(function () {
// autoUpdater.checkForUpdatesAndNotify()
// }, 10000)
// Check for an update every 2min.
// setInterval(() => {
// autoUpdater.checkForUpdatesAndNotify()
// }, 120000)
// NOTE Program Begins Here
(async () => {
autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'seMF_apn237iUw8puG9a' }
autoUpdater.logger = log;
// Check for an update 10sec after Program Starts
setTimeout(function () {
autoUpdater.checkForUpdatesAndNotify()
}, 10000)
// Check for an update every 2min.
setInterval(() => {
autoUpdater.checkForUpdatesAndNotify()
}, 120000)
console.log('Starting Crimata electron app.');
initApp(isDev);
})();
// Auto app updates.
if (!isDev) {
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
const dialogOpts = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: releaseName,
detail: 'A new version has been downloaded. Restart the application to apply the updates.'
}
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall()
})
})
setInterval(() => {
autoUpdater.checkForUpdates()
}, 5000)
}
// if (!isDev) {
// autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
// const dialogOpts = {
// type: 'info',
// buttons: ['Restart', 'Later'],
// title: 'Application Update',
// message: releaseName,
// detail: 'A new version has been downloaded. Restart the application to apply the updates.'
// }
//
// dialog.showMessageBox(dialogOpts).then((returnValue) => {
// if (returnValue.response === 0) autoUpdater.quitAndInstall()
// })
// })
//
// setInterval(() => {
// autoUpdater.checkForUpdates()
// }, 5000)
// }