Added resume from history

This commit is contained in:
booploops 2022-02-19 01:13:22 -08:00
parent 913532fcdb
commit 02ba9a7c42
3 changed files with 354 additions and 304 deletions

View file

@ -12,7 +12,8 @@ export class Store {
"discord_rpc_clear_on_pause": true, "discord_rpc_clear_on_pause": true,
"language": "en_US", // electron.app.getLocale().replace('-', '_') this can be used in future "language": "en_US", // electron.app.getLocale().replace('-', '_') this can be used in future
"playbackNotifications": true, "playbackNotifications": true,
"update_branch": "innolab" "update_branch": "main",
"resumeOnStartupBehavior": "local"
}, },
"home": { "home": {
"followedArtists": [], "followedArtists": [],

View file

@ -20,7 +20,7 @@ const CiderFrontAPI = {
MenuEntry: function () { MenuEntry: function () {
this.id = "" this.id = ""
this.name = "" this.name = ""
this.onClick = ()=>{} this.onClick = () => { }
} }
}, },
AddMenuEntry(entry) { AddMenuEntry(entry) {
@ -103,7 +103,7 @@ const app = new Vue({
radio: { radio: {
personal: [] personal: []
}, },
mklang : 'en', mklang: 'en',
webview: { webview: {
url: "", url: "",
title: "", title: "",
@ -134,7 +134,7 @@ const app = new Vue({
sorting: "name", sorting: "name",
sortOrder: "asc", sortOrder: "asc",
listing: [], listing: [],
meta: {total: 0, progress: 0}, meta: { total: 0, progress: 0 },
search: "", search: "",
displayListing: [], displayListing: [],
downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library
@ -150,7 +150,7 @@ const app = new Vue({
sorting: ["dateAdded", "name"], // [0] = recentlyadded page, [1] = albums page sorting: ["dateAdded", "name"], // [0] = recentlyadded page, [1] = albums page
sortOrder: ["desc", "asc"], // [0] = recentlyadded page, [1] = albums page sortOrder: ["desc", "asc"], // [0] = recentlyadded page, [1] = albums page
listing: [], listing: [],
meta: {total: 0, progress: 0}, meta: { total: 0, progress: 0 },
search: "", search: "",
displayListing: [], displayListing: [],
downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library
@ -166,7 +166,7 @@ const app = new Vue({
sorting: ["dateAdded", "name"], // [0] = recentlyadded page, [1] = albums page sorting: ["dateAdded", "name"], // [0] = recentlyadded page, [1] = albums page
sortOrder: ["desc", "asc"], // [0] = recentlyadded page, [1] = albums page sortOrder: ["desc", "asc"], // [0] = recentlyadded page, [1] = albums page
listing: [], listing: [],
meta: {total: 0, progress: 0}, meta: { total: 0, progress: 0 },
search: "", search: "",
displayListing: [], displayListing: [],
downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library
@ -215,7 +215,7 @@ const app = new Vue({
"attributes": { "attributes": {
"name": "Cider User", "name": "Cider User",
"handle": "CiderUser", "handle": "CiderUser",
"artwork": {"url": "./assets/logocut.png"} "artwork": { "url": "./assets/logocut.png" }
} }
}, },
menuOpened: false, menuOpened: false,
@ -265,7 +265,7 @@ const app = new Vue({
headerItems: {} headerItems: {}
} }
}, },
pauseButtonTimer : null pauseButtonTimer: null
}, },
watch: { watch: {
cfg: { cfg: {
@ -292,7 +292,7 @@ const app = new Vue({
}, },
methods: { methods: {
songLinkShare(amUrl) { songLinkShare(amUrl) {
notyf.open({type: "info", message: app.getLz('term.song.link.generate')}) notyf.open({ type: "info", message: app.getLz('term.song.link.generate') })
let self = this let self = this
httpRequest = new XMLHttpRequest(); httpRequest = new XMLHttpRequest();
httpRequest.open('GET', `https://api.song.link/v1-alpha.1/links?url=${amUrl}&userCountry=US`, true); httpRequest.open('GET', `https://api.song.link/v1-alpha.1/links?url=${amUrl}&userCountry=US`, true);
@ -313,7 +313,7 @@ const app = new Vue({
mainMenuVisibility(val) { mainMenuVisibility(val) {
if (val) { if (val) {
(this.mk.isAuthorized) ? this.chrome.menuOpened = !this.chrome.menuOpened : false; (this.mk.isAuthorized) ? this.chrome.menuOpened = !this.chrome.menuOpened : false;
if (!this.mk.isAuthorized){ if (!this.mk.isAuthorized) {
this.mk.authorize() this.mk.authorize()
} }
} else { } else {
@ -340,16 +340,17 @@ const app = new Vue({
}, },
getLz(message, options = {}) { getLz(message, options = {}) {
if (this.lz[message]) { if (this.lz[message]) {
if(options["count"] ) { if (options["count"]) {
if (typeof this.lz[message] === "object"){ if (typeof this.lz[message] === "object") {
let type = window.fastPluralRules.getPluralFormNameForCardinalByLocale(this.cfg.general.language.replace("_","-"),options["count"]); let type = window.fastPluralRules.getPluralFormNameForCardinalByLocale(this.cfg.general.language.replace("_", "-"), options["count"]);
return this.lz[message][type] ?? ((this.lz[message])[Object.keys(this.lz[message])[0]] ?? this.lz[message]) return this.lz[message][type] ?? ((this.lz[message])[Object.keys(this.lz[message])[0]] ?? this.lz[message])
} else { } else {
// fallback English plural forms ( old i18n ) // fallback English plural forms ( old i18n )
if (options["count"] > 1) { if (options["count"] > 1) {
return this.lz[message+ "s"] ?? this.lz[message]} else { return this.lz[message] ?? this.lz[message+ "s"]} return this.lz[message + "s"] ?? this.lz[message]
} else { return this.lz[message] ?? this.lz[message + "s"] }
} }
} else if(typeof this.lz[message] === "object") { } else if (typeof this.lz[message] === "object") {
return (this.lz[message])[Object.keys(this.lz[message])[0]] return (this.lz[message])[Object.keys(this.lz[message])[0]]
} }
return this.lz[message] return this.lz[message]
@ -384,7 +385,7 @@ const app = new Vue({
}, },
async showSocialListeningTo() { async showSocialListeningTo() {
let contentIds = Object.keys(app.socialBadges.badgeMap) let contentIds = Object.keys(app.socialBadges.badgeMap)
app.showCollection({data: this.socialBadges.mediaItems}, "Friends Listening To", "albums") app.showCollection({ data: this.socialBadges.mediaItems }, "Friends Listening To", "albums")
if (this.socialBadges.mediaItemDLState == 1 || this.socialBadges.mediaItemDLState == 2) { if (this.socialBadges.mediaItemDLState == 1 || this.socialBadges.mediaItemDLState == 2) {
return return
} }
@ -495,7 +496,7 @@ const app = new Vue({
self.selectedMediaItems[i].kind = "albums" self.selectedMediaItems[i].kind = "albums"
let res = await self.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/albums/${self.selectedMediaItems[i].id}/tracks`); let res = await self.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/albums/${self.selectedMediaItems[i].id}/tracks`);
let ids = res.data.data.map(function (i) { let ids = res.data.data.map(function (i) {
return {id: i.id, type: i.type} return { id: i.id, type: i.type }
}) })
pl_items = pl_items.concat(ids) pl_items = pl_items.concat(ids)
} else if (self.selectedMediaItems[i].kind == "library-song" || self.selectedMediaItems[i].kind == "library-songs") { } else if (self.selectedMediaItems[i].kind == "library-song" || self.selectedMediaItems[i].kind == "library-songs") {
@ -508,7 +509,7 @@ const app = new Vue({
self.selectedMediaItems[i].kind = "library-albums" self.selectedMediaItems[i].kind = "library-albums"
let res = await self.mk.api.v3.music(`/v1/me/library/albums/${self.selectedMediaItems[i].id}/tracks`); let res = await self.mk.api.v3.music(`/v1/me/library/albums/${self.selectedMediaItems[i].id}/tracks`);
let ids = res.data.data.map(function (i) { let ids = res.data.data.map(function (i) {
return {id: i.id, type: i.type} return { id: i.id, type: i.type }
}) })
pl_items = pl_items.concat(ids) pl_items = pl_items.concat(ids)
} else { } else {
@ -535,7 +536,7 @@ const app = new Vue({
self.selectedMediaItems[i].kind = "albums" self.selectedMediaItems[i].kind = "albums"
let res = await self.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/albums/${self.selectedMediaItems[i].id}/tracks`); let res = await self.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/albums/${self.selectedMediaItems[i].id}/tracks`);
let ids = res.data.data.map(function (i) { let ids = res.data.data.map(function (i) {
return {id: i.id, type: i.type} return { id: i.id, type: i.type }
}) })
pl_items = pl_items.concat(ids) pl_items = pl_items.concat(ids)
} else if (self.selectedMediaItems[i].kind == "library-song" || self.selectedMediaItems[i].kind == "library-songs") { } else if (self.selectedMediaItems[i].kind == "library-song" || self.selectedMediaItems[i].kind == "library-songs") {
@ -548,7 +549,7 @@ const app = new Vue({
self.selectedMediaItems[i].kind = "library-albums" self.selectedMediaItems[i].kind = "library-albums"
let res = await self.mk.api.v3.music(`/v1/me/library/albums/${self.selectedMediaItems[i].id}/tracks`); let res = await self.mk.api.v3.music(`/v1/me/library/albums/${self.selectedMediaItems[i].id}/tracks`);
let ids = res.data.data.map(function (i) { let ids = res.data.data.map(function (i) {
return {id: i.id, type: i.type} return { id: i.id, type: i.type }
}) })
pl_items = pl_items.concat(ids) pl_items = pl_items.concat(ids)
} else { } else {
@ -622,7 +623,7 @@ const app = new Vue({
"attributes": { "attributes": {
"name": "Cider User", "name": "Cider User",
"handle": "CiderUser", "handle": "CiderUser",
"artwork": {"url": "./assets/logocut.png"} "artwork": { "url": "./assets/logocut.png" }
} }
} }
} }
@ -664,6 +665,9 @@ const app = new Vue({
app.cfg.audio.quality = "HIGH" app.cfg.audio.quality = "HIGH"
} }
switch (this.cfg.general.resumeOnStartupBehavior) {
default:
case "local":
// load last played track // load last played track
try { try {
let lastItem = window.localStorage.getItem("currentTrack") let lastItem = window.localStorage.getItem("currentTrack")
@ -675,7 +679,7 @@ const app = new Vue({
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind; let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
app.mk.setQueue({ app.mk.setQueue({
[truekind]: [lastItem.attributes.playParams.id], [truekind]: [lastItem.attributes.playParams.id],
parameters : {l : app.mklang} parameters: { l: app.mklang }
}) })
app.mk.mute() app.mk.mute()
setTimeout(() => { setTimeout(() => {
@ -694,7 +698,7 @@ const app = new Vue({
for (id of ids) { for (id of ids) {
if (!(i == 0 && ids[0] == lastItem.attributes.playParams.id)) { if (!(i == 0 && ids[0] == lastItem.attributes.playParams.id)) {
try { try {
app.mk.playLater({songs: [id]}) app.mk.playLater({ songs: [id] })
} catch (err) { } catch (err) {
} }
} }
@ -714,6 +718,32 @@ const app = new Vue({
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
break;
case "history":
let history = await app.mk.api.v3.music(`/v1/me/recent/played/tracks`, { l : app.mklang})
if (history.data.data.length > 0) {
let lastItem = history.data.data[0]
let kind = lastItem.attributes.playParams.kind;
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
app.mk.setQueue({
[truekind]: [lastItem.attributes.playParams.id],
parameters: { l: app.mklang }
})
app.mk.mute()
setTimeout(() => {
app.mk.play().then(() => {
app.mk.pause().then(() => {
app.mk.unmute()
})
})
}, 1500)
}
break;
case "disabled":
break;
}
MusicKit.getInstance().videoContainerElement = document.getElementById("apple-music-video-player") MusicKit.getInstance().videoContainerElement = document.getElementById("apple-music-video-player")
@ -721,12 +751,12 @@ const app = new Vue({
let replaygain = self.parseSCTagToRG(tag) let replaygain = self.parseSCTagToRG(tag)
try { try {
CiderAudio.audioNodes.gainNode.gain.value = (Math.min(Math.pow(10, (replaygain.gain / 20)), (1 / replaygain.peak))) CiderAudio.audioNodes.gainNode.gain.value = (Math.min(Math.pow(10, (replaygain.gain / 20)), (1 / replaygain.peak)))
} catch (e) {} } catch (e) { }
}) })
ipcRenderer.on('play', function(_event, mode, id) { ipcRenderer.on('play', function (_event, mode, id) {
if (mode !== 'url'){ if (mode !== 'url') {
self.mk.setQueue({[mode]: id , parameters : {l : self.mklang}}).then(() => { self.mk.setQueue({ [mode]: id, parameters: { l: self.mklang } }).then(() => {
app.mk.play() app.mk.play()
}) })
@ -959,7 +989,7 @@ const app = new Vue({
fetchOptions: { fetchOptions: {
method: "PATCH", method: "PATCH",
body: JSON.stringify({ body: JSON.stringify({
attributes: {name: name} attributes: { name: name }
}) })
} }
} }
@ -974,7 +1004,7 @@ const app = new Vue({
fetchOptions: { fetchOptions: {
method: "PATCH", method: "PATCH",
body: JSON.stringify({ body: JSON.stringify({
attributes: {name: name} attributes: { name: name }
}) })
} }
} }
@ -983,7 +1013,7 @@ const app = new Vue({
}) })
}, },
copyToClipboard(str) { copyToClipboard(str) {
if (navigator.userAgent.includes('Darwin') || navigator.appVersion.indexOf("Mac")!=-1) { if (navigator.userAgent.includes('Darwin') || navigator.appVersion.indexOf("Mac") != -1) {
this.darwinShare(str) this.darwinShare(str)
} else { } else {
notyf.success(app.getLz('term.share.success')) notyf.success(app.getLz('term.share.success'))
@ -1002,9 +1032,9 @@ const app = new Vue({
fetchOptions: { fetchOptions: {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
"attributes": {"name": name}, "attributes": { "name": name },
"relationships": { "relationships": {
"tracks": {"data": tracks}, "tracks": { "data": tracks },
} }
}) })
} }
@ -1054,7 +1084,7 @@ const app = new Vue({
app.appRoute("collection-list") app.appRoute("collection-list")
}, },
async showArtistView(artist, title, view) { async showArtistView(artist, title, view) {
let response = (await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/artists/${artist}/view/${view}?l=${this.mklang}`, {}, {includeResponseMeta: !0})).data let response = (await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/artists/${artist}/view/${view}?l=${this.mklang}`, {}, { includeResponseMeta: !0 })).data
console.log(response) console.log(response)
await this.showCollection(response, title, "artists") await this.showCollection(response, title, "artists")
}, },
@ -1090,7 +1120,7 @@ const app = new Vue({
resource: ["autos"] resource: ["autos"]
}, },
groups: group, groups: group,
l : this.mklang l: this.mklang
} }
let response = await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/search?term=${term}`, requestBody, { let response = await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/search?term=${term}`, requestBody, {
includeResponseMeta: !0 includeResponseMeta: !0
@ -1142,7 +1172,7 @@ const app = new Vue({
"include[library-songs]": "catalog,artists,albums,playParams,name,artwork,url", "include[library-songs]": "catalog,artists,albums,playParams,name,artwork,url",
"fields[catalog]": "artistUrl,albumUrl,url", "fields[catalog]": "artistUrl,albumUrl,url",
"fields[songs]": "artistUrl,albumUrl,playParams,name,artwork,url,artistName,albumName,durationInMillis", "fields[songs]": "artistUrl,albumUrl,playParams,name,artwork,url,artistName,albumName,durationInMillis",
l : this.mklang l: this.mklang
} }
if (!transient) { if (!transient) {
this.playlists.loadingState = 0; this.playlists.loadingState = 0;
@ -1171,8 +1201,8 @@ const app = new Vue({
"fields[albums]": "artistName,artistUrl,artwork,contentRating,editorialArtwork,editorialVideo,name,playParams,releaseDate,url,trackCount", "fields[albums]": "artistName,artistUrl,artwork,contentRating,editorialArtwork,editorialVideo,name,playParams,releaseDate,url,trackCount",
"limit[artists:top-songs]": 20, "limit[artists:top-songs]": 20,
"art[url]": "f", "art[url]": "f",
l : this.mklang l: this.mklang
}, {includeResponseMeta: !0}) }, { includeResponseMeta: !0 })
console.log(artistData.data.data[0]) console.log(artistData.data.data[0])
this.artistPage.data = artistData.data.data[0] this.artistPage.data = artistData.data.data[0]
this.page = "artist-page" this.page = "artist-page"
@ -1287,7 +1317,7 @@ const app = new Vue({
kind: page, kind: page,
id: id, id: id,
attributes: { attributes: {
playParams: {kind: page, id: id, isLibrary: isLibrary} playParams: { kind: page, id: id, isLibrary: isLibrary }
} }
}) })
}, },
@ -1334,10 +1364,10 @@ const app = new Vue({
extend: "offers,editorialVideo", extend: "offers,editorialVideo",
"views": "appears-on,more-by-artist,related-videos,other-versions,you-might-also-like,video-extras,audio-extras", "views": "appears-on,more-by-artist,related-videos,other-versions,you-might-also-like,video-extras,audio-extras",
} }
if (kind.includes("playlist")){ if (kind.includes("playlist")) {
params["include"] = "tracks"; params["include"] = "tracks";
} }
if (kind.includes("album")){ if (kind.includes("album")) {
params["include[albums]"] = "artists" params["include[albums]"] = "artists"
params["fields[artists]"] = "name,url" params["fields[artists]"] = "name,url"
params["fields[albums]"] = "artistName,artistUrl,artwork,contentRating,editorialArtwork,name,playParams,releaseDate,url" params["fields[albums]"] = "artistName,artistUrl,artwork,contentRating,editorialArtwork,name,playParams,releaseDate,url"
@ -1370,11 +1400,11 @@ const app = new Vue({
prevButton() { prevButton() {
if (!app.prevButtonBackIndicator && app.mk.nowPlayingItem && app.mk.currentPlaybackTime > 2) { if (!app.prevButtonBackIndicator && app.mk.nowPlayingItem && app.mk.currentPlaybackTime > 2) {
app.prevButtonBackIndicator = true; app.prevButtonBackIndicator = true;
try{clearTimeout(app.pauseButtonTimer)} catch (e){ } try { clearTimeout(app.pauseButtonTimer) } catch (e) { }
app.mk.seekToTime(0); app.mk.seekToTime(0);
app.pauseButtonTimer = setTimeout(() => {app.prevButtonBackIndicator = false},3000); app.pauseButtonTimer = setTimeout(() => { app.prevButtonBackIndicator = false }, 3000);
} else { } else {
try{clearTimeout(app.pauseButtonTimer)} catch (e){ } try { clearTimeout(app.pauseButtonTimer) } catch (e) { }
app.prevButtonBackIndicator = false; app.prevButtonBackIndicator = false;
app.skipToPreviousItem() app.skipToPreviousItem()
} }
@ -1488,7 +1518,7 @@ const app = new Vue({
} }
if (labelId != "") { if (labelId != "") {
app.showingPlaylist = [] app.showingPlaylist = []
await app.getTypeFromID("recordLabel", labelId, false, {views: 'top-releases,latest-releases,top-artists'}); await app.getTypeFromID("recordLabel", labelId, false, { views: 'top-releases,latest-releases,top-artists' });
app.page = "recordLabel_" + labelId; app.page = "recordLabel_" + labelId;
} }
@ -1512,7 +1542,7 @@ const app = new Vue({
console.log(kind, id, isLibrary) console.log(kind, id, isLibrary)
app.mk.stop().then(() => { app.mk.stop().then(() => {
if (kind.includes("artist")) { if (kind.includes("artist")) {
app.mk.setStationQueue({artist: 'a-' + id}).then(() => { app.mk.setStationQueue({ artist: 'a-' + id }).then(() => {
app.mk.play() app.mk.play()
}) })
} }
@ -1621,7 +1651,7 @@ const app = new Vue({
searchLibrarySongs() { searchLibrarySongs() {
let self = this let self = this
let prefs = this.cfg.libraryPrefs.songs let prefs = this.cfg.libraryPrefs.songs
let albumAdded = self.library?.albums?.listing?.map(function(i){return {[i.id]: i.attributes?.dateAdded}}) let albumAdded = self.library?.albums?.listing?.map(function (i) { return { [i.id]: i.attributes?.dateAdded } })
let startTime = new Date().getTime() let startTime = new Date().getTime()
function sortSongs() { function sortSongs() {
// sort this.library.songs.displayListing by song.attributes[self.library.songs.sorting] in descending or ascending order based on alphabetical order and numeric order // sort this.library.songs.displayListing by song.attributes[self.library.songs.sorting] in descending or ascending order based on alphabetical order and numeric order
@ -1633,11 +1663,11 @@ const app = new Vue({
aa = a.attributes.genreNames[0] aa = a.attributes.genreNames[0]
bb = b.attributes.genreNames[0] bb = b.attributes.genreNames[0]
} }
if (prefs.sort == "dateAdded"){ if (prefs.sort == "dateAdded") {
let albumida = a.relationships?.albums?.data[0]?.id ?? '1970-01-01T00:01:01Z' let albumida = a.relationships?.albums?.data[0]?.id ?? '1970-01-01T00:01:01Z'
let albumidb = b.relationships?.albums?.data[0]?.id ?? '1970-01-01T00:01:01Z' let albumidb = b.relationships?.albums?.data[0]?.id ?? '1970-01-01T00:01:01Z'
aa = startTime - new Date(((albumAdded.find(i => i[albumida]))?? [])[albumida] ?? '1970-01-01T00:01:01Z').getTime() aa = startTime - new Date(((albumAdded.find(i => i[albumida])) ?? [])[albumida] ?? '1970-01-01T00:01:01Z').getTime()
bb = startTime - new Date(((albumAdded.find(i => i[albumidb]))?? [])[albumidb] ?? '1970-01-01T00:01:01Z').getTime() bb = startTime - new Date(((albumAdded.find(i => i[albumidb])) ?? [])[albumidb] ?? '1970-01-01T00:01:01Z').getTime()
} }
if (aa == null) { if (aa == null) {
aa = "" aa = ""
@ -2184,26 +2214,26 @@ const app = new Vue({
getTotalTime() { getTotalTime() {
try { try {
if (app.showingPlaylist.relationships.tracks.data.length > 0) { if (app.showingPlaylist.relationships.tracks.data.length > 0) {
let time = Math.round([].concat(...app.showingPlaylist.relationships.tracks.data).reduce((a, {attributes: {durationInMillis}}) => a + durationInMillis, 0) / 1000); let time = Math.round([].concat(...app.showingPlaylist.relationships.tracks.data).reduce((a, { attributes: { durationInMillis } }) => a + durationInMillis, 0) / 1000);
let hours = Math.floor(time / 3600) let hours = Math.floor(time / 3600)
let mins = Math.floor(time / 60) % 60 let mins = Math.floor(time / 60) % 60
let secs = time % 60 let secs = time % 60
return app.showingPlaylist.relationships.tracks.data.length + " " + app.getLz('term.tracks', options = {count : app.showingPlaylist.relationships.tracks.data.length}) + ", " return app.showingPlaylist.relationships.tracks.data.length + " " + app.getLz('term.tracks', options = { count: app.showingPlaylist.relationships.tracks.data.length }) + ", "
+ ((hours > 0) ? (hours + (" " + (app.getLz('term.time.hour', options = {count : hours}) + ", "))) : "") + + ((hours > 0) ? (hours + (" " + (app.getLz('term.time.hour', options = { count: hours }) + ", "))) : "") +
((mins > 0) ? (mins + (" " + app.getLz('term.time.minute', options = {count : mins}) + ", ")) : "") + ((mins > 0) ? (mins + (" " + app.getLz('term.time.minute', options = { count: mins }) + ", ")) : "") +
secs + (" " + app.getLz('term.time.second', options = {count : secs}) + "."); secs + (" " + app.getLz('term.time.second', options = { count: secs }) + ".");
} else return "" } else return ""
} catch (err) { } catch (err) {
return "" return ""
} }
}, },
async getLibrarySongs() { async getLibrarySongs() {
let response = await this.mkapi("songs", true, "", {limit: 100, l : this.mklang}, {includeResponseMeta: !0}) let response = await this.mkapi("songs", true, "", { limit: 100, l: this.mklang }, { includeResponseMeta: !0 })
this.library.songs.listing = response.data.data this.library.songs.listing = response.data.data
this.library.songs.meta = response.data.meta this.library.songs.meta = response.data.meta
}, },
async getLibraryAlbums() { async getLibraryAlbums() {
let response = await this.mkapi("albums", true, "", {limit: 100, l : this.mklang}, {includeResponseMeta: !0}) let response = await this.mkapi("albums", true, "", { limit: 100, l: this.mklang }, { includeResponseMeta: !0 })
this.library.albums.listing = response.data.data this.library.albums.listing = response.data.data
this.library.albums.meta = response.data.meta this.library.albums.meta = response.data.meta
}, },
@ -2312,7 +2342,7 @@ const app = new Vue({
fetchOptions: { fetchOptions: {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
attributes: {name: name} attributes: { name: name }
}) })
} }
} }
@ -2673,15 +2703,15 @@ const app = new Vue({
line: "lrcInstrumental" line: "lrcInstrumental"
}); });
} }
preLrc.push({startTime: start, endTime: end, line: element.textContent}); preLrc.push({ startTime: start, endTime: end, line: element.textContent });
endTimes.push(end); endTimes.push(end);
} }
// first line dot // first line dot
if (preLrc.length > 0) if (preLrc.length > 0)
preLrc.unshift({startTime: 0, endTime: preLrc[0].startTime, line: "lrcInstrumental"}); preLrc.unshift({ startTime: 0, endTime: preLrc[0].startTime, line: "lrcInstrumental" });
} else { } else {
for (element of lyricsLines) { for (element of lyricsLines) {
preLrc.push({startTime: 9999999, endTime: 9999999, line: element.textContent}); preLrc.push({ startTime: 9999999, endTime: 9999999, line: element.textContent });
} }
} }
this.lyrics = preLrc; this.lyrics = preLrc;
@ -2749,17 +2779,17 @@ const app = new Vue({
console.log(id, truekind, isLibrary) console.log(id, truekind, isLibrary)
try { try {
if (truekind.includes("artist")) { if (truekind.includes("artist")) {
app.mk.setStationQueue({artist: 'a-' + id}).then(() => { app.mk.setStationQueue({ artist: 'a-' + id }).then(() => {
app.mk.play() app.mk.play()
}) })
} else if (truekind == "radioStations") { } else if (truekind == "radioStations") {
this.mk.setStationQueue({url: raurl}).then(function (queue) { this.mk.setStationQueue({ url: raurl }).then(function (queue) {
MusicKit.getInstance().play() MusicKit.getInstance().play()
}); });
} else { } else {
this.mk.setQueue({ this.mk.setQueue({
[truekind]: [id], [truekind]: [id],
parameters : {l : this.mklang} parameters: { l: this.mklang }
}).then(function (queue) { }).then(function (queue) {
MusicKit.getInstance().play() MusicKit.getInstance().play()
}) })
@ -2800,7 +2830,7 @@ const app = new Vue({
if (item) { if (item) {
app.mk.setQueue({ app.mk.setQueue({
[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id, [item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id,
parameters : {l : app.mklang} parameters: { l: app.mklang }
}).then(function () { }).then(function () {
app.mk.play().then(() => { app.mk.play().then(() => {
if (app.mk.shuffleMode == 1) { if (app.mk.shuffleMode == 1) {
@ -2884,7 +2914,8 @@ const app = new Vue({
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id)) app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id))
} }
} }
)} else { )
} else {
app.mk.setQueue({ [kind + "s"]: itemsToPlay[kind] }).then(function () { app.mk.setQueue({ [kind + "s"]: itemsToPlay[kind] }).then(function () {
ind += 1; ind += 1;
console.log(ind, Object.keys(itemsToPlay).length) console.log(ind, Object.keys(itemsToPlay).length)
@ -2892,7 +2923,8 @@ const app = new Vue({
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id)) app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.attributes.playParams.id ?? item.id))
} }
} }
)} )
}
} }
} }
@ -2904,7 +2936,7 @@ const app = new Vue({
if (truekind == "playlists" && (id.startsWith("p.") || id.startsWith("pl.u"))) { if (truekind == "playlists" && (id.startsWith("p.") || id.startsWith("pl.u"))) {
app.mk.setQueue({ app.mk.setQueue({
[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id, [item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id,
parameters : {l : app.mklang} parameters: { l: app.mklang }
}).then(function () { }).then(function () {
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.id) ?? 1).then(function () { app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.id) ?? 1).then(function () {
if ((app.showingPlaylist && app.showingPlaylist.id == id)) { if ((app.showingPlaylist && app.showingPlaylist.id == id)) {
@ -2944,7 +2976,7 @@ const app = new Vue({
} else { } else {
this.mk.setQueue({ this.mk.setQueue({
[truekind]: [id], [truekind]: [id],
parameters : {l : this.mklang} parameters: { l: this.mklang }
}).then(function (queue) { }).then(function (queue) {
if (item && ((queue._itemIDs[childIndex] != item.id))) { if (item && ((queue._itemIDs[childIndex] != item.id))) {
childIndex = queue._itemIDs.indexOf(item.id) childIndex = queue._itemIDs.indexOf(item.id)
@ -3056,7 +3088,7 @@ const app = new Vue({
with: ["serverBubbles", "lyricSnippet"], with: ["serverBubbles", "lyricSnippet"],
"art[url]": "f", "art[url]": "f",
"art[social-profiles:url]": "c" "art[social-profiles:url]": "c"
}, {includeResponseMeta: !0}).then(function (results) { }, { includeResponseMeta: !0 }).then(function (results) {
results.data.results["meta"] = results.data.meta results.data.results["meta"] = results.data.meta
self.search.resultsSocial = results.data.results self.search.resultsSocial = results.data.results
}) })
@ -3076,7 +3108,7 @@ const app = new Vue({
return type.type == this return type.type == this
}, type) }, type)
if (index == -1) { if (index == -1) {
types.push({type: type, id: [id]}) types.push({ type: type, id: [id] })
} else { } else {
types[index].id.push(id) types[index].id.push(id)
} }
@ -3260,8 +3292,8 @@ const app = new Vue({
}, },
quickPlay(query) { quickPlay(query) {
let self = this let self = this
MusicKit.getInstance().api.search(query, {limit: 2, types: 'songs'}).then(function (data) { MusicKit.getInstance().api.search(query, { limit: 2, types: 'songs' }).then(function (data) {
MusicKit.getInstance().setQueue({song: data["songs"]['data'][0]["id"], parameters : {l : app.mklang}}).then(function (queue) { MusicKit.getInstance().setQueue({ song: data["songs"]['data'][0]["id"], parameters: { l: app.mklang } }).then(function (queue) {
MusicKit.getInstance().play() MusicKit.getInstance().play()
setTimeout(() => { setTimeout(() => {
self.$forceUpdate() self.$forceUpdate()
@ -3438,7 +3470,7 @@ const app = new Vue({
let data_type = this.mk.nowPlayingItem.playParams.kind let data_type = this.mk.nowPlayingItem.playParams.kind
let item_id = this.mk.nowPlayingItem.attributes.playParams.id ?? this.mk.nowPlayingItem.id let item_id = this.mk.nowPlayingItem.attributes.playParams.id ?? this.mk.nowPlayingItem.id
let isLibrary = this.mk.nowPlayingItem.attributes.playParams.isLibrary ?? false let isLibrary = this.mk.nowPlayingItem.attributes.playParams.isLibrary ?? false
let params = {"fields[songs]": "inLibrary", "fields[albums]": "inLibrary", "relate": "library", "t": "1"} let params = { "fields[songs]": "inLibrary", "fields[albums]": "inLibrary", "relate": "library", "t": "1" }
app.selectedMediaItems = [] app.selectedMediaItems = []
app.select_selectMediaItem(item_id, data_type, 0, '12344', isLibrary) app.select_selectMediaItem(item_id, data_type, 0, '12344', isLibrary)
let useMenu = "normal" let useMenu = "normal"
@ -3508,7 +3540,7 @@ const app = new Vue({
"icon": "./assets/feather/radio.svg", "icon": "./assets/feather/radio.svg",
"name": app.getLz('action.startRadio'), "name": app.getLz('action.startRadio'),
"action": function () { "action": function () {
app.mk.setStationQueue({song: app.mk.nowPlayingItem.id}).then(() => { app.mk.setStationQueue({ song: app.mk.nowPlayingItem.id }).then(() => {
app.mk.play() app.mk.play()
app.selectedMediaItems = [] app.selectedMediaItems = []
}) })
@ -3713,7 +3745,7 @@ const app = new Vue({
}, },
SpacePause() { SpacePause() {
const elems = document.querySelectorAll('input'); const elems = document.querySelectorAll('input');
for (elem of elems){ for (elem of elems) {
if (elem === document.activeElement) { if (elem === document.activeElement) {
return; return;
} }
@ -3721,7 +3753,7 @@ const app = new Vue({
if (!this.isDev) // disable in dev mode to keep my sanity if (!this.isDev) // disable in dev mode to keep my sanity
MusicKitInterop.playPause(); MusicKitInterop.playPause();
}, },
async MKJSLang(){ async MKJSLang() {
let u = this.cfg.general.language; let u = this.cfg.general.language;
// use MusicKit.getInstance or crash // use MusicKit.getInstance or crash
try { try {
@ -3757,20 +3789,20 @@ const app = new Vue({
return await sellang return await sellang
} }
}, },
skipToNextItem(){ skipToNextItem() {
app.prevButtonBackIndicator = false; app.prevButtonBackIndicator = false;
// app.mk.skipToNextItem() is buggy somehow so use this // app.mk.skipToNextItem() is buggy somehow so use this
if (this.mk.queue.nextPlayableItemIndex != -1 && this.mk.queue.nextPlayableItemIndex != null) if (this.mk.queue.nextPlayableItemIndex != -1 && this.mk.queue.nextPlayableItemIndex != null)
this.mk.changeToMediaAtIndex(this.mk.queue.nextPlayableItemIndex); this.mk.changeToMediaAtIndex(this.mk.queue.nextPlayableItemIndex);
}, },
skipToPreviousItem(){ skipToPreviousItem() {
// app.mk.skipToPreviousItem() is buggy somehow so use this // app.mk.skipToPreviousItem() is buggy somehow so use this
if (this.mk.queue.previousPlayableItemIndex != -1 && this.mk.queue.previousPlayableItemIndex != null) if (this.mk.queue.previousPlayableItemIndex != -1 && this.mk.queue.previousPlayableItemIndex != null)
this.mk.changeToMediaAtIndex(this.mk.queue.previousPlayableItemIndex); this.mk.changeToMediaAtIndex(this.mk.queue.previousPlayableItemIndex);
}, },
mediaKeyFixes(){ mediaKeyFixes() {
navigator.mediaSession.setActionHandler('previoustrack', function() { app.prevButton() }); navigator.mediaSession.setActionHandler('previoustrack', function () { app.prevButton() });
navigator.mediaSession.setActionHandler('nexttrack', function() { app.skipToNextItem() }); navigator.mediaSession.setActionHandler('nexttrack', function () { app.skipToNextItem() });
} }
} }
}) })
@ -3778,7 +3810,7 @@ const app = new Vue({
Vue.component('animated-number', { Vue.component('animated-number', {
template: "<div style='display: inline-block;'>{{ displayNumber }}</div>", template: "<div style='display: inline-block;'>{{ displayNumber }}</div>",
props: {'number': {default: 0}}, props: { 'number': { default: 0 } },
data() { data() {
return { return {
@ -4044,7 +4076,7 @@ webGPU().then()
let screenWidth = screen.width; let screenWidth = screen.width;
let screenHeight = screen.height; let screenHeight = screen.height;
window.onerror = function(error) { window.onerror = function (error) {
console.log(error) console.log(error)
bootbox.alert("Error occured: " + error) bootbox.alert("Error occured: " + error)
}; };

View file

@ -23,6 +23,23 @@
<input type="checkbox" v-model="app.mk.privateEnabled" switch/> <input type="checkbox" v-model="app.mk.privateEnabled" switch/>
</div> </div>
</div> </div>
<div class="md-option-line">
<div class="md-option-segment">
Resume behavior<br>
<small>
Resume behavior affects how Cider will resume your session when you return to the app.<br>
<b>Locally: </b> Cider will resume your last session on this machine.<br>
<b>History: </b> Cider will queue the last song from your overall Apple Music history, across devices.
</small>
</div>
<div class="md-option-segment md-option-segment_auto">
<select class="md-select" style="width:180px;" v-model="$root.cfg.general.resumeOnStartupBehavior">
<option value="disabled">Disabled</option>
<option value="local">Locally</option>
<option value="history">History</option>
</select>
</div>
</div>
</div> </div>
<div class="md-option-header"> <div class="md-option-header">
<span>{{$root.getLz('settings.header.audio')}}</span> <span>{{$root.getLz('settings.header.audio')}}</span>