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

@ -38,7 +38,7 @@ upload:
when: never # Do not run this job when a tag is created manually when: never # Do not run this job when a tag is created manually
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when when commits are pushed to the default branch - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when when commits are pushed to the default branch
script: script:
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file "./dist/${WIN_BINARY}" "${PACKAGE_REGISTRY_URL}/${WIN_BINARY}"' - 'curl --header "JOB-TOKEN: $CI_DEPLOY_PASSWORD" --upload-file "./dist/${WIN_BINARY}" "${PACKAGE_REGISTRY_URL}/${WIN_BINARY}"'
auto-release-master: auto-release-master:
image: registry.gitlab.com/gitlab-org/release-cli image: registry.gitlab.com/gitlab-org/release-cli

View file

@ -9,29 +9,27 @@
}, },
"main": "./src/background.ts", "main": "./src/background.ts",
"scripts": { "scripts": {
"dev": "yarn electron:serve", "dev": "vue-cli-service electron:serve",
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build": "electron-builder --win",
"test:unit": "vue-cli-service test:unit", "test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint", "lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build", "electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve", "electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps", "postinstall": "electron-builder install-app-deps",
"postuninstal": "electron-builder install-app-deps", "postuninstal": "electron-builder install-app-deps",
"dist":"electron-builder --publish always", "dist": "electron-builder --publish always"
"dev": "vue-cli-service electron:serve",
"build": "electron-builder --win"
}, },
"repository": { "repository": {
"type" : "git", "type": "git",
"url" : "https://gitlab.com/crimata/electron-app.git", "url": "https://gitlab.com/crimata/electron-app.git",
"release": "latest" "release": "latest"
}, },
"build": { "build": {
"artifactName": "${productName}-${version}.${ext}", "artifactName": "${productName}-${version}.${ext}",
"publish": { "publish": {
"provider": "generic", "provider": "generic",
"url": "https://gitlab.com/api/v4/projects/25637892/jobs/artifacts/master/raw/dist?job=build" "url": "https://gitlab.com/api/v4/projects/25637892/jobs/artifacts/master/raw/dist?job=build"
}, },
"win": { "win": {
"target": [ "target": [
@ -84,6 +82,7 @@
"@wasm-tool/wasm-pack-plugin": "^1.3.1", "@wasm-tool/wasm-pack-plugin": "^1.3.1",
"electron": "^9.0.0", "electron": "^9.0.0",
"electron-devtools-installer": "^3.1.0", "electron-devtools-installer": "^3.1.0",
"electron-log": "^4.3.4",
"eslint": "^6.7.2", "eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0-0", "eslint-plugin-vue": "^7.0.0-0",
"lint-staged": "^9.5.0", "lint-staged": "^9.5.0",

View file

@ -5,7 +5,9 @@
"use strict"; "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'; import { initApp } from './background/init';
// Scheme must be registered before the app is ready // Scheme must be registered before the app is ready
@ -16,31 +18,55 @@ protocol.registerSchemesAsPrivileged([
// Load environment variable // Load environment variable
const isDev = require('electron-is-dev'); 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 // NOTE Program Begins Here
(async () => { (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.'); console.log('Starting Crimata electron app.');
initApp(isDev); initApp(isDev);
})(); })();
// Auto app updates. // Auto app updates.
if (!isDev) { // if (!isDev) {
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { // autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
const dialogOpts = { // const dialogOpts = {
type: 'info', // type: 'info',
buttons: ['Restart', 'Later'], // buttons: ['Restart', 'Later'],
title: 'Application Update', // title: 'Application Update',
message: releaseName, // message: releaseName,
detail: 'A new version has been downloaded. Restart the application to apply the updates.' // detail: 'A new version has been downloaded. Restart the application to apply the updates.'
} // }
//
dialog.showMessageBox(dialogOpts).then((returnValue) => { // dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall() // if (returnValue.response === 0) autoUpdater.quitAndInstall()
}) // })
}) // })
//
setInterval(() => { // setInterval(() => {
autoUpdater.checkForUpdates() // autoUpdater.checkForUpdates()
}, 5000) // }, 5000)
} // }

View file

@ -5121,6 +5121,11 @@ electron-is-dev@^2.0.0:
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-2.0.0.tgz#833487a069b8dad21425c67a19847d9064ab19bd" resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-2.0.0.tgz#833487a069b8dad21425c67a19847d9064ab19bd"
integrity sha512-3X99K852Yoqu9AcW50qz3ibYBWY79/pBhlMCab8ToEWS48R0T9tyxRiQhwylE7zQdXrMnx2JKqUJyMPmt5FBqA== integrity sha512-3X99K852Yoqu9AcW50qz3ibYBWY79/pBhlMCab8ToEWS48R0T9tyxRiQhwylE7zQdXrMnx2JKqUJyMPmt5FBqA==
electron-log@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-4.3.4.tgz#97e991dcd653e759e14eb2ae5d6ba4440f50afd8"
integrity sha512-Cd6xZ9if2J4NG+PNoi3cARAYoanbM4ddpod0faaL5LIhmwuSdxP9XH95C9SgTpHMqklbg8u3CFh1yqiaqo2Bng==
electron-publish@22.9.1: electron-publish@22.9.1:
version "22.9.1" version "22.9.1"
resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-22.9.1.tgz#7cc76ac4cc53efd29ee31c1e5facb9724329068e" resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-22.9.1.tgz#7cc76ac4cc53efd29ee31c1e5facb9724329068e"