diff --git a/src/App.vue b/src/App.vue index b732aee6d..188f68957 100644 --- a/src/App.vue +++ b/src/App.vue @@ -263,19 +263,59 @@ import { Vue, Component } from "vue-facing-decorator"; import axios from "axios"; +import { AppString } from "@/constants/app"; +import { db } from "@/db/index"; +import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; + +interface Notification { + group: string; + type: string; + title: string; + text: string; +} + @Component export default class App extends Vue { + $notify!: (notification: Notification, timeout?: number) => void; + b64 = ""; - mounted() { - axios - .get("https://timesafari-pwa.anomalistlabs.com/web-push/vapid") - .then((response) => { - this.b64 = response.data.vapidKey; - console.log(this.b64); - }) - .catch((error) => { - console.error("API error", error); + + async mounted() { + try { + await db.open(); + const settings = await db.settings.get(MASTER_SETTINGS_KEY); + let pushUrl: string = AppString.DEFAULT_PUSH_SERVER; + if (settings?.pushServer) { + pushUrl = settings.pushServer; + } + + await axios.get(pushUrl + "/web-push/vapid").then((response) => { + this.b64 = response.data?.vapidKey; + console.log("Got vapid key:", this.b64); }); + if (!this.b64) { + this.$notify( + { + group: "alert", + type: "danger", + title: "Error Setting Notifications", + text: "Could not set notifications.", + }, + -1, + ); + } + } catch (error) { + console.error("Got an error initializing notifications:", error); + this.$notify( + { + group: "alert", + type: "danger", + title: "Error Setting Notifications", + text: "Got an error setting notifications.", + }, + -1, + ); + } } private askPermission(): Promise { diff --git a/src/constants/app.ts b/src/constants/app.ts index 270277d9f..313e4721b 100644 --- a/src/constants/app.ts +++ b/src/constants/app.ts @@ -4,20 +4,27 @@ * See also ../libs/veramo/setup.ts */ export enum AppString { - APP_NAME = "TimeSafari", + APP_NAME = "Time Safari", PROD_ENDORSER_API_SERVER = "https://api.endorser.ch", TEST_ENDORSER_API_SERVER = "https://test-api.endorser.ch", LOCAL_ENDORSER_API_SERVER = "http://localhost:3000", DEFAULT_ENDORSER_API_SERVER = TEST_ENDORSER_API_SERVER, + + PROD_PUSH_SERVER = "https://push.endorser.ch", + TEST_PUSH_SERVER = "https://timesafari-pwa.anomalistlabs.com", + LOCAL_PUSH_SERVER = "http://localhost:3001", + + DEFAULT_PUSH_SERVER = TEST_PUSH_SERVER, } /** - * See notiwind package + * The possible values for "group" and "type" are in App.vue. + * From the notiwind package */ export interface NotificationIface { - group: string; + group: string; // "alert" | "modal" type: string; // "toast" | "info" | "success" | "warning" | "danger" title: string; text: string; diff --git a/src/db/index.ts b/src/db/index.ts index 37d6cf517..ea8556c52 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -45,5 +45,8 @@ db.on("populate", () => { db.settings.add({ id: MASTER_SETTINGS_KEY, apiServer: AppString.DEFAULT_ENDORSER_API_SERVER, + + // remember that things you add from now on aren't automatically in the DB for old users + pushServer: AppString.DEFAULT_PUSH_SERVER, }); }); diff --git a/src/db/tables/settings.ts b/src/db/tables/settings.ts index 41196de29..20c378ef4 100644 --- a/src/db/tables/settings.ts +++ b/src/db/tables/settings.ts @@ -20,9 +20,9 @@ export type Settings = { lastViewedClaimId?: string; // Last viewed claim ID lastNotifiedClaimId?: string; // Last notified claim ID isRegistered?: boolean; + pushServer?: string; // Push server URL // Array of named search boxes defined by bounding boxes - searchBoxes?: Array<{ name: string; bbox: BoundingBox; diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index f222fc3c9..9bd7c73bf 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -324,19 +324,55 @@ + + +
+

+ Notification Push Server +

+ + + + + @@ -346,7 +382,7 @@