-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pwa support, ask mobile users to download app (#643)
- Loading branch information
1 parent
512800d
commit 5b2fbf0
Showing
8 changed files
with
117 additions
and
17 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "Diveni", | ||
"short_name": "Diveni", | ||
"theme_color": "#8cc04d", | ||
"icons": [ | ||
{ | ||
"src": "./img/icons/logo192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "./img/icons/logo512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "./img/icons/logo192.png", | ||
"sizes": "192x192", | ||
"type": "image/png", | ||
"purpose": "maskable" | ||
}, | ||
{ | ||
"src": "./img/icons/logo512.png", | ||
"sizes": "512x512", | ||
"type": "image/png", | ||
"purpose": "maskable" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"background_color": "#000000" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<template> | ||
<b-modal | ||
v-model="checkIfNotInstalled" | ||
class="test" | ||
centered | ||
title="Download Diveni" | ||
@ok="install()" | ||
@hide="closeModal()" | ||
> | ||
{{t('page.landing.install')}} | ||
</b-modal> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent, ref} from "vue"; | ||
import {useI18n} from "vue-i18n"; | ||
export default defineComponent({ | ||
name: "DownloadPWAModal", | ||
setup() { | ||
const deferredPrompt: any = ref(); | ||
const checkIfNotInstalled = false; | ||
window.addEventListener("beforeinstallprompt", (e) => { | ||
e.preventDefault(); | ||
deferredPrompt.value = e; | ||
}); | ||
window.addEventListener("appinstalled", () => { | ||
deferredPrompt.value = null; | ||
}); | ||
const { t } = useI18n(); | ||
return {deferredPrompt, checkIfNotInstalled, t}; | ||
}, | ||
computed: { | ||
isMobile() { | ||
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( | ||
navigator.userAgent | ||
); | ||
}, | ||
}, | ||
created() { | ||
const isInStandaloneMode = () => | ||
(window.matchMedia('(display-mode: standalone)').matches) || document.referrer.includes('android-app://'); | ||
this.checkIfNotInstalled = this.isMobile && !isInStandaloneMode() && !localStorage.getItem('downloadPWA'); | ||
}, | ||
methods: { | ||
closeModal() { | ||
localStorage.setItem('downloadPWA', 'true'); | ||
}, | ||
async install() { | ||
console.log("Installing..."); | ||
if (this.deferredPrompt) { | ||
this.deferredPrompt.prompt(); | ||
this.deferredPrompt.userChoice.then((choiceResult: any) => { | ||
if (choiceResult.outcome === 'accepted') { | ||
console.log('User accepted the Diveni prompt'); | ||
} else { | ||
console.log('User dismissed the Diveni prompt'); | ||
} | ||
this.deferredPrompt = null; | ||
}); | ||
} | ||
}, | ||
}, | ||
}); | ||
</script> | ||
|
||
<style scoped lang="scss"></style> |
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
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