diff --git a/src/components/Apps/AppViewer.tsx b/src/components/Apps/AppViewer.tsx index 5ae60ba..8b0211b 100644 --- a/src/components/Apps/AppViewer.tsx +++ b/src/components/Apps/AppViewer.tsx @@ -43,6 +43,35 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => { }; }, [app, path]); + const removeTrailingSlash = (str) => str.replace(/\/$/, ''); + const copyLinkFunc = (e) => { + const {tabId} = e.detail + if(tabId === app?.tabId){ + let link = 'qortal://' + app?.service + '/' + app?.name + if(path && path.startsWith('/')){ + link = link + removeTrailingSlash(path) + } + if(path && !path.startsWith('/')){ + link = link + '/' + removeTrailingSlash(path) + } + navigator.clipboard.writeText(link) + .then(() => { + console.log("Path copied to clipboard:", path); + }) + .catch((error) => { + console.error("Failed to copy path:", error); + }); + } + }; + + useEffect(() => { + subscribeToEvent("copyLink", copyLinkFunc); + + return () => { + unsubscribeFromEvent("copyLink", copyLinkFunc); + }; + }, [app, path]); + // Function to navigate back in iframe const navigateBackInIframe = async () => { if (iframeRef.current && iframeRef.current.contentWindow && history?.currentIndex > 0) { diff --git a/src/components/Apps/AppsNavBar.tsx b/src/components/Apps/AppsNavBar.tsx index e387a08..a5c5c36 100644 --- a/src/components/Apps/AppsNavBar.tsx +++ b/src/components/Apps/AppsNavBar.tsx @@ -7,6 +7,8 @@ import { import NavBack from "../../assets/svgs/NavBack.svg"; import NavAdd from "../../assets/svgs/NavAdd.svg"; import NavMoreMenu from "../../assets/svgs/NavMoreMenu.svg"; +import ContentCopyIcon from '@mui/icons-material/ContentCopy'; + import { ButtonBase, ListItemIcon, @@ -341,6 +343,38 @@ export const AppsNavBar = () => { primary="Refresh" /> + { + executeEvent("copyLink", { + tabId: selectedTab?.tabId, + }); + handleClose(); + }} + > + + + + + ); diff --git a/src/components/Apps/AppsNavBarDesktop.tsx b/src/components/Apps/AppsNavBarDesktop.tsx index 253cb98..9ba6540 100644 --- a/src/components/Apps/AppsNavBarDesktop.tsx +++ b/src/components/Apps/AppsNavBarDesktop.tsx @@ -7,6 +7,8 @@ import { import NavBack from "../../assets/svgs/NavBack.svg"; import NavAdd from "../../assets/svgs/NavAdd.svg"; import NavMoreMenu from "../../assets/svgs/NavMoreMenu.svg"; +import ContentCopyIcon from '@mui/icons-material/ContentCopy'; + import { ButtonBase, ListItemIcon, @@ -366,6 +368,38 @@ export const AppsNavBarDesktop = () => { primary="Refresh" /> + { + executeEvent("copyLink", { + tabId: selectedTab?.tabId, + }); + handleClose(); + }} + > + + + + + );