Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit 064f292

Browse files
authored
Merge pull request #36 from ZeroX-DG/check-update
Added check for update in menu
2 parents e298dfd + 98db8a1 commit 064f292

File tree

5 files changed

+239
-24
lines changed

5 files changed

+239
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Every notable changes in each version will be listed in this file.
88

99
- **Interface**: Added input select for faster language picking in create snippet modal ([2e83a62](https://github.com/ZeroX-DG/SnippetStore/commit/2e83a62))
1010
- **Interface**: Added markdown preview for markdown snippets
11+
- **Interface**: Added about menu ([e298dfd](https://github.com/ZeroX-DG/SnippetStore/commit/e298dfd))
12+
- **Interface**: Added check for update in menu ([5f233cb](https://github.com/ZeroX-DG/SnippetStore/commit/5f233cb))
1113

1214
## Bugfixes:
1315

app/app-menu.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const electron = require('electron')
22
const os = require('os')
3+
const { checkForUpdate, downloadAndInstall } = require('./app-updator')
34
const BrowserWindow = electron.BrowserWindow
45
const dialog = electron.dialog
56

@@ -124,6 +125,38 @@ function getMenu (app, mainWindow) {
124125
buttons: ['OK']
125126
})
126127
}
128+
},
129+
{
130+
label: 'Check for updates',
131+
click () {
132+
checkForUpdate().then(hasNewUpdate => {
133+
if (hasNewUpdate) {
134+
dialog.showMessageBox(
135+
{
136+
type: 'info',
137+
title: 'Snippet Store',
138+
message: 'A new version is available!',
139+
detail:
140+
'A new version of SnippetStore is now available, please update to receive the latest bugfixes and features',
141+
buttons: ['Update', 'Later']
142+
},
143+
response => {
144+
if (response === 0) {
145+
downloadAndInstall()
146+
}
147+
}
148+
)
149+
} else {
150+
dialog.showMessageBox({
151+
type: 'info',
152+
title: 'Snippet Store',
153+
message: 'No new version',
154+
detail: "You're now on the latest version of SnippetStore",
155+
buttons: ['OK']
156+
})
157+
}
158+
})
159+
}
127160
}
128161
]
129162
}

app/app-updator.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const GhReleases = require('electron-gh-releases')
2+
const { app } = require('electron')
3+
4+
const options = {
5+
repo: 'ZeroX-DG/SnippetStore',
6+
currentVersion: app.getVersion()
7+
}
8+
9+
const updater = new GhReleases(options)
10+
11+
const checkForUpdate = () => {
12+
return new Promise(resolve => {
13+
updater.check((err, status) => {
14+
if (!err && status) {
15+
resolve(true)
16+
return
17+
}
18+
resolve(false)
19+
})
20+
})
21+
}
22+
23+
const downloadAndInstall = () => {
24+
updater.download()
25+
updater.on('update-downloaded', info => {
26+
// Restart the app and install the update
27+
updater.install()
28+
})
29+
}
30+
31+
module.exports = {
32+
updater,
33+
checkForUpdate,
34+
downloadAndInstall
35+
}

0 commit comments

Comments
 (0)