Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Feb 6, 2023
1 parent 26e652d commit 1153c3e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 0 additions & 6 deletions composables/pwa.ts

This file was deleted.

3 changes: 1 addition & 2 deletions plugins/page-lifecycle.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export default defineNuxtPlugin(() => {
const frozenListeners: (() => void)[] = []

lifecycle.addEventListener('statechange', (evt) => {
// TODO: remove isPWAInstalled before merge
if (evt.newState === 'freeze')
/* isPWAInstalled && */frozenListeners.forEach(listener => listener())
frozenListeners.forEach(listener => listener())
else
state.value = evt.newState
})
Expand Down
8 changes: 7 additions & 1 deletion plugins/pwa.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export default defineNuxtPlugin(() => {
const showInstallPrompt = ref(false)
const hideInstall = useLocalStorage(STORAGE_KEY_PWA_HIDE_INSTALL, false)

// https://thomashunter.name/posts/2021-12-11-detecting-if-pwa-twa-is-installed
const ua = navigator.userAgent
const ios = ua.match(/iPhone|iPad|iPod/)
const standalone = window.matchMedia('(display-mode: standalone)').matches
const isInstalled = !!(standalone || (ios && !ua.match(/Safari/)))

const registerPeriodicSync = (swUrl: string, r: ServiceWorkerRegistration) => {
setInterval(async () => {
if (!online.value)
Expand Down Expand Up @@ -99,7 +105,7 @@ export default defineNuxtPlugin(() => {
return {
provide: {
pwa: reactive({
isInstalled: isPWAInstalled,
isInstalled,
showInstallPrompt,
cancelInstall,
install,
Expand Down
1 change: 0 additions & 1 deletion shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/// <reference types="vite-plugin-pwa/info" />
/// <reference types="vite-plugin-pwa/client" />


declare global {
namespace NodeJS {
interface Process {
Expand Down

0 comments on commit 1153c3e

Please sign in to comment.