Install-button verschwindet nach abbruch

This commit is contained in:
silas
2018-10-08 15:05:58 +02:00
parent e7977aa487
commit 5a131ccee3
3 changed files with 44 additions and 22 deletions

View File

@@ -11,11 +11,26 @@ class DelayPromise extends Promise {
class InstallManager {
static init() {
window.addEventListener('beforeinstallprompt', e => {
this.deferredPromt = e;
e.preventDefault();
if (this.canInstallListener) {
this.canInstallListener(this.deferredPromt);
}
this.setDeferredPrompt(e);
});
}
static setDeferredPrompt(e){
this.deferredPromt = e;
if (this.canInstallListener) {
this.canInstallListener(this.deferredPromt);
}
}
static async prompt(){
if (Helper.isNotNull(this.deferredPromt)){
this.deferredPromt.prompt();
return this.deferredPromt.userChoice();
}
return Promise.resolve({
"outcome":"dismissed",
"platform":""
});
}