forked from platypush/platypush
Better PWA installation prompt.
Display a popup modal instead of a confirm box to prompt the user to install the PWA app. `confirm` blocks the JavaScript engine when run in `beforeMount` and therefore the browser won't be able to proceed with `event.prompt()`.
This commit is contained in:
parent
666ea9ea6b
commit
5efc90ca17
2 changed files with 15 additions and 5 deletions
|
@ -4,11 +4,15 @@
|
||||||
<VoiceAssistant ref="voice-assistant" v-if="hasAssistant" />
|
<VoiceAssistant ref="voice-assistant" v-if="hasAssistant" />
|
||||||
<Pushbullet ref="pushbullet" v-if="hasPushbullet" />
|
<Pushbullet ref="pushbullet" v-if="hasPushbullet" />
|
||||||
<Ntfy ref="ntfy" v-if="hasNtfy" />
|
<Ntfy ref="ntfy" v-if="hasNtfy" />
|
||||||
|
<ConfirmDialog ref="pwaDialog" @input="installPWA">
|
||||||
|
Would you like to install this application locally?
|
||||||
|
</ConfirmDialog>
|
||||||
|
|
||||||
<router-view />
|
<router-view />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import ConfirmDialog from "@/components/elements/ConfirmDialog";
|
||||||
import Notifications from "@/components/Notifications";
|
import Notifications from "@/components/Notifications";
|
||||||
import Utils from "@/Utils";
|
import Utils from "@/Utils";
|
||||||
import Events from "@/Events";
|
import Events from "@/Events";
|
||||||
|
@ -21,13 +25,14 @@ export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
mixins: [Utils],
|
mixins: [Utils],
|
||||||
components: {
|
components: {
|
||||||
Pushbullet, Ntfy, Notifications, Events, VoiceAssistant
|
ConfirmDialog, Pushbullet, Ntfy, Notifications, Events, VoiceAssistant
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
config: {},
|
config: {},
|
||||||
userAuthenticated: false,
|
userAuthenticated: false,
|
||||||
|
pwaInstallEvent: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -62,6 +67,13 @@ export default {
|
||||||
this.config = await this.request('config.get', {}, 60000, false)
|
this.config = await this.request('config.get', {}, 60000, false)
|
||||||
this.userAuthenticated = true
|
this.userAuthenticated = true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
installPWA() {
|
||||||
|
if (this.pwaInstallEvent)
|
||||||
|
this.pwaInstallEvent.prompt()
|
||||||
|
|
||||||
|
this.$refs.pwaDialog.close()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
|
@ -71,8 +83,8 @@ export default {
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
window.addEventListener('beforeinstallprompt', (e) => {
|
window.addEventListener('beforeinstallprompt', (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (confirm('Would you like to install the application for more features?'))
|
this.pwaInstallEvent = e
|
||||||
e.prompt()
|
this.$refs.pwaDialog.show()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -64,10 +64,8 @@ export default {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: right;
|
justify-content: right;
|
||||||
padding: 1em 0 1em 1em;
|
|
||||||
border: 0;
|
border: 0;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
box-shadow: 0 -1px 2px 0 $default-shadow-color;
|
|
||||||
|
|
||||||
button {
|
button {
|
||||||
margin-right: 1em;
|
margin-right: 1em;
|
||||||
|
|
Loading…
Reference in a new issue