From: Andrew Gundersen Date: Thu, 15 Apr 2021 23:55:06 +0000 (-0500) Subject: testing autoupdate X-Git-Tag: v0.9.6 X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=36491c589492d368c59dd88993f2f20d77471a14;p=mime-chat testing autoupdate --- diff --git a/package.json b/package.json index 56a7cf8..bfd57b4 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/background.ts b/src/background.ts index 1147f86..8fafb4f 100644 --- a/src/background.ts +++ b/src/background.ts @@ -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 \ No newline at end of file diff --git a/src/background/init.ts b/src/background/init.ts index 52e184a..3c24203 100644 --- a/src/background/init.ts +++ b/src/background/init.ts @@ -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(); }); } }