mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55: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;
|
var lastPosition = audioPlayer.position;
|
||||||
|
|
||||||
final subscriptions =
|
final subscriptions = [
|
||||||
[
|
FlutterDiscordRPC.instance.isConnectedStream.listen((connected) async {
|
||||||
FlutterDiscordRPC.instance.isConnectedStream.listen((connected) async {
|
final playback = ref.read(audioPlayerProvider);
|
||||||
final playback = ref.read(audioPlayerProvider);
|
if (connected && playback.activeTrack != null) {
|
||||||
if (connected && playback.activeTrack != null) {
|
await updatePresence(playback.activeTrack!);
|
||||||
await updatePresence(playback.activeTrack!);
|
}
|
||||||
}
|
}),
|
||||||
}),
|
audioPlayer.playerStateStream.listen((state) async {
|
||||||
audioPlayer.playerStateStream.listen((state) async {
|
final playback = ref.read(audioPlayerProvider);
|
||||||
final playback = ref.read(audioPlayerProvider);
|
if (playback.activeTrack == null) return;
|
||||||
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!);
|
await updatePresence(ref.read(audioPlayerProvider).activeTrack!);
|
||||||
}),
|
}
|
||||||
audioPlayer.positionStream.listen((position) async {
|
}
|
||||||
final playback = ref.read(audioPlayerProvider);
|
lastPosition = position;
|
||||||
if (playback.activeTrack != null) {
|
})
|
||||||
final diff = position.inMilliseconds - lastPosition.inMilliseconds;
|
];
|
||||||
if (diff > 500 || diff < -500) {
|
|
||||||
await updatePresence(ref.read(audioPlayerProvider).activeTrack!);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lastPosition = position;
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
ref.onDispose(() async {
|
ref.onDispose(() async {
|
||||||
for (final subscription in subscriptions) {
|
for (final subscription in subscriptions) {
|
||||||
@ -83,8 +82,11 @@ class DiscordNotifier extends AsyncNotifier<void> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
timestamps: RPCTimestamps(
|
timestamps: RPCTimestamps(
|
||||||
start: isPlaying ? DateTime.now().millisecondsSinceEpoch - position.inMilliseconds : null,
|
start: isPlaying
|
||||||
|
? DateTime.now().millisecondsSinceEpoch - position.inMilliseconds
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
|
activityType: ActivityType.listening,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -717,7 +717,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "packages/flutter_discord_rpc"
|
path: "packages/flutter_discord_rpc"
|
||||||
ref: cargokit
|
ref: cargokit
|
||||||
resolved-ref: "1b839bf02afd5dfa56b0dc25f60af04aa9bfc7c3"
|
resolved-ref: "331636d8e378e3ac9ad30a4b0d3eed17d5a85fe9"
|
||||||
url: "https://github.com/KRTirtho/frb_plugins.git"
|
url: "https://github.com/KRTirtho/frb_plugins.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.1.0+1"
|
version: "0.1.0+1"
|
||||||
@ -1484,7 +1484,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "packages/metadata_god"
|
path: "packages/metadata_god"
|
||||||
ref: cargokit
|
ref: cargokit
|
||||||
resolved-ref: "1b839bf02afd5dfa56b0dc25f60af04aa9bfc7c3"
|
resolved-ref: "331636d8e378e3ac9ad30a4b0d3eed17d5a85fe9"
|
||||||
url: "https://github.com/KRTirtho/frb_plugins.git"
|
url: "https://github.com/KRTirtho/frb_plugins.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.5.3"
|
version: "0.5.3"
|
||||||
@ -1987,7 +1987,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "packages/smtc_windows"
|
path: "packages/smtc_windows"
|
||||||
ref: cargokit
|
ref: cargokit
|
||||||
resolved-ref: "1b839bf02afd5dfa56b0dc25f60af04aa9bfc7c3"
|
resolved-ref: "331636d8e378e3ac9ad30a4b0d3eed17d5a85fe9"
|
||||||
url: "https://github.com/KRTirtho/frb_plugins.git"
|
url: "https://github.com/KRTirtho/frb_plugins.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.1.3"
|
version: "0.1.3"
|
||||||
|
Loading…
Reference in New Issue
Block a user