-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from KELiON/feature/autoupdate
Updates
- Loading branch information
Showing
17 changed files
with
192 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as os from "os"; | ||
import { dialog, } from 'electron' | ||
import { autoUpdater } from "electron-updater"; | ||
|
||
const event = 'update-downloaded' | ||
|
||
export default class AppUpdater { | ||
constructor(w) { | ||
if (process.env.NODE_ENV === 'development' || os.platform() === "linux") { | ||
return | ||
} | ||
|
||
autoUpdater.on(event, (payload) => { | ||
w.webContents.send('message', { | ||
message: event, | ||
payload | ||
}) | ||
}) | ||
|
||
autoUpdater.checkForUpdates() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { dialog, app, shell } from 'electron' | ||
import os from 'os' | ||
import semver from 'semver' | ||
import https from 'https' | ||
|
||
const currentVersion = app.getVersion() | ||
const DEFAULT_DOWNLOAD_URL = 'https://github.com/KELiON/cerebro/releases' | ||
|
||
const TITLE = 'Cerebro Updates' | ||
|
||
const PLATFORM_EXTENSIONS = { | ||
darwin: 'dmg', | ||
linux: 'AppImage', | ||
win32: 'exe' | ||
} | ||
const platform = os.platform() | ||
const installerExtension = PLATFORM_EXTENSIONS[platform] | ||
|
||
const findInstaller = (assets) => { | ||
if (!installerExtension) { | ||
return DEFAULT_DOWNLOAD_URL | ||
} | ||
const regexp = new RegExp(`\.${installerExtension}$`) | ||
const downloadUrl = assets | ||
.map(a => a.browser_download_url) | ||
.find(url => url.match(regexp)) | ||
return downloadUrl || DEFAULT_DOWNLOAD_URL | ||
} | ||
|
||
const getLatestRelease = () => ( | ||
new Promise((resolve, reject) => { | ||
const opts = { | ||
host: 'api.github.com', | ||
path: '/repos/KELiON/cerebro/releases', | ||
headers: { | ||
'User-Agent': `CerebroApp v${currentVersion}` | ||
} | ||
} | ||
https.get(opts, res => { | ||
let json = '' | ||
res.on('data', (chunk) => { | ||
json += chunk | ||
}) | ||
res.on('end', () => resolve(JSON.parse(json)[0])) | ||
}).on('error', () => reject()) | ||
}) | ||
) | ||
|
||
export default () => { | ||
getLatestRelease().then(release => { | ||
const version = semver.valid(release.tag_name) | ||
if (version && semver.gt(version, currentVersion)) { | ||
dialog.showMessageBox({ | ||
buttons: ['Skip', 'Download'], | ||
defaultId: 1, | ||
cancelId: 0, | ||
title: TITLE, | ||
message: `New version available: ${version}`, | ||
detail: 'Click download to get it now', | ||
}, (response) => { | ||
if (response === 1) { | ||
const url = findInstaller(release.assets) | ||
shell.openExternal(url) | ||
} | ||
}) | ||
} else { | ||
dialog.showMessageBox({ | ||
title: TITLE, | ||
message: `Your are using latest version of Cerebro (${currentVersion})`, | ||
buttons: [] | ||
}) | ||
} | ||
}).catch(err => { | ||
console.log('Catch error!', err) | ||
dialog.showErrorBox( | ||
TITLE, | ||
'Error fetching latest version', | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# https://github.com/sindresorhus/appveyor-node/blob/master/appveyor.yml | ||
|
||
environment: | ||
matrix: | ||
- platform: x64 | ||
|
||
image: Visual Studio 2015 | ||
|
||
init: | ||
- npm config set msvs_version 2015 # we need this to build `pty.js` | ||
|
||
install: | ||
- ps: Install-Product node 6 x64 | ||
- set CI=true | ||
- npm install -g npm@3.10.8 | ||
- npm install | ||
|
||
build: off | ||
|
||
shallow_clone: true | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run lint | ||
- npm run test | ||
|
||
on_success: | ||
- npm run package |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters