mpris fix
This commit is contained in:
parent
6da8c3c2b6
commit
44ed769ed6
6 changed files with 127 additions and 133 deletions
|
@ -10,7 +10,7 @@ const MusicKitInterop = {
|
|||
const attributes = MusicKitInterop.getAttributes()
|
||||
if (MusicKitInterop.filterTrack(attributes, true, false)) {
|
||||
global.ipcRenderer.send('playbackStateDidChange', attributes)
|
||||
ipcRenderer.send('wsapi-updatePlaybackState', attributes);
|
||||
global.ipcRenderer.send('wsapi-updatePlaybackState', attributes);
|
||||
// if (typeof _plugins != "undefined") {
|
||||
// _plugins.execute("OnPlaybackStateChanged", {Attributes: MusicKitInterop.getAttributes()})
|
||||
// }
|
||||
|
@ -24,6 +24,7 @@ const MusicKitInterop = {
|
|||
/** wsapi */
|
||||
|
||||
MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => {
|
||||
console.log('nowPlayingItemDidChange')
|
||||
const attributes = MusicKitInterop.getAttributes()
|
||||
const trackFilter = MusicKitInterop.filterTrack(attributes, false, true)
|
||||
|
||||
|
@ -47,7 +48,7 @@ const MusicKitInterop = {
|
|||
})
|
||||
},
|
||||
async modifyNamesOnLocale() {
|
||||
if (app.mklang == '' || app.mklang == null) {
|
||||
if (app.mklang === '' || app.mklang == null) {
|
||||
return;
|
||||
}
|
||||
const mk = MusicKit.getInstance()
|
||||
|
@ -56,17 +57,17 @@ const MusicKitInterop = {
|
|||
return;
|
||||
}
|
||||
const id = nowPlayingItem?._songId ?? (nowPlayingItem?.songId ?? nowPlayingItem?.id)
|
||||
if (id != null && id != -1) {
|
||||
if (id != null && id !== -1) {
|
||||
try{
|
||||
const query = await mk.api.v3.music(`/v1${(((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != null) && ((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != -1)) ? `/catalog/${mk.storefrontId}/` : `/me/library/`}songs/${id}?l=${app.mklang}`);
|
||||
const query = await mk.api.v3.music(`/v1${(((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != null) && ((nowPlayingItem?._songId ?? nowPlayingItem?.songId) !== -1)) ? `/catalog/${mk.storefrontId}/` : `/me/library/`}songs/${id}?l=${app.mklang}`);
|
||||
if (query?.data?.data[0]){
|
||||
let attrs = query?.data?.data[0]?.attributes;
|
||||
if (attrs?.name) { nowPlayingItem.attributes.name = attrs?.name ?? ''}
|
||||
if (attrs?.albumName) { nowPlayingItem.attributes.albumName = attrs?.albumName ?? ''}
|
||||
if (attrs?.artistName) { nowPlayingItem.attributes.artistName = attrs?.artistName ?? ''}
|
||||
|
||||
}} catch (e) { return;}
|
||||
} else {return;}
|
||||
}} catch (e) { }
|
||||
} else {}
|
||||
},
|
||||
getAttributes: function () {
|
||||
const mk = MusicKit.getInstance()
|
||||
|
@ -75,7 +76,7 @@ const MusicKitInterop = {
|
|||
const remainingTimeExport = mk.currentPlaybackTimeRemaining;
|
||||
const attributes = (nowPlayingItem != null ? nowPlayingItem.attributes : {});
|
||||
|
||||
attributes.status = isPlayingExport ?? false;
|
||||
attributes.status = isPlayingExport ?? null;
|
||||
attributes.name = attributes?.name ?? 'no-title-found';
|
||||
attributes.artwork = attributes?.artwork ?? {url: ''};
|
||||
attributes.artwork.url = (attributes?.artwork?.url ?? '').replace(`{f}`, "png");
|
||||
|
@ -120,7 +121,7 @@ const MusicKitInterop = {
|
|||
},
|
||||
|
||||
play: () => {
|
||||
MusicKit.getInstance().play().then(r => console.log(`[MusicKitInterop.play] ${r}`));
|
||||
MusicKit.getInstance().play().catch(console.error);
|
||||
},
|
||||
|
||||
pause: () => {
|
||||
|
@ -131,7 +132,7 @@ const MusicKitInterop = {
|
|||
if (MusicKit.getInstance().isPlaying) {
|
||||
MusicKit.getInstance().pause();
|
||||
} else if (MusicKit.getInstance().nowPlayingItem != null) {
|
||||
MusicKit.getInstance().play().then(r => console.log(`[MusicKitInterop.playPause] Playing ${r}`));
|
||||
MusicKit.getInstance().play().catch(console.error);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue