Skip to content

Commit d78f6b7

Browse files
hsiehjackRokt33r
authored andcommitted
Ability to stop auto update
1 parent 7d4d176 commit d78f6b7

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

browser/main/lib/ConfigManager.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const win = global.process.platform === 'win32'
88
const electron = require('electron')
99
const { ipcRenderer } = electron
1010
const consts = require('browser/lib/consts')
11+
const electronConfig = new (require('electron-config'))()
1112

1213
let isInitialized = false
1314

@@ -26,6 +27,7 @@ export const DEFAULT_CONFIG = {
2627
sortTagsBy: 'ALPHABETICAL', // 'ALPHABETICAL', 'COUNTER'
2728
listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL'
2829
amaEnabled: true,
30+
autoUpdateEnabled: true,
2931
hotkey: {
3032
toggleMain: OSX ? 'Command + Alt + L' : 'Super + Alt + E',
3133
toggleMode: OSX ? 'Command + Alt + M' : 'Ctrl + M',
@@ -141,6 +143,8 @@ function get () {
141143
_save(config)
142144
}
143145

146+
config.autoUpdateEnabled = electronConfig.get('autoUpdateEnabled', config.autoUpdateEnabled)
147+
144148
if (!isInitialized) {
145149
isInitialized = true
146150
let editorTheme = document.getElementById('editorTheme')
@@ -205,6 +209,8 @@ function set (updates) {
205209
editorTheme.setAttribute('href', newTheme.path)
206210
}
207211

212+
electronConfig.set('autoUpdateEnabled', newConfig.autoUpdateEnabled)
213+
208214
ipcRenderer.send('config-renew', {
209215
config: get()
210216
})

browser/main/modals/PreferencesModal/InfoTab.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ class InfoTab extends React.Component {
6161
})
6262
}
6363

64+
toggleAutoUpdate () {
65+
const newConfig = {
66+
autoUpdateEnabled: !this.state.config.autoUpdateEnabled
67+
}
68+
69+
this.setState({ config: newConfig })
70+
ConfigManager.set(newConfig)
71+
}
72+
6473
infoMessage () {
6574
const { amaMessage } = this.state
6675
return amaMessage ? <p styleName='policy-confirm'>{amaMessage}</p> : null
@@ -140,6 +149,8 @@ class InfoTab extends React.Component {
140149
</li>
141150
</ul>
142151

152+
<div><label><input type='checkbox' onChange={this.toggleAutoUpdate.bind(this)} checked={this.state.config.autoUpdateEnabled} />{i18n.__('Enable Auto Update')}</label></div>
153+
143154
<hr styleName='separate-line' />
144155

145156
<div styleName='group-header2--sub'>{i18n.__('Analytics')}</div>

lib/main-app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Menu = electron.Menu
44
const ipc = electron.ipcMain
55
const GhReleases = require('electron-gh-releases')
66
const { isPackaged } = app
7+
const electronConfig = new (require('electron-config'))()
78
// electron.crashReporter.start()
89
const singleInstance = app.requestSingleInstanceLock()
910

@@ -40,6 +41,7 @@ function checkUpdate () {
4041
console.log('Updates are disabled in Development mode, see main-app.js')
4142
return true
4243
}
44+
if (!electronConfig.get('autoUpdateEnabled', true)) return
4345
if (process.platform === 'linux' || isUpdateReady) {
4446
return true
4547
}

locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,6 @@
190190
"Show menu bar": "Show menu bar",
191191
"Auto Detect": "Auto Detect",
192192
"Enable HTML label in mermaid flowcharts": "Enable HTML label in mermaid flowcharts ⚠ This option potentially has a risk of XSS.",
193-
"Wrap line in Snippet Note": "Wrap line in Snippet Note"
193+
"Wrap line in Snippet Note": "Wrap line in Snippet Note",
194+
"Enable Auto Update": "Enable Auto Update"
194195
}

tests/helpers/setup-electron-mock.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const noop = () => {}
55
mock('electron', {
66
remote: {
77
app: {
8-
getAppPath: noop
8+
getAppPath: noop,
9+
getPath: noop
910
}
1011
}
1112
})

0 commit comments

Comments
 (0)