mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-03-11 17:25:32 +00:00
Discord RPC now shows correct position / duration
This commit is contained in:
parent
2eca6576a2
commit
608fc525fb
2 changed files with 16 additions and 32 deletions
|
|
@ -314,10 +314,7 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage>
|
||||||
.duration
|
.duration
|
||||||
.listen((duration) {
|
.listen((duration) {
|
||||||
_currentTotalDuration.value = duration;
|
_currentTotalDuration.value = duration;
|
||||||
discordRpc?.startChapterTimestamp(
|
discordRpc?.updateChapterTimestamp(_currentPosition.value, duration);
|
||||||
_currentPosition.value.inMilliseconds,
|
|
||||||
duration.inMilliseconds,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bool get hasNextEpisode => _streamController.getEpisodeIndex().$1 != 0;
|
bool get hasNextEpisode => _streamController.getEpisodeIndex().$1 != 0;
|
||||||
|
|
@ -785,8 +782,13 @@ mp.register_script_message('call_button_${button.id}_long', button${button.id}lo
|
||||||
|
|
||||||
void _updateRpcTimestamp() {
|
void _updateRpcTimestamp() {
|
||||||
final now = DateTime.now().millisecondsSinceEpoch;
|
final now = DateTime.now().millisecondsSinceEpoch;
|
||||||
if (lastRpcTimestampUpdate + 10000 < now) {
|
if (lastRpcTimestampUpdate + 5000 < now) {
|
||||||
discordRpc?.updateChapterTimestamp(_currentPosition.value.inMilliseconds);
|
if (_currentTotalDuration.value != null) {
|
||||||
|
discordRpc?.updateChapterTimestamp(
|
||||||
|
_currentPosition.value,
|
||||||
|
_currentTotalDuration.value!,
|
||||||
|
);
|
||||||
|
}
|
||||||
lastRpcTimestampUpdate = now;
|
lastRpcTimestampUpdate = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,6 @@ class DiscordRPC {
|
||||||
/// Start timestamp in millis
|
/// Start timestamp in millis
|
||||||
final int startAt = DateTime.timestamp().millisecondsSinceEpoch;
|
final int startAt = DateTime.timestamp().millisecondsSinceEpoch;
|
||||||
|
|
||||||
/// Start timestamp in millis for the current chapter/episode
|
|
||||||
int chapterStartAt = 0;
|
|
||||||
|
|
||||||
/// End timestamp in millis for the current chapter/episode
|
|
||||||
int chapterEndAt = 0;
|
|
||||||
|
|
||||||
/// Temp var
|
/// Temp var
|
||||||
late bool rpcShowReadingWatchingProgress;
|
late bool rpcShowReadingWatchingProgress;
|
||||||
|
|
||||||
|
|
@ -132,32 +126,20 @@ class DiscordRPC {
|
||||||
await updateActivity(timestamps: RPCTimestamps(start: startAt));
|
await updateActivity(timestamps: RPCTimestamps(start: startAt));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> startChapterTimestamp(
|
Future<void> updateChapterTimestamp(
|
||||||
int offsetInMillis,
|
Duration position,
|
||||||
int durationInMillis,
|
Duration duration,
|
||||||
) async {
|
) async {
|
||||||
if (!rpcShowReadingWatchingProgress) {
|
if (!rpcShowReadingWatchingProgress) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chapterStartAt = DateTime.timestamp().millisecondsSinceEpoch;
|
|
||||||
chapterEndAt =
|
|
||||||
DateTime.timestamp().millisecondsSinceEpoch + durationInMillis;
|
|
||||||
await updateActivity(
|
await updateActivity(
|
||||||
timestamps: RPCTimestamps(
|
timestamps: RPCTimestamps(
|
||||||
start: chapterStartAt,
|
start: DateTime.timestamp().subtract(position).millisecondsSinceEpoch,
|
||||||
end: chapterEndAt - offsetInMillis,
|
end: DateTime.timestamp()
|
||||||
),
|
.subtract(position)
|
||||||
);
|
.add(duration)
|
||||||
}
|
.millisecondsSinceEpoch,
|
||||||
|
|
||||||
Future<void> updateChapterTimestamp(int newOffsetInMillis) async {
|
|
||||||
if (!rpcShowReadingWatchingProgress) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await updateActivity(
|
|
||||||
timestamps: RPCTimestamps(
|
|
||||||
start: chapterStartAt,
|
|
||||||
end: chapterEndAt - newOffsetInMillis,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue