Fix checking YouTube Music as a name
was causing small issues when someone set RPC name as YouTube Music
This commit is contained in:
parent
ba6d8c130c
commit
7c810e127b
2 changed files with 131 additions and 126 deletions
|
|
@ -81,11 +81,13 @@ class PluginManager {
|
|||
|
||||
// skip if YouTube Music is playing and user wants to ignore it
|
||||
if (currentSettings.ignoreYouTubeMusic) {
|
||||
const YOUTUBE_MUSIC_APP_ID = "463097721130188830";
|
||||
const PLUGIN_APP_ID = Constants.APPLICATION_ID;
|
||||
|
||||
const youtubeActivity = SelfPresenceStore.findActivity(
|
||||
(act) =>
|
||||
act.name === "YouTube Music" ||
|
||||
act.application_id === "463097721130188830" ||
|
||||
(act.name && act.name.toLowerCase().includes("youtube music")),
|
||||
act.application_id === YOUTUBE_MUSIC_APP_ID &&
|
||||
act.application_id !== PLUGIN_APP_ID,
|
||||
);
|
||||
if (youtubeActivity) {
|
||||
logVerbose("YouTube Music is currently playing, clearing activity");
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ const debugInfo = {} as {
|
|||
lastTrack?: Track;
|
||||
lastAPIResponse?: any;
|
||||
isSpotifyIgnored?: boolean;
|
||||
isYouTubeMusicIgnored?: boolean;
|
||||
isKizzyIgnored?: boolean;
|
||||
isMetrolistIgnored?: boolean;
|
||||
componentMountErrors?: string[];
|
||||
lastReanimatedError?: string;
|
||||
componentMountCount?: number;
|
||||
|
|
@ -30,181 +33,181 @@ debugInfo.serviceErrors = { lastfm: [], librefm: [], listenbrainz: [] };
|
|||
debugInfo.apiCallCount = 0;
|
||||
debugInfo.connectionAttempts = 0;
|
||||
debugInfo.lastCredentialValidation = {
|
||||
lastfm: false,
|
||||
librefm: false,
|
||||
listenbrainz: false,
|
||||
lastfm: false,
|
||||
librefm: false,
|
||||
listenbrainz: false,
|
||||
};
|
||||
|
||||
const log = (...args: any[]) => console.log("[Debug]", ...args);
|
||||
const logError = (...args: any[]) => console.error("[Debug] Error:", ...args);
|
||||
|
||||
export function setDebugInfo(
|
||||
key: keyof typeof debugInfo,
|
||||
value: (typeof debugInfo)[typeof key],
|
||||
key: keyof typeof debugInfo,
|
||||
value: (typeof debugInfo)[typeof key],
|
||||
) {
|
||||
debugInfo[key] = value;
|
||||
debugInfo[key] = value;
|
||||
|
||||
// log the important stuff
|
||||
if (key === "lastError" && value) {
|
||||
logError("Error recorded:", (value as Error).message);
|
||||
} else if (key === "lastTrack" && value) {
|
||||
log(
|
||||
"Track updated:",
|
||||
`${(value as Track).artist} - ${(value as Track).name}`,
|
||||
);
|
||||
} else if (key === "currentService" && value) {
|
||||
log("Service changed to:", value);
|
||||
}
|
||||
// log the important stuff
|
||||
if (key === "lastError" && value) {
|
||||
logError("Error recorded:", (value as Error).message);
|
||||
} else if (key === "lastTrack" && value) {
|
||||
log(
|
||||
"Track updated:",
|
||||
`${(value as Track).artist} - ${(value as Track).name}`,
|
||||
);
|
||||
} else if (key === "currentService" && value) {
|
||||
log("Service changed to:", value);
|
||||
}
|
||||
|
||||
__forceUpdate?.();
|
||||
__forceUpdate?.();
|
||||
}
|
||||
|
||||
export function incrementApiCall() {
|
||||
debugInfo.apiCallCount = (debugInfo.apiCallCount || 0) + 1;
|
||||
log(`API call count: ${debugInfo.apiCallCount}`);
|
||||
debugInfo.apiCallCount = (debugInfo.apiCallCount || 0) + 1;
|
||||
log(`API call count: ${debugInfo.apiCallCount}`);
|
||||
}
|
||||
|
||||
export function recordServiceError(service: ServiceType, error: string) {
|
||||
debugInfo.serviceErrors = debugInfo.serviceErrors || {
|
||||
lastfm: [],
|
||||
librefm: [],
|
||||
listenbrainz: [],
|
||||
};
|
||||
debugInfo.serviceErrors[service] = debugInfo.serviceErrors[service] || [];
|
||||
debugInfo.serviceErrors[service].push(
|
||||
`${new Date().toISOString()}: ${error}`,
|
||||
);
|
||||
debugInfo.serviceErrors = debugInfo.serviceErrors || {
|
||||
lastfm: [],
|
||||
librefm: [],
|
||||
listenbrainz: [],
|
||||
};
|
||||
debugInfo.serviceErrors[service] = debugInfo.serviceErrors[service] || [];
|
||||
debugInfo.serviceErrors[service].push(
|
||||
`${new Date().toISOString()}: ${error}`,
|
||||
);
|
||||
|
||||
// don't let error logs get too long
|
||||
if (debugInfo.serviceErrors[service].length > 10) {
|
||||
debugInfo.serviceErrors[service] =
|
||||
// don't let error logs get too long
|
||||
if (debugInfo.serviceErrors[service].length > 10) {
|
||||
debugInfo.serviceErrors[service] =
|
||||
debugInfo.serviceErrors[service].slice(-10);
|
||||
}
|
||||
}
|
||||
|
||||
logError(`${service} error:`, error);
|
||||
__forceUpdate?.();
|
||||
logError(`${service} error:`, error);
|
||||
__forceUpdate?.();
|
||||
}
|
||||
|
||||
export function recordCredentialValidation(
|
||||
service: ServiceType,
|
||||
isValid: boolean,
|
||||
service: ServiceType,
|
||||
isValid: boolean,
|
||||
) {
|
||||
debugInfo.lastCredentialValidation = debugInfo.lastCredentialValidation || {
|
||||
lastfm: false,
|
||||
librefm: false,
|
||||
listenbrainz: false,
|
||||
};
|
||||
debugInfo.lastCredentialValidation[service] = isValid;
|
||||
log(
|
||||
`${service} credentials validation:`,
|
||||
isValid ? "✅ Valid" : "❌ Invalid",
|
||||
);
|
||||
__forceUpdate?.();
|
||||
debugInfo.lastCredentialValidation = debugInfo.lastCredentialValidation || {
|
||||
lastfm: false,
|
||||
librefm: false,
|
||||
listenbrainz: false,
|
||||
};
|
||||
debugInfo.lastCredentialValidation[service] = isValid;
|
||||
log(
|
||||
`${service} credentials validation:`,
|
||||
isValid ? "✅ Valid" : "❌ Invalid",
|
||||
);
|
||||
__forceUpdate?.();
|
||||
}
|
||||
|
||||
export function recordSuccessfulUpdate() {
|
||||
debugInfo.lastSuccessfulUpdate = new Date().toISOString();
|
||||
log("Successful update recorded at:", debugInfo.lastSuccessfulUpdate);
|
||||
__forceUpdate?.();
|
||||
debugInfo.lastSuccessfulUpdate = new Date().toISOString();
|
||||
log("Successful update recorded at:", debugInfo.lastSuccessfulUpdate);
|
||||
__forceUpdate?.();
|
||||
}
|
||||
|
||||
export function incrementConnectionAttempt() {
|
||||
debugInfo.connectionAttempts = (debugInfo.connectionAttempts || 0) + 1;
|
||||
log(`Connection attempt: ${debugInfo.connectionAttempts}`);
|
||||
debugInfo.connectionAttempts = (debugInfo.connectionAttempts || 0) + 1;
|
||||
log(`Connection attempt: ${debugInfo.connectionAttempts}`);
|
||||
}
|
||||
|
||||
export function resetConnectionAttempts() {
|
||||
debugInfo.connectionAttempts = 0;
|
||||
log("Connection attempts reset");
|
||||
debugInfo.connectionAttempts = 0;
|
||||
log("Connection attempts reset");
|
||||
}
|
||||
|
||||
export function logComponentMount(componentName: string) {
|
||||
debugInfo.componentMountCount = (debugInfo.componentMountCount || 0) + 1;
|
||||
log(
|
||||
`Component mounted: ${componentName} (count: ${debugInfo.componentMountCount})`,
|
||||
);
|
||||
debugInfo.componentMountCount = (debugInfo.componentMountCount || 0) + 1;
|
||||
log(
|
||||
`Component mounted: ${componentName} (count: ${debugInfo.componentMountCount})`,
|
||||
);
|
||||
}
|
||||
|
||||
export function logComponentError(componentName: string, error: any) {
|
||||
const errorMessage = `${componentName}: ${String(error)}`;
|
||||
debugInfo.componentMountErrors = debugInfo.componentMountErrors || [];
|
||||
debugInfo.componentMountErrors.push(errorMessage);
|
||||
const errorMessage = `${componentName}: ${String(error)}`;
|
||||
debugInfo.componentMountErrors = debugInfo.componentMountErrors || [];
|
||||
debugInfo.componentMountErrors.push(errorMessage);
|
||||
|
||||
if (String(error).includes("Reanimated")) {
|
||||
debugInfo.lastReanimatedError = errorMessage;
|
||||
}
|
||||
if (String(error).includes("Reanimated")) {
|
||||
debugInfo.lastReanimatedError = errorMessage;
|
||||
}
|
||||
|
||||
logError(`Component error in ${componentName}:`, error);
|
||||
__forceUpdate?.();
|
||||
logError(`Component error in ${componentName}:`, error);
|
||||
__forceUpdate?.();
|
||||
}
|
||||
|
||||
export function logNavigationError(error: any) {
|
||||
debugInfo.lastNavigationError = String(error);
|
||||
logError("Navigation error:", error);
|
||||
__forceUpdate?.();
|
||||
debugInfo.lastNavigationError = String(error);
|
||||
logError("Navigation error:", error);
|
||||
__forceUpdate?.();
|
||||
}
|
||||
|
||||
export function incrementSettingsLoad() {
|
||||
debugInfo.settingsLoadAttempts = (debugInfo.settingsLoadAttempts || 0) + 1;
|
||||
log(`Settings load attempt: ${debugInfo.settingsLoadAttempts}`);
|
||||
debugInfo.settingsLoadAttempts = (debugInfo.settingsLoadAttempts || 0) + 1;
|
||||
log(`Settings load attempt: ${debugInfo.settingsLoadAttempts}`);
|
||||
}
|
||||
|
||||
export function getDebugSummary(): string {
|
||||
const summary = {
|
||||
status: {
|
||||
currentService: debugInfo.currentService || "unknown",
|
||||
lastSuccessfulUpdate: debugInfo.lastSuccessfulUpdate || "never",
|
||||
connectionAttempts: debugInfo.connectionAttempts || 0,
|
||||
apiCallCount: debugInfo.apiCallCount || 0,
|
||||
},
|
||||
validation: debugInfo.lastCredentialValidation,
|
||||
errors: {
|
||||
totalComponentErrors: debugInfo.componentMountErrors?.length || 0,
|
||||
lastError: debugInfo.lastError?.message || "none",
|
||||
serviceErrors: Object.fromEntries(
|
||||
Object.entries(debugInfo.serviceErrors || {}).map(
|
||||
([service, errors]) => [service, errors.length],
|
||||
),
|
||||
),
|
||||
},
|
||||
lastTrack: debugInfo.lastTrack
|
||||
? {
|
||||
artist: debugInfo.lastTrack.artist,
|
||||
name: debugInfo.lastTrack.name,
|
||||
nowPlaying: debugInfo.lastTrack.nowPlaying,
|
||||
service: debugInfo.currentService,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
const summary = {
|
||||
status: {
|
||||
currentService: debugInfo.currentService || "unknown",
|
||||
lastSuccessfulUpdate: debugInfo.lastSuccessfulUpdate || "never",
|
||||
connectionAttempts: debugInfo.connectionAttempts || 0,
|
||||
apiCallCount: debugInfo.apiCallCount || 0,
|
||||
},
|
||||
validation: debugInfo.lastCredentialValidation,
|
||||
errors: {
|
||||
totalComponentErrors: debugInfo.componentMountErrors?.length || 0,
|
||||
lastError: debugInfo.lastError?.message || "none",
|
||||
serviceErrors: Object.fromEntries(
|
||||
Object.entries(debugInfo.serviceErrors || {}).map(
|
||||
([service, errors]) => [service, errors.length],
|
||||
),
|
||||
),
|
||||
},
|
||||
lastTrack: debugInfo.lastTrack
|
||||
? {
|
||||
artist: debugInfo.lastTrack.artist,
|
||||
name: debugInfo.lastTrack.name,
|
||||
nowPlaying: debugInfo.lastTrack.nowPlaying,
|
||||
service: debugInfo.currentService,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
|
||||
return JSON.stringify(summary, null, 2);
|
||||
return JSON.stringify(summary, null, 2);
|
||||
}
|
||||
|
||||
export function useDebugInfo(): string {
|
||||
try {
|
||||
[, __forceUpdate] = useReducer((x) => ~x, 0);
|
||||
try {
|
||||
[, __forceUpdate] = useReducer((x) => ~x, 0);
|
||||
|
||||
// add some extra runtime info
|
||||
const runtimeInfo = {
|
||||
...debugInfo,
|
||||
timestamp: new Date().toISOString(),
|
||||
reactVersion: "18.0.0", // we can't check the real version here
|
||||
hasReanimatedError: !!debugInfo.lastReanimatedError,
|
||||
totalErrors: debugInfo.componentMountErrors?.length || 0,
|
||||
summary: getDebugSummary(),
|
||||
};
|
||||
// add some extra runtime info
|
||||
const runtimeInfo = {
|
||||
...debugInfo,
|
||||
timestamp: new Date().toISOString(),
|
||||
reactVersion: "18.0.0", // we can't check the real version here
|
||||
hasReanimatedError: !!debugInfo.lastReanimatedError,
|
||||
totalErrors: debugInfo.componentMountErrors?.length || 0,
|
||||
summary: getDebugSummary(),
|
||||
};
|
||||
|
||||
return JSON.stringify(runtimeInfo, null, 4);
|
||||
} catch (error) {
|
||||
logError("Error in useDebugInfo:", error);
|
||||
return JSON.stringify(
|
||||
{
|
||||
error: "Failed to generate debug info",
|
||||
errorMessage: String(error),
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
null,
|
||||
4,
|
||||
);
|
||||
}
|
||||
return JSON.stringify(runtimeInfo, null, 4);
|
||||
} catch (error) {
|
||||
logError("Error in useDebugInfo:", error);
|
||||
return JSON.stringify(
|
||||
{
|
||||
error: "Failed to generate debug info",
|
||||
errorMessage: String(error),
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
null,
|
||||
4,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue