Skip to content

Commit 635893d

Browse files
committed
feat: Discord Rich Presence seeker logic
1 parent 0078bc7 commit 635893d

File tree

3 files changed

+74
-13
lines changed

3 files changed

+74
-13
lines changed

electron/actions/discord/setActivity.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,28 @@ import {
55
export default function (
66
{
77
playingData,
8-
buttons
8+
buttons,
9+
startTime,
10+
isPlaying
911
}
1012
) {
1113
const {
1214
trackTitle,
1315
artistName,
1416
albumTitle,
15-
image
17+
image,
18+
duration
1619
} = playingData
1720

21+
const durationComputed = (
22+
isPlaying ? duration : 0
23+
)
24+
25+
const endTime = (
26+
startTime +
27+
durationComputed * 1000
28+
)
29+
1830
const activity = {
1931
type: 2,
2032
details: trackTitle,
@@ -27,7 +39,9 @@ export default function (
2739
smallImageText: appName,
2840
...(buttons.length && {
2941
buttons
30-
})
42+
}),
43+
startTimestamp: startTime,
44+
endTimestamp: endTime
3145
}
3246

3347
discordClient

src/components/layout/observers/TheDiscordObserver.vue

+35-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import discordStore from '@/stores/discord'
1212
import playerStore from '@/stores/player'
1313
import profileStore from '@/stores/profile'
14+
import audioStore from '@/stores/audio'
1415
import {
1516
homepage
1617
} from '@/../package.json'
@@ -29,6 +30,7 @@ export default {
2930
name: 'TheDiscordObserver',
3031
data () {
3132
return {
33+
playerPlayingStartTime: null,
3234
isConnected: false
3335
}
3436
},
@@ -55,6 +57,12 @@ export default {
5557
profileId: 'id'
5658
}
5759
),
60+
...mapState(
61+
audioStore,
62+
{
63+
audioStatus: 'status'
64+
}
65+
),
5866
activityDataFormatted () {
5967
return JSON.stringify(
6068
this.activityData
@@ -63,10 +71,11 @@ export default {
6371
activityData () {
6472
if (this.playerPlaying) {
6573
return {
66-
playingData:
67-
this.playingData,
68-
buttons:
69-
this.buttonsFiltered
74+
playingData: this.playingData,
75+
buttons: this.buttonsFiltered,
76+
startTime:
77+
this.playerPlayingStartTime,
78+
isPlaying: this.isPlaying
7079
}
7180
} else {
7281
return null
@@ -77,7 +86,8 @@ export default {
7786
trackTitle: this.trackTitle,
7887
artistName: this.artistName,
7988
albumTitle: this.albumTitle,
80-
image: this.image
89+
image: this.image,
90+
duration: this.duration
8191
}
8292
},
8393
trackTitle () {
@@ -95,6 +105,9 @@ export default {
95105
defaultImage
96106
)
97107
},
108+
duration () {
109+
return this.playerPlaying.duration
110+
},
98111
buttonsFiltered () {
99112
return this.buttonsFormatted.filter(
100113
e => e
@@ -207,6 +220,11 @@ export default {
207220
trackData: this.playerPlaying
208221
}
209222
)
223+
},
224+
isPlaying () {
225+
return (
226+
this.audioStatus === 'play'
227+
)
210228
}
211229
},
212230
watch: {
@@ -215,9 +233,12 @@ export default {
215233
handler:
216234
'handleIsPlayerWithDiscordRichPresenceChange'
217235
},
236+
playerPlaying: {
237+
immediate: true,
238+
handler: 'handlePlayerPlayingChange'
239+
},
218240
isConnected: 'handleIsConnectedChange',
219-
activityData:
220-
'handleActivityDataChange'
241+
activityData: 'handleActivityDataChange'
221242
},
222243
mounted () {
223244
window
@@ -262,6 +283,13 @@ export default {
262283
this.updateActivity()
263284
}
264285
},
286+
handlePlayerPlayingChange (
287+
value
288+
) {
289+
this.playerPlayingStartTime = (
290+
value ? Date.now() : null
291+
)
292+
},
265293
connect () {
266294
if (!this.isConnected) {
267295
window

src/components/layout/panels/ThePlayerVariantsPanel/PlayerPanel/AudioElement.vue

+22-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import {
2525
} from 'pinia'
2626
import audioStore from '@/stores/audio'
2727
import playerStore from '@/stores/player'
28+
import {
29+
update as updateGlobalStore
30+
} from '@/helpers/actions/store/global'
2831
2932
export default {
3033
name: 'AudioElement',
@@ -173,7 +176,7 @@ export default {
173176
)
174177
},
175178
handlePlay () {
176-
this.setAudioStatus(
179+
this.setAudioStatusWithGlobal(
177180
'play'
178181
)
179182
},
@@ -189,7 +192,7 @@ export default {
189192
)
190193
},
191194
handlePause () {
192-
this.setAudioStatus(
195+
this.setAudioStatusWithGlobal(
193196
'pause'
194197
)
195198
},
@@ -269,7 +272,7 @@ export default {
269272
.load()
270273
},
271274
stopAudio () {
272-
this.setAudioStatus(
275+
this.setAudioStatusWithGlobal(
273276
'stop'
274277
)
275278
@@ -294,6 +297,22 @@ export default {
294297
progress
295298
)
296299
}
300+
},
301+
setAudioStatusWithGlobal (
302+
value
303+
) {
304+
this.setAudioStatus(
305+
value
306+
)
307+
308+
updateGlobalStore(
309+
{
310+
'audio.status': value
311+
},
312+
{
313+
isSave: false
314+
}
315+
)
297316
}
298317
}
299318
}

0 commit comments

Comments
 (0)