-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
124 lines (104 loc) · 3.57 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const wi = require("@arcsine/win-info");
const fs = require('fs');
const fp = require("find-process");
const readline = require("readline");
var exec = require('child_process').execFile;
const setPath = require('./path.js');
const config = require('./config.json');
const configName = './config.json';
const { Client } = require("discord-rpc");
const client = new Client({ transport: "ipc" });
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const start = new Date();
async function UpdatePresence() {
const apps = await fp("name", "Aseprite");
let app;
for (let i = 0; i < apps.length; i++) {
if (["Aseprite.exe"].includes(apps[i].name)) {
app = apps[i];
}
}
var presence = {
largeImageKey: 'img',
smallImageKey: 'none',
largeImageText: ".aseprite",
smallImageText: "Aseprite"
}
let window;
if (app) {
try {
window = wi.getByPidSync(app.pid);
}
catch {
console.log('Aseprite is not open.');
}
}
if (window) {
if (window.title.includes(" - ")) {
window.filename = window.title.split(" - ")[0];
presence.smallImageKey = 'aseprite';
if (window.filename.endsWith('.ase')) {
presence.largeImageKey = 'ase';
presence.largeImageText = '.ase';
} else if (window.filename.endsWith('.aseprite')) {
presence.largeImageKey = 'ase';
presence.largeImageText = '.aseprite';
} else if (window.filename.endsWith('.jpg')) {
presence.largeImageKey = 'jpg';
presence.largeImageText = '.jpg';
} else if (window.filename.endsWith('.jpeg')) {
presence.largeImageKey = 'jpg';
presence.largeImageText = '.jpeg';
} else if (window.filename.endsWith('.png')) {
presence.largeImageKey = 'png';
presence.largeImageText = '.png';
} else if (window.filename.endsWith('.gif')) {
presence.largeImageKey = 'gif';
presence.largeImageText = '.gif';
} else {
presence.largeImageKey = 'img';
presence.largeImageText = 'Image';
}
} else {
presence.largeImageKey = 'aseprite';
presence.largeImageText = 'Aseprite';
}
client.setActivity({
state: window && window.filename ? `Editing: ${window.filename}` : "Idling",
startTimestamp: start,
largeImageKey: presence.largeImageKey,
smallImageKey: presence.smallImageKey,
largeImageText: presence.largeImageText,
smallImageText: presence.smallImageText
}, app.pid || null);
}
}
function StartPresence() {
UpdatePresence();
client.on("ready", () => {
console.log("Connected to Discord.");
UpdatePresence();
setInterval(() => {
UpdatePresence();
}, 15000);
});
console.log("Connecting...");
client.login({ clientId: config.clientID });
exec(`${config.path}`);
}
if (config.path == '') {
rl.question("Please enter your Aseprite.exe path: ", function(path) {
rl.close();
config.path = path;
fs.writeFile(configName, JSON.stringify(config, null, 4), function writeJSON(err) {
if (err) return console.log(err);
StartPresence();
});
});
} else {
StartPresence();
}
process.on("unhandledRejection", console.error);