Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit e8acbd8

Browse files
committed
version 1.1.0
2 parents 6e626de + dd20b94 commit e8acbd8

File tree

3 files changed

+170
-48
lines changed

3 files changed

+170
-48
lines changed

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
📖 A Rich Presence of Discord that shows your DBM information.
44

5-
> **Note:** This is just a first version, soon it will be super cool!
6-
7-
![](https://i.imgur.com/4IPNq8U.png)
5+
![](https://i.imgur.com/KSAR1JE.png)
86

97
![](https://img.shields.io/github/v/release/CapOliveiraBr/DBM-Rich-Presence?style=for-the-badge) ![](https://img.shields.io/github/license/CapOliveiraBr/DBM-Rich-Presence?logo=https%3A%2F%2Fimg.shields.io%2Fgithub%2Flicense%2FCapOliveiraBr%2FDBM-Rich-Presence%3Fstyle%3Dsocial&style=for-the-badge)
108

@@ -46,7 +44,7 @@ Download the latest release of the RPC [here](https://github.com/CapOliveiraBr/D
4644
When you install the RPC, a new menu tab is added to DBM, called "**Integrations**", inside it you can go to **DBM Rich Presence** where you can see some settings.
4745

4846
![](https://i.imgur.com/Mz1xPcz.png)
49-
![](https://i.imgur.com/jVgGIJ0.png)
47+
![](https://i.imgur.com/926LZKv.png)
5048

5149
---
5250

src/dbm-rich-presence.js

+167-43
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,84 @@
1-
/*======================================================*
2-
* *
3-
* # DBM Rich Presence - v1.0.0 *
4-
* Created by Cap *
5-
* https://github.com/CapOliveiraBr/DBM-Rich-Presence *
6-
* *
7-
*======================================================*/
1+
const rpcVersion = '1.1.0';
82

3+
/*======================================================*
4+
* *
5+
* # DBM Rich Presence - v1.1.0 *
6+
* Created by Cap & General Wrex *
7+
* https://github.com/CapOliveiraBr/DBM-Rich-Presence *
8+
* *
9+
*======================================================*/
10+
11+
const { Window, Menu, MenuItem } = nw;
912
const { writeFileSync } = require('fs');
1013
const { resolve } = require('path');
1114

1215
let modal;
13-
let Menu;
14-
let rpc;
16+
let menu;
1517

16-
const settings = require(resolve('rpcSettings.json'));
18+
let rpc;
19+
let rpcOptions = {
20+
details: 'Idling',
21+
state: 'No Project Opened',
22+
largeImageKey: 'dbm',
23+
largeImageText: `DBM Rich Presence v${rpcVersion}`,
24+
startTimestamp: Date.now()
25+
};
26+
27+
const rpcSettings = require(resolve('rpcSettings.json'));
1728
let enableRPC;
29+
let enableCmdNames;
1830

1931
function setMenu() {
20-
Menu = nw.Window.get().menu;
32+
menu = Window.get().menu;
2133

22-
const dbmRichPresenceMenu = new nw.Menu();
23-
dbmRichPresenceMenu.append(new nw.MenuItem({
34+
const dbmRichPresenceMenu = new Menu();
35+
dbmRichPresenceMenu.append(new MenuItem({
2436
label: 'DBM Rich Presence',
25-
click: () => jQuery('#discordRichPresence').modal('show')
37+
click: () => jQuery('#dbmRichPresence').modal('show')
2638
}))
2739

28-
Menu.append(new nw.MenuItem({
40+
menu.append(new MenuItem({
2941
label: 'Integrations',
3042
submenu: dbmRichPresenceMenu
3143
}));
3244
}
3345

3446
function setModal() {
3547
modal = document.createElement('div');
36-
modal.id = 'discordRichPresence';
48+
modal.id = 'dbmRichPresence';
3749
modal.classList.add('ui');
3850
modal.classList.add('modal');
39-
modal.setAttribute('style', 'padding: 20px; height: 220px; border-radius: 10px; background-color: #36393e; border: 2px solid #000;');
51+
modal.setAttribute('style', 'padding: 20px; height: 320px; border-radius: 10px; background-color: #36393e; border: 2px solid #000;');
4052
modal.innerHTML = `
41-
<h2>DBM Rich Presence - v1.0.0</h2>
42-
Created by <b>Cap</b> - <a href="#" onclick="nw.Shell.openExternal('https://github.com/CapOliveiraBr/DBM-Rich-Presence')">Repository</a>
43-
<h3>Settings</h3>
44-
Enable RPC:<br><br>
45-
<select id="enableRPC" class="round">
46-
<option value="true">True</option>
47-
<option value="false">False</option>
48-
</select>
49-
`;
53+
<h2>DBM Rich Presence - v${rpcVersion}</h2>
54+
Created by <b>Cap & General Wrex</b> - <a href="#" onclick="nw.Shell.openExternal('https://github.com/CapOliveiraBr/DBM-Rich-Presence')">Repository</a>
55+
<h3>Settings</h3>
56+
Enable RPC:<br><br>
57+
<select id="enableRPC" class="round">
58+
<option value="true">True</option>
59+
<option value="false">False</option>
60+
</select><br><br>
61+
Show Command/Event Names:<br><br>
62+
<select id="enableCmdNames" class="round">
63+
<option value="true">True</option>
64+
<option value="false">False</option>
65+
</select>
66+
`;
5067

5168
document.body.appendChild(modal);
52-
document.getElementById('enableRPC').value = settings.enableRPC;
69+
70+
document.getElementById('enableRPC').value = rpcSettings.enableRPC;
71+
document.getElementById('enableCmdNames').value = rpcSettings.enableCmdNames;
5372

5473
setInterval(() => {
5574
enableRPC = document.getElementById('enableRPC').value === 'true' ? true : false;
75+
enableCmdNames = document.getElementById('enableCmdNames').value === 'true' ? true : false;
76+
77+
writeFileSync(resolve('rpcSettings.json'), JSON.stringify({
78+
enableRPC,
79+
enableCmdNames
80+
}));
5681

57-
writeFileSync(resolve('rpcSettings.json'), JSON.stringify({ enableRPC }));
58-
5982
if (enableRPC) {
6083
if (!rpc) setRichPresence();
6184
} else stopRichPresence();
@@ -67,24 +90,19 @@ function setRichPresence() {
6790

6891
const { Client } = require('discord-rpc');
6992
rpc = new Client({ transport: 'ipc' });
70-
71-
const stateVal = `Project: ${require(resolve('settings.json'))['current-project'].replace(/\\/g, '/').split('/').slice(-1).toString()}`;
72-
73-
function setActivity() {
74-
rpc.setActivity({
75-
state: stateVal,
76-
largeImageKey: 'dbm',
77-
largeImageText: 'DBM Rich Presence v1.0.0',
78-
startTimestamp: Date.now()
79-
});
80-
}
93+
94+
rpcOptions.state = `Project: ${DBM._currentProject.replace(/\\/g, '/').split('/').slice(-1).toString()}`;
8195

8296
rpc.on('ready', () => {
83-
setActivity();
84-
setTimeout(() => setActivity(), 1000);
97+
try {
98+
overrideFunctions();
99+
rpc.setActivity(rpcOptions);
100+
} catch (err) {
101+
alert(err);
102+
}
85103
});
86104

87-
rpc.login({ clientId: '675588061140353025' }).catch(() => alert('Some error ocurred on set your RPC.'));
105+
rpc.login({ clientId: '675588061140353025' }).catch(alert);
88106
}
89107

90108
function stopRichPresence() {
@@ -96,6 +114,112 @@ function stopRichPresence() {
96114
});
97115
}
98116

117+
function getName(type, index) {
118+
switch (type) {
119+
case 'Commands':
120+
return DBM.$cmds[index] && DBM.$cmds[index].name ? DBM.$cmds[index].name : false;
121+
case 'Events':
122+
return DBM.$evts[index] && DBM.$evts[index].name ? DBM.$evts[index].name : false;
123+
}
124+
}
125+
126+
function overrideFunctions() {
127+
const cache = {
128+
Commands: enableCmdNames ? `Command: ${getName('Commands', 1) || `None`}` : `Editing Commands`,
129+
Events: enableCmdNames ? `Event: ${getName('Events', 1) || `None`}` : `Editing Events`,
130+
Settings: 'Editing Bot Settings'
131+
};
132+
133+
let section = 'Commands';
134+
135+
const shiftTabs = DBM.shiftTabs;
136+
DBM.shiftTabs = function(event, sect, index) {
137+
try {
138+
section = sect;
139+
rpcOptions.details = cache[sect];
140+
rpc.setActivity(rpcOptions);
141+
} catch (err) {
142+
alert(err);
143+
}
144+
145+
shiftTabs.apply(this, arguments);
146+
}
147+
148+
const onCommandClick = DBM.onCommandClick;
149+
DBM.onCommandClick = function(index) {
150+
try {
151+
const type = section.slice(0, -1);
152+
const details = enableCmdNames ? `${index ? `${type}: ` : ' '}${index ? (getName(section, index) || `New ${type}`) : 'None Selected'}` : `Editing ${section}`;
153+
154+
cache['Commands'] = details;
155+
rpcOptions.details = details;
156+
rpcOptions.state = `Project: ${DBM._currentProject.replace(/\\/g, '/').split('/').slice(-1).toString()}`;
157+
rpc.setActivity(rpcOptions);
158+
} catch (err) {
159+
alert(err);
160+
}
161+
162+
onCommandClick.apply(this, arguments);
163+
}
164+
165+
const eonCommandClick = DBM.eonCommandClick;
166+
DBM.eonCommandClick = function(index) {
167+
try {
168+
const type = section.slice(0, -1);
169+
const details = enableCmdNames ? `${index ? `${type}: ` : ' '}${index ? (getName(section, index) || `New ${type}`) : 'None Selected'}` : `Editing ${section}`;
170+
171+
cache['Events'] = details;
172+
rpcOptions.details = details;
173+
rpcOptions.state = `Project: ${DBM._currentProject.replace(/\\/g, '/').split('/').slice(-1).toString()}`;
174+
175+
rpc.setActivity(rpcOptions);
176+
} catch (err) {
177+
alert(err);
178+
}
179+
180+
eonCommandClick.apply(this, arguments);
181+
}
182+
183+
const createNewProject = DBM.createNewProject;
184+
DBM.createNewProject = function() {
185+
try {
186+
rpcOptions.state = `Creating Project...`;
187+
rpcOptions.startTimestamp = Date.now()
188+
rpc.setActivity(rpcOptions);
189+
} catch (err) {
190+
alert(err);
191+
}
192+
193+
createNewProject.apply(this, arguments);
194+
}
195+
196+
const openProject = DBM.openProject;
197+
DBM.openProject = function() {
198+
try {
199+
rpcOptions.state = 'Opening Project...';
200+
rpcOptions.startTimestamp = Date.now()
201+
rpc.setActivity(rpcOptions);
202+
} catch (err) {
203+
alert(err);
204+
}
205+
206+
openProject.apply(this, arguments);
207+
}
208+
209+
const saveAndClose = DBM.saveAndClose;
210+
DBM.saveAndClose = function() {
211+
try {
212+
rpcOptions.state = `No Project Opened`;
213+
rpc.setActivity(rpcOptions);
214+
} catch (err) {
215+
alert(err);
216+
}
217+
218+
saveAndClose.apply(this, arguments);
219+
}
220+
}
221+
99222
setMenu();
100223
setModal();
224+
101225
setRichPresence();

src/rpcSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"enableRPC":true}
1+
{"enableRPC":true,"enableCmdNames":true}

0 commit comments

Comments
 (0)