@@ -77,14 +77,14 @@ object DiscordRPC : Module(
77
77
}
78
78
79
79
private fun start () {
80
- BackgroundScope .launchLooping(job)
81
-
82
80
LambdaMod .LOG .info(" Starting Discord RPC" )
81
+
83
82
try {
84
83
ipc.connect()
85
84
rpcBuilder.setStartTimestamp(OffsetDateTime .now())
86
85
val richPresence = rpcBuilder.build()
87
86
ipc.sendRichPresence(richPresence)
87
+ BackgroundScope .launchLooping(job)
88
88
89
89
LambdaMod .LOG .info(" Discord RPC initialised successfully" )
90
90
} catch (e: NoDiscordClientException ) {
@@ -94,11 +94,11 @@ object DiscordRPC : Module(
94
94
}
95
95
96
96
private fun end () {
97
- if (! initialised || ipc.status != PipeStatus .CONNECTED ) return
98
- BackgroundScope .cancel(job)
99
-
100
97
LambdaMod .LOG .info(" Shutting down Discord RPC..." )
101
- ipc.close()
98
+ BackgroundScope .cancel(job)
99
+ if (initialised && ipc.status == PipeStatus .CONNECTED ) {
100
+ ipc.close()
101
+ }
102
102
}
103
103
104
104
private fun showCoordsConfirm (): Boolean {
@@ -109,12 +109,34 @@ object DiscordRPC : Module(
109
109
}
110
110
111
111
private fun updateRPC () {
112
- if (ipc.status == PipeStatus .CONNECTED ) {
113
- val richPresence = rpcBuilder
114
- .setDetails(getLine(line1Left) + getSeparator(0 ) + getLine(line1Right))
115
- .setState(getLine(line2Left) + getSeparator(1 ) + getLine(line2Right))
116
- .build()
117
- ipc.sendRichPresence(richPresence)
112
+ when (ipc.status) {
113
+ PipeStatus .CONNECTED -> {
114
+ val richPresence = rpcBuilder
115
+ .setDetails(getLine(line1Left) + getSeparator(0 ) + getLine(line1Right))
116
+ .setState(getLine(line2Left) + getSeparator(1 ) + getLine(line2Right))
117
+ .build()
118
+ ipc.sendRichPresence(richPresence)
119
+ }
120
+
121
+ PipeStatus .UNINITIALIZED -> {
122
+ tryConnect()
123
+ }
124
+
125
+ PipeStatus .DISCONNECTED -> {
126
+ tryConnect()
127
+ }
128
+
129
+ else -> {
130
+ // Why is this necessary now kotlin? WHY
131
+ }
132
+ }
133
+ }
134
+
135
+ private fun tryConnect () {
136
+ try {
137
+ ipc.connect()
138
+ } catch (e: NoDiscordClientException ) {
139
+ // Add something here if you want to spam the log i guess
118
140
}
119
141
}
120
142
@@ -187,10 +209,11 @@ object DiscordRPC : Module(
187
209
}
188
210
189
211
fun setCustomIcons (capeType : CapeType ? ) {
212
+ // The nullability here is VERY important, DO NOT switch this for an empty string, it causes discord to break
190
213
val text = when (capeType) {
191
214
CapeType .CONTRIBUTOR -> " Contributor"
192
- else -> " "
215
+ else -> null
193
216
}
194
- rpcBuilder.setSmallImage(capeType?.imageKey ? : " " , text)
217
+ rpcBuilder.setSmallImage(capeType?.imageKey, text)
195
218
}
196
219
}
0 commit comments