Merge branch '26-fix-webshare-api' into 'main'

fix WebShare API permissions by checking the URL to share

Closes #26

See merge request htwk-software/htwkalender-pwa!25
This commit is contained in:
Christoph Walther
2024-09-23 17:06:06 +00:00
2 changed files with 17 additions and 13 deletions

View File

@ -84,14 +84,16 @@ const forwardToHTWKalendar = () => {
}); });
}; };
const shareLink = () => { const shareData = computed(() => ({
if (typeof navigator.share === 'function' && navigator.canShare()) {
navigator
.share({
title: t("calendarLink.shareTitle"), title: t("calendarLink.shareTitle"),
text: t("calendarLink.shareText") + getLink(), text: t("calendarLink.shareText") + getLink(),
url: "https://" + domain + "/", url: "https://" + domain + "/",
}) }));
const shareLink = () => {
if (typeof navigator.share === 'function' && navigator.canShare(shareData.value)) {
navigator
.share(shareData.value)
.then(() => { .then(() => {
toast.add({ toast.add({
severity: "info", 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({ actionList.push({
label: t("calendarLink.share"), label: t("calendarLink.share"),
icon: "pi pi-share-alt", icon: "pi pi-share-alt",

View File

@ -59,12 +59,14 @@ function shareLink() {
} }
const link = "https://" + window.location.hostname + "/calendar/view?token=" + token.value + datePart; const link = "https://" + window.location.hostname + "/calendar/view?token=" + token.value + datePart;
if (typeof navigator.share === "function" && navigator.canShare()) { const shareData = {
navigator.share({
title: t("calendarLink.shareLinkTitle"), title: t("calendarLink.shareLinkTitle"),
text: t("calendarLink.shareLinkText"), text: t("calendarLink.shareLinkText"),
url: link, url: link,
}); };
if (typeof navigator.share === "function" && navigator.canShare(shareData)) {
navigator.share(shareData);
} else { } else {
navigator.clipboard.writeText(link).then(() => { navigator.clipboard.writeText(link).then(() => {
toast.add({ toast.add({