Skip to content

Commit

Permalink
working standalone + already installed detection
Browse files Browse the repository at this point in the history
  • Loading branch information
xyven1 committed Oct 5, 2023
1 parent 02d1e4c commit 02c74cb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
Binary file added src/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/logo.png
Binary file not shown.
6 changes: 0 additions & 6 deletions src/assets/logo.svg

This file was deleted.

36 changes: 32 additions & 4 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@
</v-card-actions>
</v-card>
</v-overlay>
<v-overlay
v-model="alreadyInstalledOverlay"
class="d-flex flex-col ma-2 justify-center align-center"
>
<v-card class="text-center">
<v-card-title>Already Installed!</v-card-title>
<v-card-text class="d-flex align-center">
The device already has the application installed! Check your apps
for an app called "IQP Tools", with this icon:
<v-img src="@/assets/icon.png" :width="80" />
</v-card-text>
<v-card-actions class="justify-center">
<v-btn color="error" @click="alreadyInstalledOverlay = false">
Close
</v-btn>
</v-card-actions>
</v-card>
</v-overlay>
<v-overlay
v-model="unknownInstallOverlay"
class="d-flex flex-col ma-2 justify-center align-center"
Expand Down Expand Up @@ -73,16 +91,26 @@ import { useDisplay } from "vuetify";
const { platform } = useDisplay();
const iosInstallOverlay = ref(false);
const alreadyInstalledOverlay = ref(false);
const unknownInstallOverlay = ref(false);
let installPromptEvent: BeforeInstallPromptEvent | null = null;
window.addEventListener("beforeinstallprompt", (e) => {
e.preventDefault();
installPromptEvent = e as BeforeInstallPromptEvent;
});
const isInStandaloneMode =
"standalone" in window.navigator && window.navigator.standalone;
function installPWA() {
if (platform.value.ios) {
const isInStandaloneMode = window.matchMedia(
"(display-mode: standalone)",
).matches;
async function installPWA() {
let installed = false;
//check if browser version supports the api
if ("getInstalledRelatedApps" in window.navigator) {
const relatedApps = await navigator.getInstalledRelatedApps();

Check failure on line 108 in src/views/Home.vue

View workflow job for this annotation

GitHub Actions / build_and_deploy

Property 'getInstalledRelatedApps' does not exist on type 'Navigator'.
installed = relatedApps.length > 0;
}
if (installed || true) {
alreadyInstalledOverlay.value = true;
} else if (platform.value.ios) {
iosInstallOverlay.value = true;
} else if (installPromptEvent) {
installPromptEvent.prompt();

Check failure on line 116 in src/views/Home.vue

View workflow job for this annotation

GitHub Actions / build_and_deploy

'installPromptEvent' is possibly 'null'.
Expand Down
6 changes: 6 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export default defineConfig({
purpose: "maskable",
},
],
related_applications: [
{
platform: "webapp",
url: "https://iss-scooter-data-collection.web.app",
},
],
shortcuts: [
{
name: "Take Data",
Expand Down

0 comments on commit 02c74cb

Please sign in to comment.