-
Notifications
You must be signed in to change notification settings - Fork 2
/
rpc.js
67 lines (54 loc) · 1.55 KB
/
rpc.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
const { Client } = require('discord-rpc'),
monitor = require('active-win');
const client = new Client({ transport: 'ipc' }),
clientId = '513802765139574786';
var currentFile = null;
async function checkPhotoshop() {
let window = monitor.sync();
try {
let appExtension = isWin() ? ".exe" : ".app";
let processName = window.owner.name;
let windowTitle = window.title;
if (processName.toLowerCase() == `photoshop${appExtension}`) {
if (windowTitle.includes('.psd') || windowTitle.includes('% (RGB/')) {
let split = windowTitle.split('@');
if (split[0] !== currentFile) {
currentFile = split[0];
updateRP(`Editing ${currentFile}`);
}
} else {
if (currentFile !== "IDLE") {
currentFile = 'IDLE';
updateRP(null);
}
}
}
} catch(e) {
console.log(e);
}
}
function updateRP(status) {
if (status == null) status = 'IDLE';
client.setActivity({
details: 'CC 2018',
state: status,
startTimestamp: new Date(),
largeImageKey: 'pslarge',
smallImageKey: 'pssmall',
largeImageText: 'Adobe Photoshop',
smallImageText: 'Editing',
instance: false
});
console.log(`> Updated Status: ${status}`);
}
function isWin() {
if (process.platform == "win32") return true;
return false;
}
client.on('ready', () => {
console.log("> Connected to Discord using Photoshop Rich Presence!");
setInterval(() => {
checkPhotoshop();
}, 15000);
});
client.login({ clientId }).catch(console.error);