TagSpaces is an offline, open source, document manager with tagging support
feat: added support for named sharing links
Ilian Sapundshiev545602e16344
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsxindex 4eba2fbd4..d23cbd6cf 100644--- a/src/renderer/components/EntryProperties.tsx+++ b/src/renderer/components/EntryProperties.tsx@@ -24,7 +24,10 @@ import React, {useState,} from 'react';import { styled, useTheme } from '@mui/material/styles';-import { getMetaFileLocationForFile } from '@tagspaces/tagspaces-common/paths';+import {+ getMetaFileLocationForFile,+ extractTitle,+} from '@tagspaces/tagspaces-common/paths';import L from 'leaflet';import {Grid,@@ -98,6 +101,7 @@ import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';+import { generateClipboardLink } from '-/utils/dom';const PREFIX = 'EntryProperties';@@ -846,8 +850,17 @@ function EntryProperties(props: Props) {data-tid="copyLinkToClipboardTID"color="primary"onClick={() => {+ const entryTitle = extractTitle(+ openedEntry.name,+ !openedEntry.isFile,+ PlatformIO.getDirSeparator(),+ );+ const clibboardItem = generateClipboardLink(+ sharingLink,+ entryTitle,+ );const promise =- navigator.clipboard.writeText(sharingLink);+ navigator.clipboard.write(clibboardItem);showNotification(t('core:linkCopied'));}}>diff --git a/src/renderer/components/dialogs/LinkGeneratorDialog.tsx b/src/renderer/components/dialogs/LinkGeneratorDialog.tsxindex 3557abeda..1ea3c9813 100644--- a/src/renderer/components/dialogs/LinkGeneratorDialog.tsx+++ b/src/renderer/components/dialogs/LinkGeneratorDialog.tsx@@ -34,9 +34,11 @@ import TextField from '@mui/material/TextField';import MenuItem from '@mui/material/MenuItem';import PlatformIO from '-/services/platform-facade';import Links from 'assets/links';+import { extractTitle } from '@tagspaces/tagspaces-common/paths';import { useTranslation } from 'react-i18next';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useNotificationContext } from '-/hooks/useNotificationContext';+import { generateClipboardLink } from '-/utils/dom';const PREFIX = 'LinkGeneratorDialog';@@ -136,11 +138,18 @@ function LinkGeneratorDialog(props: Props) {<Buttondata-tid="copySharingLinkTID"onClick={() => {- navigator.clipboard- .writeText(signedLink.current)- .then(() => {- showNotification(t('core:linkCopied'));- });+ const entryTitle = extractTitle(+ path,+ true,+ PlatformIO.getDirSeparator(),+ );+ const clibboardItem = generateClipboardLink(+ signedLink.current,+ entryTitle,+ );+ navigator.clipboard.write(clibboardItem).then(() => {+ showNotification(t('core:linkCopied'));+ });}}color="primary">diff --git a/src/renderer/components/menus/DirectoryMenu.tsx b/src/renderer/components/menus/DirectoryMenu.tsxindex f4535da22..aaad8c506 100644--- a/src/renderer/components/menus/DirectoryMenu.tsx+++ b/src/renderer/components/menus/DirectoryMenu.tsx@@ -49,6 +49,7 @@ import { useNotificationContext } from '-/hooks/useNotificationContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';import { useThumbGenerationContext } from '-/hooks/useThumbGenerationContext';+import { generateClipboardLink } from '-/utils/dom';interface Props {open: boolean;@@ -119,7 +120,7 @@ function DirectoryMenu(props: Props) {dispatch(AppActions.toggleProTeaser(slidePage));};- function generateFolderLink(): Promise<string> {+ function generateFolderLink(): Promise<any> {let locationID = currentLocation.uuid;let entryPath = currentDirectoryPath;if (selectedEntries && selectedEntries.length > 0) {@@ -131,23 +132,33 @@ function DirectoryMenu(props: Props) {const tmpLoc = locations.find((location) => location.uuid === locationID);return getLocationPath(tmpLoc).then((locationPath) => {const relativePath = getRelativeEntryPath(locationPath, entryPath);- return generateSharingLink(locationID, undefined, relativePath);+ const folderName = extractDirectoryName(+ selectedEntries[0].name,+ PlatformIO.getDirSeparator(),+ );+ return {+ url: generateSharingLink(locationID, undefined, relativePath),+ name: folderName,+ };});}function copySharingLink() {- //if (selectedEntries && selectedEntries.length === 1) {- generateFolderLink().then((sharingLink) =>+ generateFolderLink().then((sharingLink) => {+ const clibboardItem = generateClipboardLink(+ sharingLink.url,+ sharingLink.name,+ );navigator.clipboard- .writeText(sharingLink)+ .write(clibboardItem).then(() => {showNotification(t('core:sharingLinkCopied'));return true;}).catch(() => {showNotification(t('core:sharingLinkFailed'));- }),- );+ });+ });}function openDir() {diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsxindex db1fc86f8..693361ad1 100644--- a/src/renderer/components/menus/FileMenu.tsx+++ b/src/renderer/components/menus/FileMenu.tsx@@ -39,6 +39,7 @@ import {extractContainingDirectoryPath,extractParentDirectoryPath,generateSharingLink,+ extractTitle,} from '@tagspaces/tagspaces-common/paths';import PlatformIO from '-/services/platform-facade';import {@@ -68,6 +69,7 @@ import MenuKeyBinding from '-/components/menus/MenuKeyBinding';import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';import PlatformFacade from '-/services/platform-facade';import { TS } from '-/tagspaces.namespace';+import { generateClipboardLink } from '-/utils/dom';interface Props {anchorEl: Element;@@ -132,13 +134,22 @@ function FileMenu(props: Props) {onClose();if (selectedEntries && selectedEntries.length === 1) {const sharingLink = generateFileLink();+ const entryTitle = extractTitle(+ selectedEntries[0].name,+ !selectedEntries[0].isFile,+ PlatformIO.getDirSeparator(),+ );++ const clibboardItem = generateClipboardLink(sharingLink, entryTitle);+navigator.clipboard- .writeText(sharingLink)+ .write(clibboardItem).then(() => {showNotification(t('core:sharingLinkCopied'));return true;})- .catch(() => {+ .catch((e) => {+ console.log('Error copying to clipboard ' + e);showNotification(t('core:sharingLinkFailed'));});}diff --git a/src/renderer/utils/dom.ts b/src/renderer/utils/dom.tsindex affea24cb..1bab399fa 100644--- a/src/renderer/utils/dom.ts+++ b/src/renderer/utils/dom.ts@@ -140,3 +140,18 @@ export function base64ToBlob(base64) {}return bytes;}++export function generateClipboardLink(url, name?) {+ const htmlType = 'text/html';+ const plainTextType = 'text/plain';+ const htmlLink = `<a href="${url}">${name ? name : url}</a>`;+ const cbi = [+ new ClipboardItem({+ [htmlType]: new Blob([htmlLink], {+ type: htmlType,+ }),+ [plainTextType]: new Blob([url], { type: plainTextType }),+ }),+ ];+ return cbi;+}