testing autoupdate

This commit is contained in:
Andrew Gundersen 2021-04-15 18:55:06 -05:00
commit 36491c5894
3 changed files with 39 additions and 52 deletions

View file

@ -1,6 +1,6 @@
{
"name": "Crimata",
"version": "0.9.5",
"version": "0.9.6",
"private": true,
"description": "Cross-platform messenger application built with electron, vue3, and TS.",
"author": {

View file

@ -5,10 +5,8 @@
"use strict";
const { autoUpdater } = require('electron-updater')
import { initApp } from './background/init';
import { protocol, dialog } from "electron";
import { protocol } from "electron";
// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
@ -21,47 +19,7 @@ const isDev = require('electron-is-dev');
// NOTE Program Begins Here
(async () => {
autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'seMF_apn237iUw8puG9a' }
const dialogConfig = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: 'A new version has been downloaded. Restart to update.'
}
autoUpdater.on('checking-for-update', () => {
console.log("Checking for update...")
})
autoUpdater.on('update-available', () => {
console.log("Update available.")
})
autoUpdater.on('download-progress', function (progress: any) {
console.log(`Downloading update: ${progress.percent}`)
})
autoUpdater.on('error', (err: any) => {
console.log(String(err))
})
autoUpdater.on('update-downloaded', () => {
console.log("Update downloaded.")
dialog.showMessageBox(dialogConfig).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall()
})
})
autoUpdater.checkForUpdatesAndNotify()
setInterval(() => {
autoUpdater.checkForUpdatesAndNotify()
}, 5000)
console.log('Starting Crimata electron app.');
initApp(isDev);
await initApp(isDev);
})();
https://gitlab.com/crimata/electron-app/-/package_files/9495519/download

View file

@ -1,12 +1,11 @@
"use strict";
import { app } from "electron";
import { app, dialog } from "electron";
import { createWindow } from './window';
import { initSession } from './session';
import { initAudioIO } from './audio';
import { backgroundMitt } from '@/modules/emitter';
const { autoUpdater } = require('electron-updater');
let win: boolean;
@ -15,6 +14,30 @@ backgroundMitt.on('window-active', (state: boolean) => {
win = state;
});
// Auto updating.
const { autoUpdater } = require('electron-updater')
autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'seMF_apn237iUw8puG9a' }
autoUpdater.on('update-available', (info: any) => {
console.log(`Update available: ${info.version}`)
})
autoUpdater.on('update-downloaded', (info: any) => {
const updateDialog = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: info.version,
detail: 'A new version has been downloaded. Restart the application to apply the updates.'
}
dialog.showMessageBox(updateDialog).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall()
})
})
// Run when electron app is initialized.
async function main() {
console.log("MAIN:Initializing Electron App.")
@ -35,7 +58,13 @@ export function initApp(dev: boolean): void {
// On initial startup.
app.on("ready", () => {
main()
// Check for updates every 2min.
setInterval(() => {
autoUpdater.checkForUpdates()
}, 5000) // 5s for development.
main()
});
// Must keep to ensure app doesn't quit on close.
@ -49,16 +78,16 @@ export function initApp(dev: boolean): void {
// When user clicks app icon (re-open)
app.on("activate", () => {
if (!win) {
createWindow();
}
if (!win) {
createWindow();
}
});
// Exit cleanly on request from parent process in development mode.
if (dev) {
process.on("SIGTERM", () => {
app.quit();
app.quit();
});
}
}