-
-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow Fluidd to run fully offline (#986)
Signed-off-by: Pedro Lamas <[email protected]>
- Loading branch information
1 parent
78f2780
commit e91af48
Showing
5 changed files
with
103 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<template> | ||
<div> | ||
<v-snackbar | ||
v-model="needRefresh" | ||
timeout="-1" | ||
multi-line | ||
elevation="24" | ||
bottom | ||
right | ||
> | ||
<span v-html="$t('app.general.msg.needs_refresh')" /> | ||
<template #action="{ attrs }"> | ||
<app-btn | ||
v-bind="attrs" | ||
@click="updateServiceWorker" | ||
> | ||
{{ $t('app.general.btn.reload') }} | ||
</app-btn> | ||
</template> | ||
</v-snackbar> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { Component, Vue } from 'vue-property-decorator' | ||
import consola from 'consola' | ||
import { EventBus } from '@/eventBus' | ||
@Component({}) | ||
export default class RegisterServiceWorker extends Vue { | ||
updateSW: ((reloadPage?: boolean) => Promise<void>) | null = null | ||
needRefresh = false | ||
onOfflineReady () { | ||
consola.debug('[PWA] ready for offline work') | ||
EventBus.$emit(this.$tc('app.general.msg.offline_ready'), { timeout: 5000 }) | ||
} | ||
onNeedRefresh () { | ||
consola.debug('[PWA] needs refresh') | ||
this.needRefresh = true | ||
} | ||
onRegistered (registration?: ServiceWorkerRegistration) { | ||
consola.debug('[PWA] registered', registration) | ||
} | ||
onRegisterError (e: any) { | ||
consola.error('[PWA] registration error', e) | ||
} | ||
updateServiceWorker () { | ||
this.updateSW && this.updateSW(true) | ||
} | ||
async mounted () { | ||
try { | ||
const { registerSW } = await import('virtual:pwa-register') | ||
this.updateSW = registerSW({ | ||
immediate: true, | ||
onOfflineReady: this.onOfflineReady, | ||
onNeedRefresh: this.onNeedRefresh, | ||
onRegistered: this.onRegistered, | ||
onRegisterError: this.onRegisterError | ||
}) | ||
} catch { | ||
consola.error('[PWA] disabled') | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
:deep(.v-snack__wrapper .v-snack__content) { | ||
overflow: hidden; | ||
overflow-wrap: break-word; | ||
} | ||
</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