fix(mpris): normalize local cover URLs
This commit is contained in:
1 parent
2c13986244
commit
f620e55dfe
1 file changed
+29
-1
@@ -164,18 +164,46 @@ export async function playTrack(
|
||||
*/
|
||||
export async function updateMediaMetadata(metadata: MediaMetadata): Promise<void> {
|
||||
try {
|
||||
const coverUrl = normalizeCoverUrlForMetadata(metadata.coverUrl);
|
||||
await invoke('set_media_metadata', {
|
||||
title: metadata.title,
|
||||
artist: metadata.artist,
|
||||
album: metadata.album,
|
||||
durationSecs: metadata.durationSecs,
|
||||
coverUrl: metadata.coverUrl
|
||||
coverUrl
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to update media metadata:', err);
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeCoverUrlForMetadata(coverUrl?: string | null): string | null {
|
||||
if (!coverUrl) return null;
|
||||
const assetPrefix = 'asset://localhost/';
|
||||
if (coverUrl.startsWith(assetPrefix)) {
|
||||
const encodedPath = coverUrl.slice(assetPrefix.length);
|
||||
try {
|
||||
const decodedPath = decodeURIComponent(encodedPath);
|
||||
return `file://${encodeURI(decodedPath)}`;
|
||||
} catch {
|
||||
return coverUrl;
|
||||
}
|
||||
}
|
||||
if (coverUrl.startsWith('asset://')) {
|
||||
const encodedPath = coverUrl.replace(/^asset:\/\/+/, '');
|
||||
try {
|
||||
const decodedPath = decodeURIComponent(encodedPath);
|
||||
return `file://${encodeURI(decodedPath)}`;
|
||||
} catch {
|
||||
return coverUrl;
|
||||
}
|
||||
}
|
||||
if (coverUrl.startsWith('/')) {
|
||||
return `file://${encodeURI(coverUrl)}`;
|
||||
}
|
||||
return coverUrl;
|
||||
}
|
||||
|
||||
// ============ System Notifications ============
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user