adds playlist caching
This commit is contained in:
parent
0f8b739705
commit
a8375c5c59
3 changed files with 125 additions and 91 deletions
|
@ -726,79 +726,22 @@ export class BrowserWindow {
|
||||||
event.returnValue = this.devMode;
|
event.returnValue = this.devMode;
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("put-library-songs", (_event, arg) => {
|
ipcMain.handle("put-cache", (_event, arg) => {
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
join(utils.getPath('ciderCache'), "library-songs.json"),
|
join(utils.getPath('ciderCache'), `${arg.file}.json`),
|
||||||
JSON.stringify(arg)
|
arg.data
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("put-library-artists", (_event, arg) => {
|
ipcMain.on("get-cache", (event, arg) => {
|
||||||
writeFileSync(
|
let read = ""
|
||||||
join(utils.getPath('ciderCache'), "library-artists.json"),
|
if (existsSync(join(utils.getPath('ciderCache'), `${arg}.json`))) {
|
||||||
JSON.stringify(arg)
|
read = readFileSync(
|
||||||
);
|
join(utils.getPath('ciderCache'), `${arg}.json`),
|
||||||
});
|
"utf8"
|
||||||
|
);
|
||||||
ipcMain.on("put-library-albums", (_event, arg) => {
|
}
|
||||||
writeFileSync(
|
event.returnValue = read;
|
||||||
join(utils.getPath('ciderCache'), "library-albums.json"),
|
|
||||||
JSON.stringify(arg)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on("put-library-playlists", (_event, arg) => {
|
|
||||||
writeFileSync(
|
|
||||||
join(utils.getPath('ciderCache'), "library-playlists.json"),
|
|
||||||
JSON.stringify(arg)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on("put-library-recentlyAdded", (_event, arg) => {
|
|
||||||
writeFileSync(
|
|
||||||
join(utils.getPath('ciderCache'), "library-recentlyAdded.json"),
|
|
||||||
JSON.stringify(arg)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on("get-library-songs", (event) => {
|
|
||||||
let librarySongs = readFileSync(
|
|
||||||
join(utils.getPath('ciderCache'), "library-songs.json"),
|
|
||||||
"utf8"
|
|
||||||
);
|
|
||||||
event.returnValue = JSON.parse(librarySongs);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on("get-library-artists", (event) => {
|
|
||||||
let libraryArtists = readFileSync(
|
|
||||||
join(utils.getPath('ciderCache'), "library-artists.json"),
|
|
||||||
"utf8"
|
|
||||||
);
|
|
||||||
event.returnValue = JSON.parse(libraryArtists);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on("get-library-albums", (event) => {
|
|
||||||
let libraryAlbums = readFileSync(
|
|
||||||
join(utils.getPath('ciderCache'), "library-albums.json"),
|
|
||||||
"utf8"
|
|
||||||
);
|
|
||||||
event.returnValue = JSON.parse(libraryAlbums);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on("get-library-playlists", (event) => {
|
|
||||||
let libraryPlaylists = readFileSync(
|
|
||||||
join(utils.getPath('ciderCache'), "library-playlists.json"),
|
|
||||||
"utf8"
|
|
||||||
);
|
|
||||||
event.returnValue = JSON.parse(libraryPlaylists);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on("get-library-recentlyAdded", (event) => {
|
|
||||||
let libraryRecentlyAdded = readFileSync(
|
|
||||||
join(utils.getPath('ciderCache'), "library-recentlyAdded.json"),
|
|
||||||
"utf8"
|
|
||||||
);
|
|
||||||
event.returnValue = JSON.parse(libraryRecentlyAdded);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle("getYTLyrics", async (_event, track, artist) => {
|
ipcMain.handle("getYTLyrics", async (_event, track, artist) => {
|
||||||
|
|
|
@ -1,5 +1,25 @@
|
||||||
Vue.use(VueHorizontal);
|
Vue.use(VueHorizontal);
|
||||||
Vue.use(VueObserveVisibility);
|
Vue.use(VueObserveVisibility);
|
||||||
|
|
||||||
|
const CiderCache = {
|
||||||
|
async getCache(file) {
|
||||||
|
let cache = await ipcRenderer.sendSync("get-cache", file)
|
||||||
|
if (isJson(cache)) {
|
||||||
|
cache = JSON.parse(cache)
|
||||||
|
}else{
|
||||||
|
cache = false
|
||||||
|
}
|
||||||
|
return cache
|
||||||
|
},
|
||||||
|
async putCache(file, data) {
|
||||||
|
ipcRenderer.invoke("put-cache", {
|
||||||
|
file: file,
|
||||||
|
data: JSON.stringify(data)
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var notyf = new Notyf();
|
var notyf = new Notyf();
|
||||||
|
|
||||||
const MusicKitObjects = {
|
const MusicKitObjects = {
|
||||||
|
@ -49,10 +69,10 @@ Array.prototype.limit = function (n) {
|
||||||
const store = new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
library: {
|
library: {
|
||||||
songs: ipcRenderer.sendSync("get-library-songs"),
|
// songs: ipcRenderer.sendSync("get-library-songs"),
|
||||||
albums: ipcRenderer.sendSync("get-library-albums"),
|
// albums: ipcRenderer.sendSync("get-library-albums"),
|
||||||
recentlyAdded: ipcRenderer.sendSync("get-library-recentlyAdded"),
|
// recentlyAdded: ipcRenderer.sendSync("get-library-recentlyAdded"),
|
||||||
playlists: ipcRenderer.sendSync("get-library-playlists")
|
// playlists: ipcRenderer.sendSync("get-library-playlists")
|
||||||
},
|
},
|
||||||
artwork: {
|
artwork: {
|
||||||
playerLCD: ""
|
playerLCD: ""
|
||||||
|
@ -308,12 +328,14 @@ const app = new Vue({
|
||||||
let cursorPos = [0, 0];
|
let cursorPos = [0, 0];
|
||||||
let intTabIndex = 0
|
let intTabIndex = 0
|
||||||
let self = this
|
let self = this
|
||||||
let cursorSpeed = 4
|
const cursorSpeedPvt = 4
|
||||||
let scrollSpeed = 8
|
let scrollSpeed = 8
|
||||||
let buttonPressDelay = 500
|
let buttonPressDelay = 500
|
||||||
let stickDeadZone = 0.2
|
let stickDeadZone = 0.2
|
||||||
let scrollGroup = null
|
let scrollGroup = null
|
||||||
|
|
||||||
|
let cursorSpeed = cursorSpeedPvt
|
||||||
|
|
||||||
let lastButtonPress = {
|
let lastButtonPress = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -354,9 +376,9 @@ const app = new Vue({
|
||||||
} else if (gp.axes[3] < -stickDeadZone) {
|
} else if (gp.axes[3] < -stickDeadZone) {
|
||||||
$("#app-content").scrollTop($("#app-content").scrollTop() + (gp.axes[3] * scrollSpeed))
|
$("#app-content").scrollTop($("#app-content").scrollTop() + (gp.axes[3] * scrollSpeed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(scrollGroup) {
|
|
||||||
|
if (scrollGroup) {
|
||||||
if (gp.axes[2] > stickDeadZone) {
|
if (gp.axes[2] > stickDeadZone) {
|
||||||
console.log('axis 2 up')
|
console.log('axis 2 up')
|
||||||
$(scrollGroup).scrollLeft($(scrollGroup).scrollLeft() + (gp.axes[2] * scrollSpeed))
|
$(scrollGroup).scrollLeft($(scrollGroup).scrollLeft() + (gp.axes[2] * scrollSpeed))
|
||||||
|
@ -369,7 +391,8 @@ const app = new Vue({
|
||||||
|
|
||||||
$(".cursor").css({
|
$(".cursor").css({
|
||||||
top: cursorPos[1] + "px",
|
top: cursorPos[1] + "px",
|
||||||
left: cursorPos[0] + "px"
|
left: cursorPos[0] + "px",
|
||||||
|
display: "block"
|
||||||
})
|
})
|
||||||
|
|
||||||
// A BUTTON
|
// A BUTTON
|
||||||
|
@ -400,8 +423,8 @@ const app = new Vue({
|
||||||
lastButtonPress["B"] = Date.now()
|
lastButtonPress["B"] = Date.now()
|
||||||
if (elementType == 0) {
|
if (elementType == 0) {
|
||||||
document.activeElement.dispatchEvent(new Event("contextmenu"))
|
document.activeElement.dispatchEvent(new Event("contextmenu"))
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
if($(".menu-option").length > 0) {
|
if ($(".menu-option").length > 0) {
|
||||||
let bounds = $(".menu-option")[0].getBoundingClientRect()
|
let bounds = $(".menu-option")[0].getBoundingClientRect()
|
||||||
cursorPos[0] = bounds.left + (bounds.width / 2)
|
cursorPos[0] = bounds.left + (bounds.width / 2)
|
||||||
cursorPos[1] = bounds.top + (bounds.height / 2)
|
cursorPos[1] = bounds.top + (bounds.height / 2)
|
||||||
|
@ -411,7 +434,7 @@ const app = new Vue({
|
||||||
element.dispatchEvent(new Event("contextmenu"))
|
element.dispatchEvent(new Event("contextmenu"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// right bumper
|
// right bumper
|
||||||
|
@ -447,9 +470,9 @@ const app = new Vue({
|
||||||
if (element) {
|
if (element) {
|
||||||
let closest = element.closest("[tabindex], input, button, a")
|
let closest = element.closest("[tabindex], input, button, a")
|
||||||
let scrollGroupClo = element.closest(".v-hl-container")
|
let scrollGroupClo = element.closest(".v-hl-container")
|
||||||
|
|
||||||
if(scrollGroupClo) {
|
if (scrollGroupClo) {
|
||||||
if(scrollGroupClo.classList.contains("v-hl-container")) {
|
if (scrollGroupClo.classList.contains("v-hl-container")) {
|
||||||
scrollGroup = scrollGroupClo
|
scrollGroup = scrollGroupClo
|
||||||
scrollGroup.style["scroll-snap-type"] = "unset"
|
scrollGroup.style["scroll-snap-type"] = "unset"
|
||||||
} else {
|
} else {
|
||||||
|
@ -459,16 +482,23 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closest) {
|
if (closest) {
|
||||||
|
|
||||||
elementType = 0
|
elementType = 0
|
||||||
closest.focus()
|
closest.focus()
|
||||||
} else {
|
} else {
|
||||||
if(closest) {
|
if (closest) {
|
||||||
closest.blur()
|
closest.blur()
|
||||||
}
|
}
|
||||||
elementType = 1
|
elementType = 1
|
||||||
element.focus()
|
element.focus()
|
||||||
}
|
}
|
||||||
|
cursorSpeed = cursorSpeedPvt
|
||||||
|
if (!element.classList.contains("app-chrome")
|
||||||
|
&& !element.classList.contains("app-content")) {
|
||||||
|
cursorSpeed = cursorSpeedPvt
|
||||||
|
}
|
||||||
|
// console.log($._data($(element), "events"))
|
||||||
|
} else {
|
||||||
|
cursorSpeed = 12
|
||||||
}
|
}
|
||||||
// console.log(gp.axes[0], gp.axes[1])
|
// console.log(gp.axes[0], gp.axes[1])
|
||||||
start = requestAnimationFrame(appLoop);
|
start = requestAnimationFrame(appLoop);
|
||||||
|
@ -1330,13 +1360,55 @@ const app = new Vue({
|
||||||
},
|
},
|
||||||
async refreshPlaylists() {
|
async refreshPlaylists() {
|
||||||
let self = this
|
let self = this
|
||||||
this.apiCall('https://api.music.apple.com/v1/me/library/playlist-folders/p.playlistsroot/children/', res => {
|
let newListing = []
|
||||||
self.playlists.listing = res.data
|
const cachedPlaylist = await CiderCache.getCache("library-playlists")
|
||||||
self.playlists.listing.forEach(playlist => {
|
|
||||||
playlist.parent = "p.playlistsroot"
|
if(cachedPlaylist) {
|
||||||
})
|
console.log("using cached playlists")
|
||||||
|
this.playlists.listing = cachedPlaylist
|
||||||
self.sortPlaylists()
|
self.sortPlaylists()
|
||||||
})
|
}else{
|
||||||
|
console.log("playlist has no cache")
|
||||||
|
}
|
||||||
|
|
||||||
|
const playlistroot = await app.mk.api.v3.music("/v1/me/library/playlist-folders/p.playlistsroot/children/")
|
||||||
|
|
||||||
|
newListing = []
|
||||||
|
|
||||||
|
this.library.backgroundNotification.message = "Building playlist cache..."
|
||||||
|
this.library.backgroundNotification.show = true
|
||||||
|
|
||||||
|
async function deepScan(parent = "p.playlistsroot") {
|
||||||
|
console.log(`scanning ${parent}`)
|
||||||
|
const playlistData = await app.mk.api.v3.music(`/v1/me/library/playlist-folders/${parent}/children/`)
|
||||||
|
await asyncForEach(playlistData.data.data, async (playlist) => {
|
||||||
|
playlist.parent = parent
|
||||||
|
playlist.children = []
|
||||||
|
playlist.tracks = []
|
||||||
|
try {
|
||||||
|
let tracks = await app.mk.api.v3.music(playlist.href + "/tracks").catch(e => {
|
||||||
|
// no tracks
|
||||||
|
})
|
||||||
|
playlist.tracks = tracks.data
|
||||||
|
} catch (e) { }
|
||||||
|
|
||||||
|
if (playlist.type == "library-playlist-folders") {
|
||||||
|
try {
|
||||||
|
await deepScan(playlist.id).catch(e => {})
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newListing.push(playlist)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
await deepScan()
|
||||||
|
|
||||||
|
this.library.backgroundNotification.show = false
|
||||||
|
this.playlists.listing = newListing
|
||||||
|
self.sortPlaylists()
|
||||||
|
CiderCache.putCache("library-playlists", newListing)
|
||||||
},
|
},
|
||||||
sortPlaylists() {
|
sortPlaylists() {
|
||||||
this.playlists.listing.sort((a, b) => {
|
this.playlists.listing.sort((a, b) => {
|
||||||
|
@ -4594,6 +4666,24 @@ async function webGPU() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isJson(item) {
|
||||||
|
item = typeof item !== "string"
|
||||||
|
? JSON.stringify(item)
|
||||||
|
: item;
|
||||||
|
|
||||||
|
try {
|
||||||
|
item = JSON.parse(item);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof item === "object" && item !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
webGPU().then()
|
webGPU().then()
|
||||||
|
|
||||||
let screenWidth = screen.width;
|
let screenWidth = screen.width;
|
||||||
|
|
|
@ -3163,6 +3163,7 @@ body[platform='darwin'] {
|
||||||
box-shadow: 0px 0px 0px 2px rgb(200 200 200 / 100%);
|
box-shadow: 0px 0px 0px 2px rgb(200 200 200 / 100%);
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@import url("less/macos.less");
|
@import url("less/macos.less");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue