-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature.js
51 lines (44 loc) · 1.56 KB
/
feature.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
const { Notification, shell } = require("electron");
const path = require("path");
const { parseAsJSONIfNeeded } = require("./events");
const { upsert } = require("./api");
const fs = require("fs");
const { getLogPath, debounce } = require("./lib");
const iconPath = path.join(__dirname, "./icon.png");
exports.showNotification = function ({ title, body }) {
new Notification({ title, body, icon: iconPath }).show();
};
exports.dataSync = function () {
const filePath = getLogPath();
const file = fs.readFileSync(filePath, { encoding: "utf8" });
const json = parseAsJSONIfNeeded(file);
const profileId = json.ServerState.Account.Id;
const cards = Array.from(
new Set(json.ServerState.Cards.map((c) => c.CardDefId))
);
upsert(profileId, cards, { open: true });
};
exports.autoSync = function () {
const filePath = getLogPath();
fs.watch(
filePath,
debounce((event, filename) => {
const filePath = getLogPath();
const file = fs.readFileSync(filePath, { encoding: "utf8" });
const json = parseAsJSONIfNeeded(file);
const profileId = json.ServerState.Account.Id;
const cards = Array.from(
new Set(json.ServerState.Cards.map((c) => c.CardDefId))
);
upsert(profileId, cards, { open: false });
}),
1000 * 10
);
};
exports.openProfilePage = function () {
const filePath = getLogPath();
const file = fs.readFileSync(filePath, { encoding: "utf8" });
const json = parseAsJSONIfNeeded(file);
const profileId = json.ServerState.Account.Id;
shell.openExternal(`https://snapsco.net/p/${profileId}`);
};