fix(plugins/multi-scrobbler/src/utils/activity.ts): fix activity

sometimes disappearing without word, or not showing at all
This commit is contained in:
kmmiio99o 2026-01-31 17:15:40 +01:00
parent 8d82323f65
commit a9d756f0a2
No known key found for this signature in database
GPG key ID: 163FE39F7772D2EC

View file

@ -6,70 +6,39 @@ import Constants from "../constants";
import { stop } from "../manager";
import { AssetManager } from "../modules";
const log = (...args: any[]) => console.log("[Activity]", ...args);
const logError = (...args: any[]) =>
console.error("[Activity] Error:", ...args);
const logVerbose = (...args: any[]) => {
// just log everything for now since checking the setting is tricky here
try {
console.log("[Activity] Verbose:", ...args);
} catch {
console.log("[Activity] Verbose:", ...args);
}
};
// Remove Discord activity
/** Clears the user's activity */
export function clearActivity() {
log("Clearing Discord activity");
return sendRequest(null);
}
// Send activity to Discord or clear it
/** Sends the activity details to Discord */
export function sendRequest(activity: Activity | null) {
if (pluginState.pluginStopped) {
logVerbose("Plugin is stopped, clearing activity");
stop();
activity = null;
}
pluginState.lastActivity = activity;
logVerbose(
"Dispatching activity update:",
activity ? "Setting activity" : "Clearing activity",
);
FluxDispatcher.dispatch({
type: "LOCAL_ACTIVITY_UPDATE",
activity: activity,
pid: 2312,
socketId: "Multi-Service-Scrobbler@Vendetta",
socketId: "Multi-Scrobbler@Vendetta",
});
if (activity) {
log(`Activity set: ${activity.details} - ${activity.state}`);
} else {
log("Activity cleared");
}
}
// Get Discord asset for album art
/** Fetches Discord application assets */
export async function fetchAsset(
asset: string[],
appId: string = Constants.APPLICATION_ID,
): Promise<string[]> {
if (!asset?.length) {
logVerbose("No assets to fetch");
return [];
}
if (!asset?.length) return [];
try {
logVerbose(`Fetching ${asset.length} asset(s):`, asset);
const result = await AssetManager.fetchAssetIds(appId, asset);
logVerbose(`Successfully fetched ${result.length} asset(s)`);
return result;
return await AssetManager.fetchAssetIds(appId, asset);
} catch (error) {
logError("Failed to fetch assets:", error);
console.error("[Multi-Scrobbler] Failed to fetch assets:", error);
return [];
}
}
}