ImportSongs: Implement Google Drive beta testing
Instances that wish to enable Google Drive support should first enable it to only a small subset of users (100 maximum) to allow the OAuth screen to be verified by Google without hitting the user limit. Minimum level in the config can be set to enable beta testing of this feature and then disabled by setting it to None. - Add user level assignment screen to the administration panel - Add privacy policy and links to it in various places - Add switch accounts link near the Google Drive picker
This commit is contained in:
@@ -36,7 +36,10 @@ class CustomSongs{
|
||||
this.linkLocalFolder.parentNode.removeChild(this.linkLocalFolder)
|
||||
}
|
||||
|
||||
var groupGdrive = document.getElementById("group-gdrive")
|
||||
this.linkGdriveFolder = document.getElementById("link-gdrivefolder")
|
||||
this.linkGdriveAccount = document.getElementById("link-gdriveaccount")
|
||||
this.linkPrivacy = document.getElementById("link-privacy")
|
||||
if(gameConfig.google_credentials.gdrive_enabled){
|
||||
this.setAltText(this.linkGdriveFolder, strings.customSongs.gdriveFolder)
|
||||
pageEvents.add(this.linkGdriveFolder, ["mousedown", "touchstart"], this.gdriveFolder.bind(this))
|
||||
@@ -45,8 +48,14 @@ class CustomSongs{
|
||||
this.linkGdriveFolder.classList.add("selected")
|
||||
this.selected = this.items.length - 1
|
||||
}
|
||||
this.setAltText(this.linkGdriveAccount, strings.customSongs.gdriveAccount)
|
||||
pageEvents.add(this.linkGdriveAccount, ["mousedown", "touchstart"], this.gdriveAccount.bind(this))
|
||||
this.items.push(this.linkGdriveAccount)
|
||||
this.setAltText(this.linkPrivacy, strings.account.privacy)
|
||||
pageEvents.add(this.linkPrivacy, ["mousedown", "touchstart"], this.openPrivacy.bind(this))
|
||||
this.items.push(this.linkPrivacy)
|
||||
}else{
|
||||
this.linkGdriveFolder.parentNode.removeChild(this.linkGdriveFolder)
|
||||
groupGdrive.style.display = "none"
|
||||
}
|
||||
|
||||
this.endButton = this.getElement("view-end-button")
|
||||
@@ -237,13 +246,67 @@ class CustomSongs{
|
||||
}else if(e !== "cancel"){
|
||||
return Promise.reject(e)
|
||||
}
|
||||
}).finally(() => {
|
||||
var addRemove = !gpicker || !gpicker.oauthToken ? "add" : "remove"
|
||||
this.linkGdriveAccount.classList[addRemove]("hiddenbtn")
|
||||
})
|
||||
}
|
||||
gdriveAccount(event){
|
||||
if(event){
|
||||
if(event.type === "touchstart"){
|
||||
event.preventDefault()
|
||||
}else if(event.which !== 1){
|
||||
return
|
||||
}
|
||||
}
|
||||
if(this.locked || this.mode !== "main"){
|
||||
return
|
||||
}
|
||||
this.changeSelected(this.linkGdriveAccount)
|
||||
this.locked = true
|
||||
this.loading(true)
|
||||
if(!gpicker){
|
||||
var gpickerPromise = loader.loadScript("/src/js/gpicker.js").then(() => {
|
||||
gpicker = new Gpicker()
|
||||
})
|
||||
}else{
|
||||
var gpickerPromise = Promise.resolve()
|
||||
}
|
||||
gpickerPromise.then(() => {
|
||||
return gpicker.switchAccounts(locked => {
|
||||
this.locked = locked
|
||||
this.loading(locked)
|
||||
}, error => {
|
||||
this.showError(error)
|
||||
})
|
||||
}).then(() => {
|
||||
this.locked = false
|
||||
this.loading(false)
|
||||
}).catch(error => {
|
||||
if(error !== "cancel"){
|
||||
this.showError(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
openPrivacy(event){
|
||||
if(event){
|
||||
if(event.type === "touchstart"){
|
||||
event.preventDefault()
|
||||
}else if(event.which !== 1){
|
||||
return
|
||||
}
|
||||
}
|
||||
if(this.locked || this.mode !== "main"){
|
||||
return
|
||||
}
|
||||
this.changeSelected(this.linkPrivacy)
|
||||
open("privacy")
|
||||
}
|
||||
loading(show){
|
||||
if(show){
|
||||
loader.screen.appendChild(this.loaderDiv)
|
||||
}else{
|
||||
loader.screen.removeChild(this.loaderDiv)
|
||||
}else if(this.loaderDiv.parentNode){
|
||||
this.loaderDiv.parentNode.removeChild(this.loaderDiv)
|
||||
}
|
||||
}
|
||||
songsLoaded(songs){
|
||||
@@ -276,6 +339,12 @@ class CustomSongs{
|
||||
}else if(selected === this.linkGdriveFolder){
|
||||
assets.sounds["se_don"].play()
|
||||
this.gdriveFolder()
|
||||
}else if(selected === this.linkGdriveAccount){
|
||||
assets.sounds["se_don"].play()
|
||||
this.gdriveAccount()
|
||||
}else if(selected === this.linkPrivacy){
|
||||
assets.sounds["se_don"].play()
|
||||
this.openPrivacy()
|
||||
}
|
||||
}
|
||||
}else if(name === "previous" || name === "next"){
|
||||
@@ -327,6 +396,8 @@ class CustomSongs{
|
||||
}, 500)
|
||||
}
|
||||
showError(text){
|
||||
this.locked = false
|
||||
this.loading(false)
|
||||
if(this.mode === "error"){
|
||||
return
|
||||
}
|
||||
@@ -352,6 +423,8 @@ class CustomSongs{
|
||||
}
|
||||
if(gameConfig.google_credentials.gdrive_enabled){
|
||||
pageEvents.remove(this.linkGdriveFolder, ["mousedown", "touchstart"])
|
||||
pageEvents.remove(this.linkGdriveAccount, ["mousedown", "touchstart"])
|
||||
pageEvents.remove(this.linkPrivacy, ["mousedown", "touchstart"])
|
||||
}
|
||||
pageEvents.remove(this.endButton, ["mousedown", "touchstart"])
|
||||
pageEvents.remove(this.errorDiv, ["mousedown", "touchstart"])
|
||||
@@ -363,6 +436,8 @@ class CustomSongs{
|
||||
delete this.browse
|
||||
delete this.linkLocalFolder
|
||||
delete this.linkGdriveFolder
|
||||
delete this.linkGdriveAccount
|
||||
delete this.linkPrivacy
|
||||
delete this.endButton
|
||||
delete this.items
|
||||
delete this.loaderDiv
|
||||
|
||||
Reference in New Issue
Block a user