fix(plugins/multi-scrobbler/src/utils/activity.ts): fix activity
sometimes disappearing without word, or not showing at all
This commit is contained in:
parent
8d82323f65
commit
a9d756f0a2
1 changed files with 8 additions and 39 deletions
|
|
@ -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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue