mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-14 20:40:21 +02:00
25bfb65b6d
* add getImageUrl to domain endpoints * add new ItemImage component and hooks to generate image url * add configuration for image resolution based on types
36 lines
945 B
TypeScript
36 lines
945 B
TypeScript
import isElectron from 'is-electron';
|
|
|
|
import { QueueSong } from '/@/shared/types/domain-types';
|
|
|
|
const remote = isElectron() ? window.api.remote : null;
|
|
const mediaSession = navigator.mediaSession;
|
|
|
|
export const updateSong = (song: QueueSong | undefined, imageUrl?: null | string) => {
|
|
if (mediaSession) {
|
|
let metadata: MediaMetadata;
|
|
|
|
if (song?.id) {
|
|
let artwork: MediaImage[];
|
|
|
|
if (imageUrl) {
|
|
artwork = [{ sizes: '300x300', src: imageUrl, type: 'image/png' }];
|
|
} else {
|
|
artwork = [];
|
|
}
|
|
|
|
metadata = new MediaMetadata({
|
|
album: song.album ?? '',
|
|
artist: song.artistName,
|
|
artwork,
|
|
title: song.name,
|
|
});
|
|
} else {
|
|
metadata = new MediaMetadata();
|
|
}
|
|
|
|
mediaSession.metadata = metadata;
|
|
}
|
|
|
|
remote?.updateSong(song);
|
|
};
|