From 9b0a67e0af83fff8a5a06ae3b79d0dac13643ca6 Mon Sep 17 00:00:00 2001 From: userquin Date: Sun, 30 Jul 2023 01:03:09 +0200 Subject: [PATCH] feat(pwa): register `web+ap` protocol handler --- middleware/auth.ts | 8 ++++++++ modules/pwa/i18n.ts | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/middleware/auth.ts b/middleware/auth.ts index 7d5c36c4..2f048b7e 100644 --- a/middleware/auth.ts +++ b/middleware/auth.ts @@ -15,6 +15,14 @@ export default defineNuxtRouteMiddleware((to) => { function handleAuth(to: RouteLocationNormalized) { if (to.path === '/') { + // handle PWA protocol handler + if (to.query['protocol-handler'] && to.query.target) { + const target = decodeURIComponent(to.query.target as string).replace(/^web\+ap:\/\//, 'https://') + // eslint-disable-next-line no-console + console.log(target) + return navigateTo('/home') + } + // Installed PWA shortcut to notifications if (to.query['notifications-pwa-shortcut'] !== undefined) { if (currentUser.value) diff --git a/modules/pwa/i18n.ts b/modules/pwa/i18n.ts index e1cfe25b..f489e021 100644 --- a/modules/pwa/i18n.ts +++ b/modules/pwa/i18n.ts @@ -124,6 +124,10 @@ export async function createI18n(): Promise { edge_side_panel: { preferred_width: 480, }, + protocol_handlers: [{ + protocol: 'web+ap', + url: '/?protocol-handler=1&target=%s', + }], } if (env === 'release') {