From a3506bf015fd8db27411d74d2bc892c534ea36a3 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 27 Dec 2019 12:07:39 +0530 Subject: [PATCH] feat: Auto Update - Ability to disable auto update from System tab in Settings --- .../AccountingSettings/AccountingSettings.js | 7 ++++ package.json | 1 + src/App.vue | 4 +++ src/background.js | 10 ++++++ src/main.js | 7 ++++ src/pages/Settings/TabSystem.vue | 16 +++++++++ yarn.lock | 34 ++++++++++++++++++- 7 files changed, 78 insertions(+), 1 deletion(-) diff --git a/models/doctype/AccountingSettings/AccountingSettings.js b/models/doctype/AccountingSettings/AccountingSettings.js index 284a8301..195aee44 100644 --- a/models/doctype/AccountingSettings/AccountingSettings.js +++ b/models/doctype/AccountingSettings/AccountingSettings.js @@ -95,6 +95,13 @@ module.exports = { label: 'Fiscal Year End Date', fieldtype: 'Date', required: 1 + }, + + { + fieldname: 'autoUpdate', + label: 'Auto Update', + fieldtype: 'Check', + default: 1 } ], quickEditFields: [ diff --git a/package.json b/package.json index c9751c6b..117f53f3 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "babel-eslint": "^10.0.3", "electron": "^6.0.0", "electron-notarize": "^0.2.1", + "electron-updater": "^4.2.0", "eslint": "^5.16.0", "eslint-plugin-prettier": "^3.1.1", "eslint-plugin-vue": "^5.0.0", diff --git a/src/App.vue b/src/App.vue index 226d3450..96ece3d8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -88,6 +88,7 @@ export default { this.showSettings = true; } else { this.showDesk = true; + this.checkForUpdates(); } this.showSetupWizard = false; this.showDatabaseSelector = false; @@ -101,6 +102,9 @@ export default { if (this.showSettings) { frappe.events.trigger('reload-main-window'); } + }, + checkForUpdates() { + frappe.events.trigger('check-for-updates'); } } }; diff --git a/src/background.js b/src/background.js index 249e761f..1103786b 100644 --- a/src/background.js +++ b/src/background.js @@ -1,11 +1,13 @@ 'use strict'; import { app, protocol, BrowserWindow, ipcMain } from 'electron'; +import { autoUpdater } from 'electron-updater'; import { createProtocol, installVueDevtools } from 'vue-cli-plugin-electron-builder/lib'; import theme from '@/theme'; + const isDevelopment = process.env.NODE_ENV !== 'production'; const isMac = process.platform === 'darwin'; @@ -13,6 +15,7 @@ const isMac = process.platform === 'darwin'; // be closed automatically when the JavaScript object is garbage collected. let mainWindow; let winURL; +let checkedForUpdate = false; // Scheme must be registered before the app is ready protocol.registerSchemesAsPrivileged([ @@ -69,6 +72,13 @@ function createSettingsWindow(tab = 'General') { settingsWindow.loadURL(`${winURL}#/settings/${tab}`); } +ipcMain.on('check-for-updates', () => { + if (!isDevelopment && !checkedForUpdate) { + autoUpdater.checkForUpdatesAndNotify(); + checkedForUpdate = true; + } +}); + ipcMain.on('open-settings-window', (event, tab) => { createSettingsWindow(tab); }); diff --git a/src/main.js b/src/main.js index ac1ee72a..9758fb4e 100644 --- a/src/main.js +++ b/src/main.js @@ -61,6 +61,13 @@ import router from './router'; ipcRenderer.send('reload-main-window'); }); + frappe.events.on('check-for-updates', () => { + let { autoUpdate } = frappe.AccountingSettings; + if (autoUpdate == null || autoUpdate === 1) { + ipcRenderer.send('check-for-updates'); + } + }); + frappe.events.on('SetupWizard:setup-complete', async setupWizardValues => { const countryList = require('../fixtures/countryInfo.json'); const { diff --git a/src/pages/Settings/TabSystem.vue b/src/pages/Settings/TabSystem.vue index d5a79957..fb9999e2 100644 --- a/src/pages/Settings/TabSystem.vue +++ b/src/pages/Settings/TabSystem.vue @@ -31,12 +31,24 @@ :fields="fields" :autosave="true" /> +
+ +

+ + {{ _('Automatically check for updates and download them if available. The update will be applied after you restart the app.') }} +

+