Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #369 from bui/customsongs-filesystem
CustomSongs: Restore custom song list after reload
- Loading branch information
Showing
with
255 additions
and 66 deletions.
- +32 −0 public/src/js/abstractfile.js
- +2 −1 public/src/js/assets.js
- +116 −46 public/src/js/customsongs.js
- +51 −0 public/src/js/idb.js
- +1 −0 public/src/js/loader.js
- +1 −0 public/src/js/main.js
- +10 −6 public/src/js/songselect.js
- +42 −13 public/src/js/titlescreen.js
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -35,7 +35,8 @@ var assets = { | ||
"account.js", | ||
"lyrics.js", | ||
"customsongs.js", | ||
"abstractfile.js", | ||
"idb.js" | ||
], | ||
"css": [ | ||
"main.css", | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,51 @@ | ||
class IDB{ | ||
constructor(name, store){ | ||
this.name = name | ||
this.store = store | ||
} | ||
init(){ | ||
if(this.db){ | ||
return Promise.resolve(this.db) | ||
} | ||
var request = indexedDB.open(this.name) | ||
request.onupgradeneeded = event => { | ||
var db = event.target.result | ||
db.createObjectStore(this.store) | ||
} | ||
return this.promise(request).then(result => { | ||
this.db = result | ||
return this.db | ||
}, target => | ||
console.warn("DB error", target) | ||
) | ||
} | ||
promise(request){ | ||
return new Promise((resolve, reject) => { | ||
return pageEvents.race(request, "success", "error").then(response => { | ||
if(response.type === "success"){ | ||
return resolve(event.target.result) | ||
}else{ | ||
return reject(event.target) | ||
} | ||
}) | ||
}) | ||
} | ||
transaction(method, ...args){ | ||
return this.init().then(db => | ||
db.transaction(this.store, "readwrite").objectStore(this.store)[method](...args) | ||
).then(this.promise.bind(this)) | ||
} | ||
getItem(name){ | ||
return this.transaction("get", name) | ||
} | ||
setItem(name, value){ | ||
return this.transaction("put", value, name) | ||
} | ||
removeItem(name){ | ||
return this.transaction("delete", name) | ||
} | ||
removeDB(){ | ||
delete this.db | ||
return indexedDB.deleteDatabase(this.name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.