diff --git a/core/types.ts b/core/types.ts index b3b33c2..675db96 100644 --- a/core/types.ts +++ b/core/types.ts @@ -53,3 +53,8 @@ export interface RootState extends IndexState { config: ConfigState; } + +export interface WorkboxEvent extends Event +{ + isUpdate: boolean; +} diff --git a/nuxt.config.js b/nuxt.config.js index f07c49a..721d6d0 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -47,6 +47,7 @@ export default { "@/plugins/globals/mdc.client.ts", "@/plugins/globals/time.client.ts", + "@/plugins/refresh-dialog.client.ts", "@/plugins/vue-scroll-animator.client.ts" ], diff --git a/package.json b/package.json index 3020564..3fcf9fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@byloth/website", - "version": "5.0.9", + "version": "5.0.10", "description": "My personal website as a Nuxt.js application, written in TypeScript and based on Material Design.", "keywords": [ "Vue.js", diff --git a/plugins/globals.d.ts b/plugins/globals.d.ts new file mode 100644 index 0000000..ea5d01b --- /dev/null +++ b/plugins/globals.d.ts @@ -0,0 +1,15 @@ +import { MDCTextField } from "@material/textfield"; + +import Time from "@/core/time"; + +declare global +{ + interface Window + { + $workbox: Promise; + + mdc: { textfield: { MDCTextField: typeof MDCTextField } }; + + Time: Time; + } +} diff --git a/plugins/globals/mdc.client.ts b/plugins/globals/mdc.client.ts index b2997c2..c906f50 100644 --- a/plugins/globals/mdc.client.ts +++ b/plugins/globals/mdc.client.ts @@ -1,11 +1,3 @@ import { MDCTextField as _MDCTextField } from "@material/textfield"; -declare global -{ - interface Window - { - mdc: { textfield: { MDCTextField: typeof _MDCTextField } }; - } -} - window.mdc = { textfield: { MDCTextField: _MDCTextField } }; diff --git a/plugins/globals/time.client.ts b/plugins/globals/time.client.ts index babb1e5..87730c0 100644 --- a/plugins/globals/time.client.ts +++ b/plugins/globals/time.client.ts @@ -1,11 +1,3 @@ import Time from "@/core/time"; -declare global -{ - interface Window - { - Time: Time; - } -} - window.Time = Time; diff --git a/plugins/refresh-dialog.client.ts b/plugins/refresh-dialog.client.ts new file mode 100644 index 0000000..d09746f --- /dev/null +++ b/plugins/refresh-dialog.client.ts @@ -0,0 +1,28 @@ +import { Context } from "@nuxt/types"; + +import { WorkboxEvent } from "@/core/types"; + +export default async ({ store }: Context): Promise => +{ + const workbox = await window.$workbox; + + if (workbox) + { + workbox.addEventListener("installed", (event) => + { + const workboxEvent = event as WorkboxEvent; + + if (workboxEvent.isUpdate) + { + store.dispatch("dialog", { + type: "snackbar", + message: { text: "Sono disponibili dei nuovi contenuti!" }, + actions: [{ + text: "Ricarica", + callback: () => window.location.reload() + }] + }); + } + }); + } +}; diff --git a/store/config.ts b/store/config.ts index ee644e8..c4d592e 100644 --- a/store/config.ts +++ b/store/config.ts @@ -54,7 +54,7 @@ const state = (): ConfigState => ({ title: "Chi sono" } ], - version: "5.0.9" + version: "5.0.10" }); export { state };