TagSpaces is an offline, open source, document manager with tagging support
feat: introducing openLink for handling external and internal links
Ilian Sapundshiev232bd504fb74
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsxindex 6ccf5ed17..831f454b0 100644--- a/app/components/EntryContainer.tsx+++ b/app/components/EntryContainer.tsx@@ -185,7 +185,7 @@ interface Props {openPrevFile: (path: string) => void;openNextFile: (path: string) => void;openFileNatively: (path: string) => void;- openURLExternally: (url: string) => void;+ openLink: (url: string) => void;showNotification: (text: string,notificationType?: string, // NotificationTypes@@ -310,8 +310,6 @@ const EntryContainer = (props: Props) => {const handleMessage = (data: any) => {let message;let textFilePath;- let decodedURI;-switch (data.command) {case 'showAlertDialog':message = data.title ? data.title : '';@@ -331,16 +329,7 @@ const EntryContainer = (props: Props) => {break;case 'openLinkExternally':// console.log('Open link externally: ' + data.link);- decodedURI = decodeURIComponent(data.link);- if (- decodedURI.startsWith('http://') ||- decodedURI.startsWith('https://') ||- decodedURI.startsWith('file://')- ) {- props.openURLExternally(decodedURI);- } else {- console.log('Not supported URL format: ' + decodedURI);- }+ props.openLink(data.link);break;case 'openFileNatively':console.log('Open file natively: ' + data.link);@@ -1290,7 +1279,7 @@ function mapActionCreatorsToProps(dispatch) {renameDirectory: AppActions.renameDirectory,openFsEntry: AppActions.openFsEntry,openFileNatively: AppActions.openFileNatively,- openURLExternally: AppActions.openURLExternally,+ openLink: AppActions.openLink,showNotification: AppActions.showNotification,openNextFile: AppActions.openNextFile,openPrevFile: AppActions.openPrevFile,diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 3fc147f86..66f750500 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -1767,6 +1767,18 @@ export const actions = {openFileNatively: (selectedFile: string) => () => {PlatformIO.openFile(selectedFile);},+ openLink: (url: string) => (dispatch: (actions: Object) => void) => {+ const decodedURI = decodeURIComponent(url);+ if (+ decodedURI.startsWith('http://') ||+ decodedURI.startsWith('https://') ||+ decodedURI.startsWith('file://')+ ) {+ dispatch(actions.openURLExternally(decodedURI));+ } else {+ console.log('Not supported URL format: ' + decodedURI);+ }+ },openURLExternally: (url: string, skipConfirmation: boolean = false) => () => {if (skipConfirmation) {PlatformIO.openUrl(url);@@ -1776,8 +1788,14 @@ export const actions = {PlatformIO.openUrl(url);}},- saveFile: () => () => {- actions.showNotification(i18n.t('core:notImplementedYet'), 'warning', true);+ saveFile: () => (dispatch: (actions: Object) => void) => {+ dispatch(+ actions.showNotification(+ i18n.t('core:notImplementedYet'),+ 'warning',+ true+ )+ );}};