TagSpaces is an offline, open source, document manager with tagging support
Third party extensions not loaded (#2105)
Stanimir4d3bff3a853c
diff --git a/package-lock.json b/package-lock.jsonindex 95ee927b4..a5424dc90 100644--- a/package-lock.json+++ b/package-lock.json@@ -196,7 +196,7 @@"yarn": "please-use-npm"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.41"+ "@tagspacespro/tagspacespro": "5.0.42"}},"node_modules/@adobe/css-tools": {@@ -13904,9 +13904,9 @@}},"node_modules/@tagspacespro/tagspacespro": {- "version": "5.0.41",- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.41/ba4fc8219ce8341cb7921f11ec059f7b6b4ba51d",- "integrity": "sha512-bY1O/u4ig64VJ7YAmpl0F8aKdpDJaghV19fRplEl9EaRR87FonY2H6tcScDlH5KIZKCHBdjXge+FgDcNv/DbTw==",+ "version": "5.0.42",+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.42/c124709be8de644457f51dce9b58881e6feac87c",+ "integrity": "sha512-6R6pBkwOV1BM8VKMfs1c2kL6tEPxvHwxdiYzxcjIqKTRKiJ7Ct0lPw91sTm2CPkOKB0GoI+yHTdnM987WK5mfg==","license": "Proprietary","optional": true},diff --git a/src/main/main.ts b/src/main/main.tsindex c1614c719..5d2e2e160 100644--- a/src/main/main.ts+++ b/src/main/main.ts@@ -665,6 +665,7 @@ appextensions,supportedFileTypes,};+ console.log('set_extensions' + JSON.stringify(setExtensions));mainWindow?.webContents.send('set_extensions', setExtensions);// mainWindow.webContents.send('set_supported_file_types', supportedFileTypes);})diff --git a/src/renderer/components/dialogs/settings/SettingsExtensions.tsx b/src/renderer/components/dialogs/settings/SettingsExtensions.tsxindex 8c1861912..1ae936102 100644--- a/src/renderer/components/dialogs/settings/SettingsExtensions.tsx+++ b/src/renderer/components/dialogs/settings/SettingsExtensions.tsx@@ -30,36 +30,30 @@ import Switch from '@mui/material/Switch';import Button from '@mui/material/Button';import DeleteIcon from '@mui/icons-material/Delete';import { actions as SettingsActions, isDevMode } from '-/reducers/settings';-import {- actions as AppActions,- AppDispatch,- getExtensions,-} from '-/reducers/app';+import { actions as AppActions, AppDispatch } from '-/reducers/app';import { TS } from '-/tagspaces.namespace';import ConfirmDialog from '-/components/dialogs/ConfirmDialog';import InfoIcon from '-/components/InfoIcon';import { useTranslation } from 'react-i18next';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useIOActionsContext } from '-/hooks/useIOActionsContext';-import {- getUserDataDir,- loadExtensions,- removeExtension,- unZip,-} from '-/services/utils-io';+import { getUserDataDir, loadExtensions, unZip } from '-/services/utils-io';import AppConfig from '-/AppConfig';import { useFileUploadDialogContext } from '-/components/dialogs/hooks/useFileUploadDialogContext';+import { useExtensionsContext } from '-/hooks/useExtensionsContext';function SettingsExtensions() {const { t } = useTranslation();- const { currentLocation } = useCurrentLocationContext();+ const { extensions, removeExtension, updateExtension } =+ useExtensionsContext();+ const { findLocalLocation } = useCurrentLocationContext();const { uploadFilesAPI } = useIOActionsContext();const { openFileUploadDialog } = useFileUploadDialogContext();const fileInputRef = useRef<HTMLInputElement>(null);const [removeExtDialogOpened, setRemoveExtDialogOpened] =useState<TS.Extension>(undefined);- const extension = useSelector(getExtensions);+ //const extension = useSelector(getExtensions);const devMode = useSelector(isDevMode);const dispatch: AppDispatch = useDispatch();@@ -73,7 +67,16 @@ function SettingsExtensions() {dispatch(AppActions.resetProgress());openFileUploadDialog();const destinationPath = dataDir + AppConfig.dirSeparator + 'tsplugins';- uploadFilesAPI(files, destinationPath, onUploadProgress, false)+ const location = findLocalLocation();+ uploadFilesAPI(+ files,+ destinationPath,+ onUploadProgress,+ false,+ false,+ location.uuid,+ location.uuid,+ ).then((fsEntries: Array<TS.FileSystemEntry>) => {const targetPath =destinationPath +@@ -82,11 +85,14 @@ function SettingsExtensions() {AppConfig.dirSeparator +'extensions';const promises = fsEntries.map((fsEntry) =>- unZip(fsEntry.path, targetPath),+ unZip(+ fsEntry.path,+ targetPath + AppConfig.dirSeparator + fsEntry.name,+ ),);return Promise.all(promises).then((paths) => {loadExtensions();- paths.forEach((path) => currentLocation.deleteFilePromise(path));+ paths.forEach((path) => location.deleteFilePromise(path));return true;});})@@ -112,8 +118,8 @@ function SettingsExtensions() {</AccordionSummary><AccordionDetails><List>- {extension &&- extension+ {extensions &&+ extensions.filter((ext) => !ext.extensionExternal).map((ext) => (<ListItem key={ext.extensionId} disablePadding>@@ -137,8 +143,8 @@ function SettingsExtensions() {</AccordionSummary><AccordionDetails><List>- {extension &&- extension+ {extensions &&+ extensions.filter((ext) => ext.extensionExternal).map((ext) => (<ListItem key={ext.extensionId} disablePadding>@@ -149,32 +155,26 @@ function SettingsExtensions() {name="enableExtension"checked={ext.extensionEnabled}onChange={(event: ChangeEvent<HTMLInputElement>) => {+ const extId = ext.extensionId.endsWith('/build')+ ? ext.extensionId.slice(0, -'/build'.length)+ : ext.extensionId;+if (event.target.checked) {+ updateExtension({+ ...ext,+ extensionEnabled: true,+ });dispatch(- AppActions.updateExtension({- ...ext,- extensionEnabled: true,- }),- );- dispatch(- SettingsActions.enableExtension(- ext.extensionId,- true,- ),+ SettingsActions.enableExtension(extId, true),);loadExtensions();} else {+ updateExtension({+ ...ext,+ extensionEnabled: false,+ });dispatch(- AppActions.updateExtension({- ...ext,- extensionEnabled: false,- }),- );- dispatch(- SettingsActions.enableExtension(- ext.extensionId,- false,- ),+ SettingsActions.enableExtension(extId, false),);dispatch(SettingsActions.removeSupportedFileTypes(@@ -210,9 +210,6 @@ function SettingsExtensions() {})}confirmCallback={(result) => {if (result) {- dispatch(- AppActions.removeExtension(removeExtDialogOpened.extensionId),- );dispatch(SettingsActions.removeSupportedFileTypes(removeExtDialogOpened.extensionId,@@ -225,8 +222,8 @@ function SettingsExtensions() {confirmDialogTID="confirmRemoveExtDialogTID"confirmDialogContentTID="confirmRemoveExtDialogContentTID"/>- {extension &&- extension.filter((ext) => ext.extensionExternal).length < 1 && (+ {extensions &&+ extensions.filter((ext) => ext.extensionExternal).length < 1 && (<Typography variant="subtitle1">No extensions found</Typography>)}{devMode && (diff --git a/src/renderer/components/dialogs/settings/SettingsFileTypes.tsx b/src/renderer/components/dialogs/settings/SettingsFileTypes.tsxindex dd5e5d644..d32dcc705 100644--- a/src/renderer/components/dialogs/settings/SettingsFileTypes.tsx+++ b/src/renderer/components/dialogs/settings/SettingsFileTypes.tsx@@ -49,12 +49,13 @@ import {isDevMode,} from '-/reducers/settings';import ConfirmDialog from '-/components/dialogs/ConfirmDialog';-import { AppDispatch, getExtensions } from '-/reducers/app';+import { AppDispatch } from '-/reducers/app';import { supportedFileTypes as defaultSupportedFileTypes } from '-/extension-config';import useFirstRender from '-/utils/useFirstRender';import { useTranslation } from 'react-i18next';import { getUserDataDir } from '-/services/utils-io';import AppConfig from '-/AppConfig';+import { useExtensionsContext } from '-/hooks/useExtensionsContext';const PREFIX = 'SettingsFileTypes';@@ -86,6 +87,7 @@ const Root = styled('div')(({ theme: any }) => ({function SettingsFileTypes() {const { t } = useTranslation();+ const { extensions } = useExtensionsContext();const supportedFileTypes = useSelector(getSupportedFileTypes);const items = useRef<Array<TS.FileTypes>>(supportedFileTypes);const selectedItem = useRef<TS.FileTypes>(undefined);@@ -99,7 +101,7 @@ function SettingsFileTypes() {const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);const firstRender = useFirstRender();- const extensions = useSelector(getExtensions);+ //const extensions = useSelector(getExtensions);const devMode = useSelector(isDevMode);const dispatch: AppDispatch = useDispatch();diff --git a/src/renderer/containers/Root.tsx b/src/renderer/containers/Root.tsxindex 0a42deed0..798e16477 100644--- a/src/renderer/containers/Root.tsx+++ b/src/renderer/containers/Root.tsx@@ -46,6 +46,7 @@ import { EditedKanBanMetaContextProvider } from '-/hooks/EditedKanBanMetaContextimport { PerspectiveActionsContextProvider } from '-/hooks/PerspectiveActionsContextProvider';import { Pro } from '-/pro';import DialogsRoot from '-/containers/DialogsRoot';+import { ExtensionsContextProvider } from '-/hooks/ExtensionsContextProvider';type RootType = {store: Store<{}>;@@ -84,17 +85,19 @@ export default function Root({ store, persistor }: RootType) {<TagGroupsLocationContextProvider><TaggingActionsContextProvider><DndProvider backend={HTML5Backend}>- <DialogsRoot>- {Pro ? (- <Pro.contextProviders.BookmarksContextProvider>- <Pro.contextProviders.HistoryContextProvider>- <MainPage />- </Pro.contextProviders.HistoryContextProvider>- </Pro.contextProviders.BookmarksContextProvider>- ) : (- <MainPage />- )}- </DialogsRoot>+ <ExtensionsContextProvider>+ <DialogsRoot>+ {Pro ? (+ <Pro.contextProviders.BookmarksContextProvider>+ <Pro.contextProviders.HistoryContextProvider>+ <MainPage />+ </Pro.contextProviders.HistoryContextProvider>+ </Pro.contextProviders.BookmarksContextProvider>+ ) : (+ <MainPage />+ )}+ </DialogsRoot>+ </ExtensionsContextProvider></DndProvider></TaggingActionsContextProvider></TagGroupsLocationContextProvider>diff --git a/src/renderer/hooks/ExtensionsContextProvider.tsx b/src/renderer/hooks/ExtensionsContextProvider.tsxnew file mode 100644index 000000000..145f15dbd--- /dev/null+++ b/src/renderer/hooks/ExtensionsContextProvider.tsx@@ -0,0 +1,123 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2023-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React, {+ createContext,+ useEffect,+ useMemo,+ useReducer,+ useRef,+} from 'react';+import { AppDispatch } from '-/reducers/app';+import AppConfig from '-/AppConfig';+import {+ actions as SettingsActions,+ getEnabledExtensions,+} from '-/reducers/settings';+import { Extensions } from '../../main/types';+import { TS } from '-/tagspaces.namespace';+import { extensionsFound } from '-/extension-config';+import { useDispatch, useSelector } from 'react-redux';+import { mergeByProp } from '-/services/utils-io';++type ExtensionsContextData = {+ extensions: TS.Extension[];+ addExtensions: (newExt: TS.Extension[]) => void;+ removeExtension: (extensionId: string) => void;+ updateExtension: (extension: TS.Extension) => void;+};++export const ExtensionsContext = createContext<ExtensionsContextData>({+ extensions: undefined,+ addExtensions: undefined,+ removeExtension: undefined,+ updateExtension: undefined,+});++export type ExtensionsContextProviderProps = {+ children: React.ReactNode;+};++export const ExtensionsContextProvider = ({+ children,+}: ExtensionsContextProviderProps) => {+ const dispatch: AppDispatch = useDispatch();+ const enabledExtensions = useSelector(getEnabledExtensions);+ const extensions = useRef<TS.Extension[]>(extensionsFound);+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);++ useEffect(() => {+ if (AppConfig.isElectron) {+ window.electronIO.ipcRenderer.on('set_extensions', (arg: Extensions) => {+ const { extensions, supportedFileTypes } = arg;+ addExtensions(extensions);+ dispatch(SettingsActions.addSupportedFileTypes(supportedFileTypes));+ });+ return () => {+ window.electronIO.ipcRenderer.removeAllListeners('set_extensions');+ };+ }+ }, []);++ function addExtensions(newExt: TS.Extension[]) {+ const ext = mergeByProp(extensions.current, newExt, 'extensionId');+ extensions.current = ext.map((ex) => {+ if (enabledExtensions.includes(ex.extensionId)) {+ return { ...ex, extensionEnabled: true };+ }+ return ex;+ });+ forceUpdate();+ }++ function removeExtension(extensionId: string) {+ extensions.current = extensions.current.filter(+ (ext) => ext.extensionId !== extensionId,+ );+ if (AppConfig.isElectron) {+ window.electronIO.ipcRenderer.sendMessage('removeExtension', extensionId);+ } else {+ console.error('remove extensions is supported only on Electron.');+ }+ forceUpdate();+ }++ function updateExtension(extension: TS.Extension) {+ extensions.current = mergeByProp(+ extensions.current,+ [extension],+ 'extensionId',+ );+ forceUpdate();+ }++ const context = useMemo(() => {+ return {+ extensions: extensions.current,+ addExtensions,+ removeExtension,+ updateExtension,+ };+ }, [extensions.current]);++ return (+ <ExtensionsContext.Provider value={context}>+ {children}+ </ExtensionsContext.Provider>+ );+};diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsxindex 27f45ec09..47b9656b1 100644--- a/src/renderer/hooks/IOActionsContextProvider.tsx+++ b/src/renderer/hooks/IOActionsContextProvider.tsx@@ -969,7 +969,7 @@ export const IOActionsContextProvider = ({reflect: boolean = true,locationID: string = undefined,) {- return currentLocation+ return findLocation(locationID).getPropertiesPromise(filePath).then((entryProps) => {if (entryProps) {diff --git a/src/renderer/hooks/RendererListenerContextProvider.tsx b/src/renderer/hooks/RendererListenerContextProvider.tsxindex 42236cfbd..460aa2755 100644--- a/src/renderer/hooks/RendererListenerContextProvider.tsx+++ b/src/renderer/hooks/RendererListenerContextProvider.tsx@@ -23,7 +23,6 @@ import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import AppConfig from '-/AppConfig';import { actions as SettingsActions } from '-/reducers/settings';-import { Extensions } from '../../main/types';import { getNextFile, getPrevFile } from '-/services/utils-io';import { useSortedDirContext } from '-/perspectives/grid/hooks/useSortedDirContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';@@ -177,13 +176,13 @@ export const RendererListenerContextProvider = ({window.dispatchEvent(audioEvent);});- window.electronIO.ipcRenderer.on('set_extensions', (arg: Extensions) => {+ /* window.electronIO.ipcRenderer.on('set_extensions', (arg: Extensions) => {const { extensions, supportedFileTypes } = arg;dispatch(AppActions.addExtensions(extensions));dispatch(SettingsActions.addSupportedFileTypes(supportedFileTypes));//console.debug('extensions', extensions);//console.debug('supportedFileTypes', supportedFileTypes);- });+ });*//*ipcRenderer.on('start_ws', (event, arg) => {const { port } = arg;@@ -207,7 +206,7 @@ export const RendererListenerContextProvider = ({if (window.electronIO.ipcRenderer) {window.electronIO.ipcRenderer.removeAllListeners('cmd');window.electronIO.ipcRenderer.removeAllListeners('play-pause');- window.electronIO.ipcRenderer.removeAllListeners('set_extensions');+ //window.electronIO.ipcRenderer.removeAllListeners('set_extensions');window.electronIO.ipcRenderer.removeAllListeners('start_ws');}}diff --git a/src/renderer/hooks/useExtensionsContext.tsx b/src/renderer/hooks/useExtensionsContext.tsxnew file mode 100644index 000000000..4e4a1075d--- /dev/null+++ b/src/renderer/hooks/useExtensionsContext.tsx@@ -0,0 +1,23 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2023-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import { useContext } from 'react';++import { ExtensionsContext } from '-/hooks/ExtensionsContextProvider';++export const useExtensionsContext = () => useContext(ExtensionsContext);diff --git a/src/renderer/reducers/app.ts b/src/renderer/reducers/app.tsindex 9a910abff..4a086549d 100644--- a/src/renderer/reducers/app.ts+++ b/src/renderer/reducers/app.ts@@ -34,7 +34,7 @@ import {} from '-/reducers/settings';import { TS } from '-/tagspaces.namespace';import { getProTeaserSlideIndex } from '-/content/ProTeaserSlides';-import { extensionsFound } from '-/extension-config';+//import { extensionsFound } from '-/extension-config';import { ThunkDispatch } from 'redux-thunk';import { AnyAction } from 'redux';@@ -109,9 +109,9 @@ export const types = {//UPDATE_CURRENTDIR_ENTRIES: 'APP/UPDATE_CURRENTDIR_ENTRIES',//REFLECT_EDITED_ENTRY_PATHS: 'APP/REFLECT_EDITED_ENTRY_PATHS',// SET_ISLOADING: 'APP/SET_ISLOADING',- ADD_EXTENSIONS: 'APP/ADD_EXTENSIONS',- REMOVE_EXTENSIONS: 'APP/REMOVE_EXTENSIONS',- UPDATE_EXTENSION: 'APP/UPDATE_EXTENSION',+ //ADD_EXTENSIONS: 'APP/ADD_EXTENSIONS',+ //REMOVE_EXTENSIONS: 'APP/REMOVE_EXTENSIONS',+ //UPDATE_EXTENSION: 'APP/UPDATE_EXTENSION',};/*export type OpenedEntry = {@@ -164,7 +164,7 @@ if (window.ExtDefaultVerticalPanel === 'none') {}export const initialState = {- extensions: extensionsFound,+ //extensions: extensionsFound,//isLoading: false,error: null,loggedIn: false,@@ -547,7 +547,7 @@ export default (state: any = initialState, action: any) => {helpFeedbackPanelOpened: true,};}- case types.ADD_EXTENSIONS: {+ /*case types.ADD_EXTENSIONS: {const extensions = mergeByProp(state.extensions,action.extensions,@@ -562,8 +562,8 @@ export default (state: any = initialState, action: any) => {return ext;}),};- }- case types.UPDATE_EXTENSION: {+ }*/+ /*case types.UPDATE_EXTENSION: {return {...state,extensions: mergeByProp(@@ -572,15 +572,15 @@ export default (state: any = initialState, action: any) => {'extensionId',), // updateExtensions(state.extensions, action.extension)};- }- case types.REMOVE_EXTENSIONS: {+ }*/+ /*case types.REMOVE_EXTENSIONS: {return {...state,extensions: state.extensions.filter((ext) => ext.extensionId !== action.extensionId,),};- }+ }*/default: {return state;}@@ -601,7 +601,7 @@ function disableBackGestureMac() {}export const actions = {- addExtensions:+ /*addExtensions:(extensions: Array<TS.Extension>) =>(dispatch: (action) => void, getState: () => any) => {const { settings } = getState();@@ -616,15 +616,15 @@ export const actions = {type: types.ADD_EXTENSIONS,extensions,enabledExtensions,- }),- removeExtension: (extensionId: string) => ({+ }),*/+ /*removeExtension: (extensionId: string) => ({type: types.REMOVE_EXTENSIONS,extensionId,- }),- updateExtension: (extension: TS.Extension) => ({+ }),*/+ /*updateExtension: (extension: TS.Extension) => ({type: types.UPDATE_EXTENSION,extension,- }),+ }),*//*setLastBackgroundImageChange: (folderPath, lastBackgroundImageChange) => ({type: types.LAST_BACKGROUND_IMAGE_CHANGE,folderPath,@@ -983,7 +983,7 @@ export const isTagLibraryChanged = (state: any) => state.app.tagLibraryChanged;state.app.selectedEntries ? state.app.selectedEntries : [];*//*export const getSelectedEntriesLength = (state: any) =>state.app.selectedEntries ? state.app.selectedEntries.length : 0;*/-export const getExtensions = (state: any) => state.app.extensions;+//export const getExtensions = (state: any) => state.app.extensions;// export const getDirectoryMeta = (state: any) => state.app.directoryMeta;// export const isGeneratingThumbs = (state: any) => state.app.isGeneratingThumbs;// export const isReadOnlyMode = (state: any) => state.app.isReadOnlyMode;diff --git a/src/renderer/reducers/settings.ts b/src/renderer/reducers/settings.tsindex d8ccec6a0..6b75e4646 100644--- a/src/renderer/reducers/settings.ts+++ b/src/renderer/reducers/settings.ts@@ -936,6 +936,8 @@ export const getMainVerticalSplitSize = (state: any) =>state.settings.mainVSplitSize;export const getNewHTMLFileContent = (state: any) =>state.settings.newHTMLFileContent;+export const getEnabledExtensions = (state: any) =>+ state.settings.enabledExtensions;export const getTagGroupCollapsed = (state: any) =>state.settings.tagGroupCollapsed;export const getTagDelimiter = (state: any) => state.settings.tagDelimiter;diff --git a/src/renderer/services/utils-io.ts b/src/renderer/services/utils-io.tsindex 32aaea2f2..b2839ae2a 100644--- a/src/renderer/services/utils-io.ts+++ b/src/renderer/services/utils-io.ts@@ -1015,13 +1015,13 @@ export function unZip(filePath, targetPath): Promise<string> {}}-export function removeExtension(extensionId: string) {+/*export function removeExtension(extensionId: string) {if (AppConfig.isElectron) {window.electronIO.ipcRenderer.sendMessage('removeExtension', extensionId);} else {console.error('remove extensions is supported only on Electron.');}-}+}*/export function quitApp(): void {if (AppConfig.isElectron) {