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' ;
8
2
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 ;
9
12
const { writeFileSync } = require ( 'fs' ) ;
10
13
const { resolve } = require ( 'path' ) ;
11
14
12
15
let modal ;
13
- let Menu ;
14
- let rpc ;
16
+ let menu ;
15
17
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' ) ) ;
17
28
let enableRPC ;
29
+ let enableCmdNames ;
18
30
19
31
function setMenu ( ) {
20
- Menu = nw . Window . get ( ) . menu ;
32
+ menu = Window . get ( ) . menu ;
21
33
22
- const dbmRichPresenceMenu = new nw . Menu ( ) ;
23
- dbmRichPresenceMenu . append ( new nw . MenuItem ( {
34
+ const dbmRichPresenceMenu = new Menu ( ) ;
35
+ dbmRichPresenceMenu . append ( new MenuItem ( {
24
36
label : 'DBM Rich Presence' ,
25
- click : ( ) => jQuery ( '#discordRichPresence ' ) . modal ( 'show' )
37
+ click : ( ) => jQuery ( '#dbmRichPresence ' ) . modal ( 'show' )
26
38
} ) )
27
39
28
- Menu . append ( new nw . MenuItem ( {
40
+ menu . append ( new MenuItem ( {
29
41
label : 'Integrations' ,
30
42
submenu : dbmRichPresenceMenu
31
43
} ) ) ;
32
44
}
33
45
34
46
function setModal ( ) {
35
47
modal = document . createElement ( 'div' ) ;
36
- modal . id = 'discordRichPresence ' ;
48
+ modal . id = 'dbmRichPresence ' ;
37
49
modal . classList . add ( 'ui' ) ;
38
50
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;' ) ;
40
52
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
+ ` ;
50
67
51
68
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 ;
53
72
54
73
setInterval ( ( ) => {
55
74
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
+ } ) ) ;
56
81
57
- writeFileSync ( resolve ( 'rpcSettings.json' ) , JSON . stringify ( { enableRPC } ) ) ;
58
-
59
82
if ( enableRPC ) {
60
83
if ( ! rpc ) setRichPresence ( ) ;
61
84
} else stopRichPresence ( ) ;
@@ -67,24 +90,19 @@ function setRichPresence() {
67
90
68
91
const { Client } = require ( 'discord-rpc' ) ;
69
92
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 ( ) } ` ;
81
95
82
96
rpc . on ( 'ready' , ( ) => {
83
- setActivity ( ) ;
84
- setTimeout ( ( ) => setActivity ( ) , 1000 ) ;
97
+ try {
98
+ overrideFunctions ( ) ;
99
+ rpc . setActivity ( rpcOptions ) ;
100
+ } catch ( err ) {
101
+ alert ( err ) ;
102
+ }
85
103
} ) ;
86
104
87
- rpc . login ( { clientId : '675588061140353025' } ) . catch ( ( ) => alert ( 'Some error ocurred on set your RPC.' ) ) ;
105
+ rpc . login ( { clientId : '675588061140353025' } ) . catch ( alert ) ;
88
106
}
89
107
90
108
function stopRichPresence ( ) {
@@ -96,6 +114,112 @@ function stopRichPresence() {
96
114
} ) ;
97
115
}
98
116
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
+
99
222
setMenu ( ) ;
100
223
setModal ( ) ;
224
+
101
225
setRichPresence ( ) ;
0 commit comments