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 { stop } from "../manager";
|
||||||
import { AssetManager } from "../modules";
|
import { AssetManager } from "../modules";
|
||||||
|
|
||||||
const log = (...args: any[]) => console.log("[Activity]", ...args);
|
/** Clears the user's activity */
|
||||||
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
|
|
||||||
export function clearActivity() {
|
export function clearActivity() {
|
||||||
log("Clearing Discord activity");
|
|
||||||
return sendRequest(null);
|
return sendRequest(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send activity to Discord or clear it
|
/** Sends the activity details to Discord */
|
||||||
export function sendRequest(activity: Activity | null) {
|
export function sendRequest(activity: Activity | null) {
|
||||||
if (pluginState.pluginStopped) {
|
if (pluginState.pluginStopped) {
|
||||||
logVerbose("Plugin is stopped, clearing activity");
|
|
||||||
stop();
|
stop();
|
||||||
activity = null;
|
activity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginState.lastActivity = activity;
|
pluginState.lastActivity = activity;
|
||||||
|
|
||||||
logVerbose(
|
|
||||||
"Dispatching activity update:",
|
|
||||||
activity ? "Setting activity" : "Clearing activity",
|
|
||||||
);
|
|
||||||
|
|
||||||
FluxDispatcher.dispatch({
|
FluxDispatcher.dispatch({
|
||||||
type: "LOCAL_ACTIVITY_UPDATE",
|
type: "LOCAL_ACTIVITY_UPDATE",
|
||||||
activity: activity,
|
activity: activity,
|
||||||
pid: 2312,
|
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(
|
export async function fetchAsset(
|
||||||
asset: string[],
|
asset: string[],
|
||||||
appId: string = Constants.APPLICATION_ID,
|
appId: string = Constants.APPLICATION_ID,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
if (!asset?.length) {
|
if (!asset?.length) return [];
|
||||||
logVerbose("No assets to fetch");
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logVerbose(`Fetching ${asset.length} asset(s):`, asset);
|
return await AssetManager.fetchAssetIds(appId, asset);
|
||||||
const result = await AssetManager.fetchAssetIds(appId, asset);
|
|
||||||
logVerbose(`Successfully fetched ${result.length} asset(s)`);
|
|
||||||
return result;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError("Failed to fetch assets:", error);
|
console.error("[Multi-Scrobbler] Failed to fetch assets:", error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue