-
Notifications
You must be signed in to change notification settings - Fork 10
/
node_helper.js
60 lines (54 loc) · 1.76 KB
/
node_helper.js
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
53
54
55
56
57
58
59
60
const NodeHelper = require("node_helper");
const BringClient = require("./BringClient");
let lists;
let currentList;
let client;
let config;
module.exports = NodeHelper.create({
start: function () {
},
socketNotificationReceived: function (notification, payload) {
if (notification === "GET_LIST") {
if (!this.client) {
this.initClient(payload);
} else {
this.getList(payload);
this.config = payload;
}
return true;
} else if (notification === "PURCHASED_ITEM") {
if (payload.purchase) {
this.client.recently(payload.name, payload.listId).then(() => {
this.sendSocketNotification("RELOAD_LIST");
});
} else {
this.client.purchase(payload.name, payload.listId).then(() => {
this.sendSocketNotification("RELOAD_LIST");
});
}
return true;
}
},
getList: function (payload) {
if (this.client.mustLogin()) {
this.initClient(payload.config);
} else {
this.client.getList(true, payload.listName).then(list => {
this.currentList = list;
this.sendSocketNotification("LIST_DATA", {lists: this.lists, currentList: list});
});
}
},
initClient: function (payload) {
this.client = new BringClient(payload, this.path);
// Wait for Login
setTimeout(() => {
if (!this.client.mustLogin()) {
this.client.getLists().then(lists => {
this.lists = lists;
this.getList(payload);
});
}
}, 1500);
}
});