This repository was archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.js
More file actions
52 lines (47 loc) · 1.22 KB
/
github.js
File metadata and controls
52 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var remote = require('remote');
var app = remote.require('app');
var shell = remote.require('shell');
var path = require('path');
var fs = require('fs');
var github = require('octonode');
if (Notification.permission != 'granted') {
Notification.requestPermission(function (permission) {
if (permission != "granted") {
app.quit();
}
})
}
var dataFilePath = path.join(app.getPath('home'), '.github-electron');
var data;
if (!fs.existsSync(dataFilePath)) {
data = {};
}
data = JSON.parse(fs.readFileSync(dataFilePath, 'utf-8'));
var token = null
if ('token' in data) {
token = data['token'];
}
var client, ghme;
if (token != null) {
client = github.client(token);
ghme = client.me();
}
var notifications = []
var timer = setInterval(function() {
if (ghme != undefined) {
ghme.notifications({}, function(err, data, headers) {
if (data.length > 0) {
data.forEach(function(e,i,a) {
if (notifications.indexOf(e.id) >= 0) {
return;
}
notifications.push(e.id);
var notification = new Notification(e.subject.type, { tag: e.id, body: e.subject.title });
notification.onclick = function () {
shell.openExternal("https://github.com/notifications")
};
})
}
});
}
}, 3000);