mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
feat(discord): add listening activity type
This commit is contained in:
parent
64d25509b4
commit
84f47df6c1
@ -17,31 +17,30 @@ class DiscordNotifier extends AsyncNotifier<void> {
|
||||
|
||||
var lastPosition = audioPlayer.position;
|
||||
|
||||
final subscriptions =
|
||||
[
|
||||
FlutterDiscordRPC.instance.isConnectedStream.listen((connected) async {
|
||||
final playback = ref.read(audioPlayerProvider);
|
||||
if (connected && playback.activeTrack != null) {
|
||||
await updatePresence(playback.activeTrack!);
|
||||
}
|
||||
}),
|
||||
audioPlayer.playerStateStream.listen((state) async {
|
||||
final playback = ref.read(audioPlayerProvider);
|
||||
if (playback.activeTrack == null) return;
|
||||
final subscriptions = [
|
||||
FlutterDiscordRPC.instance.isConnectedStream.listen((connected) async {
|
||||
final playback = ref.read(audioPlayerProvider);
|
||||
if (connected && playback.activeTrack != null) {
|
||||
await updatePresence(playback.activeTrack!);
|
||||
}
|
||||
}),
|
||||
audioPlayer.playerStateStream.listen((state) async {
|
||||
final playback = ref.read(audioPlayerProvider);
|
||||
if (playback.activeTrack == null) return;
|
||||
|
||||
await updatePresence(ref.read(audioPlayerProvider).activeTrack!);
|
||||
}),
|
||||
audioPlayer.positionStream.listen((position) async {
|
||||
final playback = ref.read(audioPlayerProvider);
|
||||
if (playback.activeTrack != null) {
|
||||
final diff = position.inMilliseconds - lastPosition.inMilliseconds;
|
||||
if (diff > 500 || diff < -500) {
|
||||
await updatePresence(ref.read(audioPlayerProvider).activeTrack!);
|
||||
}),
|
||||
audioPlayer.positionStream.listen((position) async {
|
||||
final playback = ref.read(audioPlayerProvider);
|
||||
if (playback.activeTrack != null) {
|
||||
final diff = position.inMilliseconds - lastPosition.inMilliseconds;
|
||||
if (diff > 500 || diff < -500) {
|
||||
await updatePresence(ref.read(audioPlayerProvider).activeTrack!);
|
||||
}
|
||||
}
|
||||
lastPosition = position;
|
||||
})
|
||||
];
|
||||
}
|
||||
}
|
||||
lastPosition = position;
|
||||
})
|
||||
];
|
||||
|
||||
ref.onDispose(() async {
|
||||
for (final subscription in subscriptions) {
|
||||
@ -83,8 +82,11 @@ class DiscordNotifier extends AsyncNotifier<void> {
|
||||
),
|
||||
],
|
||||
timestamps: RPCTimestamps(
|
||||
start: isPlaying ? DateTime.now().millisecondsSinceEpoch - position.inMilliseconds : null,
|
||||
start: isPlaying
|
||||
? DateTime.now().millisecondsSinceEpoch - position.inMilliseconds
|
||||
: null,
|
||||
),
|
||||
activityType: ActivityType.listening,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -99,4 +101,4 @@ class DiscordNotifier extends AsyncNotifier<void> {
|
||||
}
|
||||
|
||||
final discordProvider =
|
||||
AsyncNotifierProvider<DiscordNotifier, void>(() => DiscordNotifier());
|
||||
AsyncNotifierProvider<DiscordNotifier, void>(() => DiscordNotifier());
|
||||
|
@ -717,7 +717,7 @@ packages:
|
||||
description:
|
||||
path: "packages/flutter_discord_rpc"
|
||||
ref: cargokit
|
||||
resolved-ref: "1b839bf02afd5dfa56b0dc25f60af04aa9bfc7c3"
|
||||
resolved-ref: "331636d8e378e3ac9ad30a4b0d3eed17d5a85fe9"
|
||||
url: "https://github.com/KRTirtho/frb_plugins.git"
|
||||
source: git
|
||||
version: "0.1.0+1"
|
||||
@ -1484,7 +1484,7 @@ packages:
|
||||
description:
|
||||
path: "packages/metadata_god"
|
||||
ref: cargokit
|
||||
resolved-ref: "1b839bf02afd5dfa56b0dc25f60af04aa9bfc7c3"
|
||||
resolved-ref: "331636d8e378e3ac9ad30a4b0d3eed17d5a85fe9"
|
||||
url: "https://github.com/KRTirtho/frb_plugins.git"
|
||||
source: git
|
||||
version: "0.5.3"
|
||||
@ -1987,7 +1987,7 @@ packages:
|
||||
description:
|
||||
path: "packages/smtc_windows"
|
||||
ref: cargokit
|
||||
resolved-ref: "1b839bf02afd5dfa56b0dc25f60af04aa9bfc7c3"
|
||||
resolved-ref: "331636d8e378e3ac9ad30a4b0d3eed17d5a85fe9"
|
||||
url: "https://github.com/KRTirtho/frb_plugins.git"
|
||||
source: git
|
||||
version: "0.1.3"
|
||||
|
Loading…
Reference in New Issue
Block a user