library now uses CiderCache
This commit is contained in:
parent
760fce64c9
commit
66a659ad77
1 changed files with 27 additions and 16 deletions
|
@ -6,6 +6,9 @@ const CiderCache = {
|
||||||
let cache = await ipcRenderer.sendSync("get-cache", file)
|
let cache = await ipcRenderer.sendSync("get-cache", file)
|
||||||
if (isJson(cache)) {
|
if (isJson(cache)) {
|
||||||
cache = JSON.parse(cache)
|
cache = JSON.parse(cache)
|
||||||
|
if(Object.keys(cache).length === 0) {
|
||||||
|
cache = false
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
cache = false
|
cache = false
|
||||||
}
|
}
|
||||||
|
@ -983,12 +986,14 @@ const app = new Vue({
|
||||||
// })
|
// })
|
||||||
|
|
||||||
// load cached library
|
// load cached library
|
||||||
if (localStorage.getItem("librarySongs") != null) {
|
let librarySongs = await CiderCache.getCache("library-songs")
|
||||||
this.library.songs.listing = JSON.parse(localStorage.getItem("librarySongs"))
|
let libraryAlbums = await CiderCache.getCache("library-albums")
|
||||||
|
if (librarySongs) {
|
||||||
|
this.library.songs.listing = librarySongs
|
||||||
this.library.songs.displayListing = this.library.songs.listing
|
this.library.songs.displayListing = this.library.songs.listing
|
||||||
}
|
}
|
||||||
if (localStorage.getItem("libraryAlbums") != null) {
|
if (libraryAlbums) {
|
||||||
this.library.albums.listing = JSON.parse(localStorage.getItem("libraryAlbums"))
|
this.library.albums.listing = libraryAlbums
|
||||||
this.library.albums.displayListing = this.library.albums.listing
|
this.library.albums.displayListing = this.library.albums.listing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2418,6 +2423,7 @@ const app = new Vue({
|
||||||
async getLibrarySongsFull(force = false) {
|
async getLibrarySongsFull(force = false) {
|
||||||
let self = this
|
let self = this
|
||||||
let library = []
|
let library = []
|
||||||
|
let cacheId = "library-songs"
|
||||||
let downloaded = null;
|
let downloaded = null;
|
||||||
if ((this.library.songs.downloadState == 2) && !force) {
|
if ((this.library.songs.downloadState == 2) && !force) {
|
||||||
return
|
return
|
||||||
|
@ -2425,8 +2431,9 @@ const app = new Vue({
|
||||||
if (this.library.songs.downloadState == 1) {
|
if (this.library.songs.downloadState == 1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (localStorage.getItem("librarySongs") != null) {
|
let librarySongs = await CiderCache.getCache(cacheId)
|
||||||
this.library.songs.listing = JSON.parse(localStorage.getItem("librarySongs"))
|
if (librarySongs) {
|
||||||
|
this.library.songs.listing = librarySongs
|
||||||
this.searchLibrarySongs()
|
this.searchLibrarySongs()
|
||||||
}
|
}
|
||||||
if (this.songstest) {
|
if (this.songstest) {
|
||||||
|
@ -2503,7 +2510,7 @@ const app = new Vue({
|
||||||
self.library.songs.downloadState = 2
|
self.library.songs.downloadState = 2
|
||||||
self.library.backgroundNotification.show = false
|
self.library.backgroundNotification.show = false
|
||||||
self.searchLibrarySongs()
|
self.searchLibrarySongs()
|
||||||
localStorage.setItem("librarySongs", JSON.stringify(library))
|
CiderCache.putCache(cacheId, library)
|
||||||
}
|
}
|
||||||
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
||||||
console.log(`downloading next chunk - ${library.length} songs so far`)
|
console.log(`downloading next chunk - ${library.length} songs so far`)
|
||||||
|
@ -2513,7 +2520,7 @@ const app = new Vue({
|
||||||
self.library.songs.downloadState = 2
|
self.library.songs.downloadState = 2
|
||||||
self.library.backgroundNotification.show = false
|
self.library.backgroundNotification.show = false
|
||||||
self.searchLibrarySongs()
|
self.searchLibrarySongs()
|
||||||
localStorage.setItem("librarySongs", JSON.stringify(library))
|
CiderCache.putCache(cacheId, library)
|
||||||
// console.log(library)
|
// console.log(library)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2524,12 +2531,14 @@ const app = new Vue({
|
||||||
async getLibraryAlbumsFull(force = false, index) {
|
async getLibraryAlbumsFull(force = false, index) {
|
||||||
let self = this
|
let self = this
|
||||||
let library = []
|
let library = []
|
||||||
|
let cacheId = "library-albums"
|
||||||
let downloaded = null;
|
let downloaded = null;
|
||||||
if ((this.library.albums.downloadState == 2 || this.library.albums.downloadState == 1) && !force) {
|
if ((this.library.albums.downloadState == 2 || this.library.albums.downloadState == 1) && !force) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (localStorage.getItem("libraryAlbums") != null) {
|
let libraryAlbums = await CiderCache.getCache(cacheId)
|
||||||
this.library.albums.listing = JSON.parse(localStorage.getItem("libraryAlbums"))
|
if (libraryAlbums) {
|
||||||
|
this.library.albums.listing = libraryAlbums
|
||||||
this.searchLibraryAlbums(index)
|
this.searchLibraryAlbums(index)
|
||||||
}
|
}
|
||||||
if (this.songstest) {
|
if (this.songstest) {
|
||||||
|
@ -2610,7 +2619,7 @@ const app = new Vue({
|
||||||
self.library.albums.listing = library
|
self.library.albums.listing = library
|
||||||
self.library.albums.downloadState = 2
|
self.library.albums.downloadState = 2
|
||||||
self.library.backgroundNotification.show = false
|
self.library.backgroundNotification.show = false
|
||||||
localStorage.setItem("libraryAlbums", JSON.stringify(library))
|
CiderCache.putCache(cacheId, library)
|
||||||
self.searchLibraryAlbums(index)
|
self.searchLibraryAlbums(index)
|
||||||
}
|
}
|
||||||
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
||||||
|
@ -2621,7 +2630,7 @@ const app = new Vue({
|
||||||
self.library.albums.listing = library
|
self.library.albums.listing = library
|
||||||
self.library.albums.downloadState = 2
|
self.library.albums.downloadState = 2
|
||||||
self.library.backgroundNotification.show = false
|
self.library.backgroundNotification.show = false
|
||||||
localStorage.setItem("libraryAlbums", JSON.stringify(library))
|
CiderCache.putCache(cacheId, library)
|
||||||
self.searchLibraryAlbums(index)
|
self.searchLibraryAlbums(index)
|
||||||
// console.log(library)
|
// console.log(library)
|
||||||
}
|
}
|
||||||
|
@ -2633,12 +2642,14 @@ const app = new Vue({
|
||||||
async getLibraryArtistsFull(force = false, index) {
|
async getLibraryArtistsFull(force = false, index) {
|
||||||
let self = this
|
let self = this
|
||||||
let library = []
|
let library = []
|
||||||
|
let cacheId = "library-artists"
|
||||||
let downloaded = null;
|
let downloaded = null;
|
||||||
if ((this.library.artists.downloadState == 2 || this.library.artists.downloadState == 1) && !force) {
|
if ((this.library.artists.downloadState == 2 || this.library.artists.downloadState == 1) && !force) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (localStorage.getItem("libraryArtists") != null) {
|
let libraryArtists = await CiderCache.getCache(cacheId)
|
||||||
this.library.artists.listing = JSON.parse(localStorage.getItem("libraryArtists"))
|
if (libraryArtists) {
|
||||||
|
this.library.artists.listing = libraryArtists
|
||||||
this.searchLibraryArtists(index)
|
this.searchLibraryArtists(index)
|
||||||
}
|
}
|
||||||
if (this.songstest) {
|
if (this.songstest) {
|
||||||
|
@ -2717,7 +2728,7 @@ const app = new Vue({
|
||||||
self.library.artists.listing = library
|
self.library.artists.listing = library
|
||||||
self.library.artists.downloadState = 2
|
self.library.artists.downloadState = 2
|
||||||
self.library.artists.show = false
|
self.library.artists.show = false
|
||||||
localStorage.setItem("libraryArtists", JSON.stringify(library))
|
CiderCache.putCache(cacheId, library)
|
||||||
self.searchLibraryArtists(index)
|
self.searchLibraryArtists(index)
|
||||||
}
|
}
|
||||||
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
|
||||||
|
@ -2728,7 +2739,7 @@ const app = new Vue({
|
||||||
self.library.artists.listing = library
|
self.library.artists.listing = library
|
||||||
self.library.artists.downloadState = 2
|
self.library.artists.downloadState = 2
|
||||||
self.library.backgroundNotification.show = false
|
self.library.backgroundNotification.show = false
|
||||||
localStorage.setItem("libraryArtists", JSON.stringify(library))
|
CiderCache.putCache(cacheId, library)
|
||||||
self.searchLibraryArtists(index)
|
self.searchLibraryArtists(index)
|
||||||
// console.log(library)
|
// console.log(library)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue