From 55158a2ca65eb9e0050529ac9c4fe7e7167be2fd Mon Sep 17 00:00:00 2001 From: Jack Hsieh Date: Sat, 17 Nov 2018 10:46:49 -0800 Subject: [PATCH] Ability to stop auto update --- browser/main/lib/ConfigManager.js | 6 ++++++ browser/main/modals/PreferencesModal/InfoTab.js | 11 +++++++++++ lib/main-app.js | 2 ++ locales/en.json | 3 ++- tests/helpers/setup-electron-mock.js | 3 ++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 20799de50..ce641b9a5 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -8,6 +8,7 @@ const win = global.process.platform === 'win32' const electron = require('electron') const { ipcRenderer } = electron const consts = require('browser/lib/consts') +const electronConfig = new (require('electron-config'))() let isInitialized = false @@ -26,6 +27,7 @@ export const DEFAULT_CONFIG = { sortTagsBy: 'ALPHABETICAL', // 'ALPHABETICAL', 'COUNTER' listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL' amaEnabled: true, + autoUpdateEnabled: true, hotkey: { toggleMain: OSX ? 'Command + Alt + L' : 'Super + Alt + E', toggleMode: OSX ? 'Command + Alt + M' : 'Ctrl + M', @@ -141,6 +143,8 @@ function get () { _save(config) } + config.autoUpdateEnabled = electronConfig.get('autoUpdateEnabled', config.autoUpdateEnabled) + if (!isInitialized) { isInitialized = true let editorTheme = document.getElementById('editorTheme') @@ -205,6 +209,8 @@ function set (updates) { editorTheme.setAttribute('href', newTheme.path) } + electronConfig.set('autoUpdateEnabled', newConfig.autoUpdateEnabled) + ipcRenderer.send('config-renew', { config: get() }) diff --git a/browser/main/modals/PreferencesModal/InfoTab.js b/browser/main/modals/PreferencesModal/InfoTab.js index 71e99da9a..662504124 100644 --- a/browser/main/modals/PreferencesModal/InfoTab.js +++ b/browser/main/modals/PreferencesModal/InfoTab.js @@ -61,6 +61,15 @@ class InfoTab extends React.Component { }) } + toggleAutoUpdate () { + const newConfig = { + autoUpdateEnabled: !this.state.config.autoUpdateEnabled + } + + this.setState({ config: newConfig }) + ConfigManager.set(newConfig) + } + infoMessage () { const { amaMessage } = this.state return amaMessage ?

{amaMessage}

: null @@ -140,6 +149,8 @@ class InfoTab extends React.Component { +
+
{i18n.__('Analytics')}
diff --git a/lib/main-app.js b/lib/main-app.js index 9a2c4e59e..f8ee1ecfc 100644 --- a/lib/main-app.js +++ b/lib/main-app.js @@ -4,6 +4,7 @@ const Menu = electron.Menu const ipc = electron.ipcMain const GhReleases = require('electron-gh-releases') const { isPackaged } = app +const electronConfig = new (require('electron-config'))() // electron.crashReporter.start() const singleInstance = app.requestSingleInstanceLock() @@ -40,6 +41,7 @@ function checkUpdate () { console.log('Updates are disabled in Development mode, see main-app.js') return true } + if (!electronConfig.get('autoUpdateEnabled', true)) return if (process.platform === 'linux' || isUpdateReady) { return true } diff --git a/locales/en.json b/locales/en.json index 7ad5e0b7b..183bdaad3 100644 --- a/locales/en.json +++ b/locales/en.json @@ -190,5 +190,6 @@ "Show menu bar": "Show menu bar", "Auto Detect": "Auto Detect", "Enable HTML label in mermaid flowcharts": "Enable HTML label in mermaid flowcharts ⚠ This option potentially has a risk of XSS.", - "Wrap line in Snippet Note": "Wrap line in Snippet Note" + "Wrap line in Snippet Note": "Wrap line in Snippet Note", + "Enable Auto Update": "Enable Auto Update" } diff --git a/tests/helpers/setup-electron-mock.js b/tests/helpers/setup-electron-mock.js index dd6a97330..a236df1bf 100644 --- a/tests/helpers/setup-electron-mock.js +++ b/tests/helpers/setup-electron-mock.js @@ -5,7 +5,8 @@ const noop = () => {} mock('electron', { remote: { app: { - getAppPath: noop + getAppPath: noop, + getPath: noop } } })