mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Update hyper-news notification fetching
This commit is contained in:
parent
4264493147
commit
2b3c49b1ec
1 changed files with 12 additions and 12 deletions
|
|
@ -1,13 +1,9 @@
|
||||||
const ms = require('ms');
|
const ms = require('ms');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const {satisfies} = require('semver');
|
|
||||||
|
|
||||||
const {version} = './package';
|
const {version} = require('./package');
|
||||||
|
|
||||||
const NEWS_URL = 'https://hyper-news.now.sh';
|
const NEWS_URL = 'https://hyper-news.now.sh';
|
||||||
const matchVersion = versions => (
|
|
||||||
versions.some(v => v === '*' || satisfies(version, v))
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = function fetchNotifications(win) {
|
module.exports = function fetchNotifications(win) {
|
||||||
const {rpc} = win;
|
const {rpc} = win;
|
||||||
|
|
@ -19,18 +15,22 @@ module.exports = function fetchNotifications(win) {
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Checking for notification messages');
|
console.log('Checking for notification messages');
|
||||||
fetch(NEWS_URL)
|
fetch(NEWS_URL, {
|
||||||
|
headers: {
|
||||||
|
'X-Hyper-Version': version,
|
||||||
|
'X-Hyper-Platform': process.platform
|
||||||
|
}
|
||||||
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const {messages} = data || {};
|
const {message} = data || {};
|
||||||
if (!messages) {
|
if (typeof message !== 'object' && message !== '') {
|
||||||
throw new Error('Bad response');
|
throw new Error('Bad response');
|
||||||
}
|
}
|
||||||
const message = messages.find(msg => matchVersion(msg.versions));
|
if (message === '') {
|
||||||
if (message) {
|
|
||||||
rpc.emit('add notification', message);
|
|
||||||
} else {
|
|
||||||
console.log('No matching notification messages');
|
console.log('No matching notification messages');
|
||||||
|
} else {
|
||||||
|
rpc.emit('add notification', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
retry();
|
retry();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue