From 3ed25a412fe3716487578b1e1556de23acf237b9 Mon Sep 17 00:00:00 2001 From: survellow <59056368+survellow@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:03:24 +0200 Subject: [PATCH] fix WebShare API permissions by checking the URL to share --- frontend/src/components/CalendarLink.vue | 16 +++++++++------- frontend/src/view/UserCalendar.vue | 14 ++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/CalendarLink.vue b/frontend/src/components/CalendarLink.vue index 1e955e4..c7ca242 100644 --- a/frontend/src/components/CalendarLink.vue +++ b/frontend/src/components/CalendarLink.vue @@ -84,14 +84,16 @@ const forwardToHTWKalendar = () => { }); }; +const shareData = computed(() => ({ + title: t("calendarLink.shareTitle"), + text: t("calendarLink.shareText") + getLink(), + url: "https://" + domain + "/", +})); + const shareLink = () => { - if (typeof navigator.share === 'function' && navigator.canShare()) { + if (typeof navigator.share === 'function' && navigator.canShare(shareData.value)) { navigator - .share({ - title: t("calendarLink.shareTitle"), - text: t("calendarLink.shareText") + getLink(), - url: "https://" + domain + "/", - }) + .share(shareData.value) .then(() => { toast.add({ severity: "info", @@ -142,7 +144,7 @@ const actions = computed(() => { } ]; - if (typeof navigator.share === 'function' && navigator.canShare()) { + if (typeof navigator.share === 'function' && navigator.canShare(shareData.value)) { actionList.push({ label: t("calendarLink.share"), icon: "pi pi-share-alt", diff --git a/frontend/src/view/UserCalendar.vue b/frontend/src/view/UserCalendar.vue index a41eac3..ee803f8 100644 --- a/frontend/src/view/UserCalendar.vue +++ b/frontend/src/view/UserCalendar.vue @@ -59,12 +59,14 @@ function shareLink() { } const link = "https://" + window.location.hostname + "/calendar/view?token=" + token.value + datePart; - if (typeof navigator.share === "function" && navigator.canShare()) { - navigator.share({ - title: t("calendarLink.shareLinkTitle"), - text: t("calendarLink.shareLinkText"), - url: link, - }); + const shareData = { + title: t("calendarLink.shareLinkTitle"), + text: t("calendarLink.shareLinkText"), + url: link, + }; + + if (typeof navigator.share === "function" && navigator.canShare(shareData)) { + navigator.share(shareData); } else { navigator.clipboard.writeText(link).then(() => { toast.add({