[discordPresence] Throttle presence updates (#365)

This commit is contained in:
NotForMyCV 2024-07-20 00:06:10 +01:00 committed by GitHub
parent bd566a03fd
commit d6e7243c33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -85,6 +85,7 @@
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const player = () => document.querySelector("#VideoJsPlayer video");
let WAITING_FOR_REFRESH = true;
let SCENE_ID = null;
/** @type {FlattenedSceneData?} */ let cachedSceneData;
@ -201,7 +202,16 @@
);
}
async function setDiscordActivity() {
async function setDiscordActivity(event) {
if (event?.type === "timeupdate") {
if (!WAITING_FOR_REFRESH) {
return;
}
WAITING_FOR_REFRESH = false;
setTimeout(() => (WAITING_FOR_REFRESH = true), 5000);
}
const sceneData = await getSceneData(SCENE_ID);
if (!sceneData) return;

View File

@ -2,7 +2,7 @@ name: Discord Presence
description: Sets currently playing scene data as your Discord status. See README for prerequisites and config options (blue hyperlink next to enable/disable button)
url: https://github.com/stashapp/CommunityScripts/tree/main/plugins/discordPresence
# requires: CommunityScriptsUILibrary
version: 1.1
version: 1.2
settings:
discordClientId:
displayName: Custom Discord application ID