TagSpaces is an offline, open source, document manager with tagging support
extension-fixes (#1887)
Stanimir640c62946f3e
diff --git a/app/components/dialogs/settings/SettingsExtensions.tsx b/app/components/dialogs/settings/SettingsExtensions.tsxindex 7e652ffdb..71703674d 100644--- a/app/components/dialogs/settings/SettingsExtensions.tsx+++ b/app/components/dialogs/settings/SettingsExtensions.tsx@@ -30,29 +30,29 @@ import IconButton from '@mui/material/IconButton';import Button from '@mui/material/Button';import DeleteIcon from '@mui/icons-material/Delete';import { Progress } from 'aws-sdk/clients/s3';-import {- actions as SettingsActions,- getExtensions,- isDevMode-} from '-/reducers/settings';-import { actions as AppActions } from '-/reducers/app';+import { actions as SettingsActions, isDevMode } from '-/reducers/settings';+import { actions as AppActions, getExtensions } from '-/reducers/app';import IOActions from '-/reducers/io-actions';import { TS } from '-/tagspaces.namespace';import i18n from '-/services/i18n';import PlatformFacade from '-/services/platform-facade';+import PlatformIO from '-/services/platform-facade';interface Props {extension: Array<TS.Extension>;isDevMode: boolean;removeExtension: (extensionId: string) => void;+ removeSupportedFileTypes: (extensionId: string) => void;resetProgress: () => void;onUploadProgress: (progress: Progress, response: any) => void;toggleUploadDialog: () => void;uploadFilesAPI: (files: Array<File>,destination: string,- onUploadProgress?: (progress: Progress, response: any) => void+ onUploadProgress?: (progress: Progress, response: any) => void,+ uploadMeta?: boolean) => any;+ switchCurrentLocationType: (currentLocationId?) => void;}function SettingsExtensions(props: Props) {@@ -63,10 +63,12 @@ function SettingsExtensions(props: Props) {PlatformFacade.getUserDataDir().then(dataDir => {props.resetProgress();props.toggleUploadDialog();+ PlatformIO.disableObjectStoreSupport();+ PlatformIO.disableWebdavSupport();const destinationPath =dataDir + PlatformFacade.getDirSeparator() + 'tsplugins';props- .uploadFilesAPI(files, destinationPath, props.onUploadProgress)+ .uploadFilesAPI(files, destinationPath, props.onUploadProgress, false).then(fsEntries => {const targetPath =destinationPath +@@ -81,11 +83,12 @@ function SettingsExtensions(props: Props) {return Promise.all(promises).then(paths => {PlatformFacade.loadExtensions();paths.forEach(path => PlatformFacade.deleteFilePromise(path));- return true;+ return props.switchCurrentLocationType();});}).catch(error => {console.log('uploadFiles', error);+ return props.switchCurrentLocationType();});});}@@ -132,6 +135,7 @@ function SettingsExtensions(props: Props) {aria-label={i18n.t('core:delete')}onClick={() => {props.removeExtension(ext.extensionId);+ props.removeSupportedFileTypes(ext.extensionId);PlatformFacade.removeExtension(ext.extensionId);}}data-tid="revisionsTID"@@ -177,11 +181,13 @@ function mapStateToProps(state) {function mapActionCreatorsToProps(dispatch) {return bindActionCreators({- removeExtension: SettingsActions.removeExtension,+ removeExtension: AppActions.removeExtension,+ removeSupportedFileTypes: SettingsActions.removeSupportedFileTypes,onUploadProgress: AppActions.onUploadProgress,uploadFilesAPI: IOActions.uploadFilesAPI,toggleUploadDialog: AppActions.toggleUploadDialog,- resetProgress: AppActions.resetProgress+ resetProgress: AppActions.resetProgress,+ switchCurrentLocationType: AppActions.switchCurrentLocationType},dispatch);diff --git a/app/components/dialogs/settings/SettingsFileTypes.tsx b/app/components/dialogs/settings/SettingsFileTypes.tsxindex ade75ac9a..a7ac3f485 100644--- a/app/components/dialogs/settings/SettingsFileTypes.tsx+++ b/app/components/dialogs/settings/SettingsFileTypes.tsx@@ -46,13 +46,10 @@ import i18n from '-/services/i18n';import TransparentBackground from '-/components/TransparentBackground';import { TS } from '-/tagspaces.namespace';import AppConfig from '-/AppConfig';-import {- actions,- getExtensions,- getSupportedFileTypes-} from '-/reducers/settings';+import { actions, getSupportedFileTypes } from '-/reducers/settings';import ConfirmDialog from '-/components/dialogs/ConfirmDialog';import PlatformFacade from '-/services/platform-facade';+import { getExtensions } from '-/reducers/app';// import { extensionsFound } from '-/extension-config';const styles: any = (theme: any) => ({diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex 74f3ed978..cb3134056 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -986,7 +986,7 @@ function mapDispatchToProps(dispatch) {deleteDirectory: AppActions.deleteDirectory,deleteFile: AppActions.deleteFile,setSearchQuery: LocationIndexActions.setSearchQuery,- addExtensions: SettingsActions.addExtensions,+ addExtensions: AppActions.addExtensions,addSupportedFileTypes: SettingsActions.addSupportedFileTypes},dispatchdiff --git a/app/reducers/app.ts b/app/reducers/app.tsindex becb560b7..f03346e70 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -57,7 +57,8 @@ import {getRelativeEntryPath,getCleanLocationPath,updateFsEntries,- loadMetaDataPromise+ loadMetaDataPromise,+ mergeByProp} from '-/services/utils-io';import { getUuid } from '@tagspaces/tagspaces-common/utils-io';import i18n from '../services/i18n';@@ -80,6 +81,7 @@ import {} from '-/services/taglibrary-utils';import { getProTeaserSlideIndex } from '-/content/ProTeaserSlides';import GlobalSearch from '-/services/search-index';+import { extensionsFound } from '-/extension-config';export const types = {DEVICE_ONLINE: 'APP/DEVICE_ONLINE',@@ -153,7 +155,10 @@ export const types = {UPDATE_CURRENTDIR_ENTRY: 'APP/UPDATE_CURRENTDIR_ENTRY',UPDATE_CURRENTDIR_ENTRIES: 'APP/UPDATE_CURRENTDIR_ENTRIES',REFLECT_EDITED_ENTRY_PATHS: 'APP/REFLECT_EDITED_ENTRY_PATHS',- SET_ISLOADING: 'APP/SET_ISLOADING'+ SET_ISLOADING: 'APP/SET_ISLOADING',+ ADD_EXTENSION: 'APP/ADD_EXTENSION',+ ADD_EXTENSIONS: 'APP/ADD_EXTENSIONS',+ REMOVE_EXTENSIONS: 'APP/REMOVE_EXTENSIONS'};export const NotificationTypes = {@@ -211,6 +216,7 @@ if (window.ExtDefaultVerticalPanel === 'none') {}export const initialState = {+ extensions: extensionsFound,isLoading: false,error: null,loggedIn: false,@@ -926,6 +932,34 @@ export default (state: any = initialState, action: any) => {helpFeedbackPanelOpened: false};}+ case types.ADD_EXTENSIONS: {+ return {+ ...state,+ extensions: mergeByProp(+ state.extensions,+ action.extensions,+ 'extensionId'+ )+ };+ }+ case types.ADD_EXTENSION: {+ return {+ ...state,+ extensions: mergeByProp(+ state.extensions,+ [action.extension],+ 'extensionId'+ ) // updateExtensions(state.extensions, action.extension)+ };+ }+ case types.REMOVE_EXTENSIONS: {+ return {+ ...state,+ extensions: state.extensions.filter(+ ext => ext.extensionId !== action.extensionId+ )+ };+ }default: {return state;}@@ -946,6 +980,18 @@ function disableBackGestureMac() {}export const actions = {+ addExtension: (extension: TS.Extension) => ({+ type: types.ADD_EXTENSION,+ extension+ }),+ addExtensions: (extensions: Array<TS.Extension>) => ({+ type: types.ADD_EXTENSIONS,+ extensions+ }),+ removeExtension: (extensionId: string) => ({+ type: types.REMOVE_EXTENSIONS,+ extensionId+ }),setLastBackgroundImageChange: (folderPath, lastBackgroundImageChange) => ({type: types.LAST_BACKGROUND_IMAGE_CHANGE,folderPath,@@ -2858,6 +2904,7 @@ export const getSelectedEntries = (state: any) =>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 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/app/reducers/io-actions.ts b/app/reducers/io-actions.tsindex fdac3a9d5..c2b764515 100644--- a/app/reducers/io-actions.ts+++ b/app/reducers/io-actions.ts@@ -115,10 +115,7 @@ const actions = {fsEntryMeta.id,PlatformIO.getDirSeparator());- return PlatformIO.moveDirectoryPromise(- backupDir,- newBackupDir- )+ return PlatformIO.moveDirectoryPromise(backupDir, newBackupDir).then(() => {console.log('Moving revisions successful from ' +@@ -296,12 +293,14 @@ const actions = {* @param files* @param targetPath* @param onUploadProgress+ * @param uploadMeta - try to upload meta and thumbs if available* reader.onload not work for multiple files https://stackoverflow.com/questions/56178918/react-upload-multiple-files-using-window-filereader*/uploadFilesAPI: (files: Array<File>,targetPath: string,- onUploadProgress?: (progress: Progress, response: any) => void+ onUploadProgress?: (progress: Progress, response: any) => void,+ uploadMeta = true) => (dispatch: (actions: Object) => void) => {if (AppConfig.isElectron || AppConfig.isCordovaiOS) {const arrFiles = [];@@ -309,7 +308,7 @@ const actions = {arrFiles.push(files[i].path);}return dispatch(- actions.uploadFiles(arrFiles, targetPath, onUploadProgress)+ actions.uploadFiles(arrFiles, targetPath, onUploadProgress, uploadMeta));}@@ -410,11 +409,13 @@ const actions = {* @param paths* @param targetPath* @param onUploadProgress+ * @param uploadMeta*/uploadFiles: (paths: Array<string>,targetPath: string,- onUploadProgress?: (progress: Progress, response: any) => void+ onUploadProgress?: (progress: Progress, response: any) => void,+ uploadMeta = true) => (dispatch: (actions: Object) => void) =>new Promise((resolve, reject) => {function uploadFile(@@ -490,18 +491,20 @@ const actions = {target = target.substr(1);}uploadJobs.push([path, target, 'file']);- // copy meta- uploadJobs.push([- getMetaFileLocationForFile(path, AppConfig.dirSeparator),- getMetaFileLocationForFile(target, AppConfig.dirSeparator),- 'meta'- ]);- uploadJobs.push([- getThumbFileLocationForFile(path, AppConfig.dirSeparator),- getThumbFileLocationForFile(target, AppConfig.dirSeparator),- 'thumb',- path- ]);+ if (uploadMeta) {+ // copy meta+ uploadJobs.push([+ getMetaFileLocationForFile(path, AppConfig.dirSeparator),+ getMetaFileLocationForFile(target, AppConfig.dirSeparator),+ 'meta'+ ]);+ uploadJobs.push([+ getThumbFileLocationForFile(path, AppConfig.dirSeparator),+ getThumbFileLocationForFile(target, AppConfig.dirSeparator),+ 'thumb',+ path+ ]);+ }return true;});const jobsPromises = uploadJobs.map(job => {diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.tsindex de1345794..0382df162 100644--- a/app/reducers/settings-default.ts+++ b/app/reducers/settings-default.ts@@ -20,7 +20,7 @@ import AppConfig from '-/AppConfig';import keyBindings from '-/reducers/keybindings-default';import { PerspectiveIDs } from '-/perspectives';import { getUuid } from '@tagspaces/tagspaces-common/utils-io';-import { extensionsFound, supportedFileTypes } from '-/extension-config';+import { supportedFileTypes } from '-/extension-config';let desktopMode = !AppConfig.isMobile;if (window.ExtDisplayMode && window.ExtDisplayMode === 'mobile') {@@ -219,442 +219,7 @@ export default {}],keyBindings: keyBindings(AppConfig.isMacLike),- extensions: extensionsFound,supportedFileTypes: supportedFileTypes,- /*[- {- type: 'avif',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'bmp',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'c',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'cpp',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'cs',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'css',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'desktop',- viewer: '@tagspaces/extensions/url-viewer',- color: ''- },- {- type: 'eml',- viewer: '@tagspaces/extensions/mhtml-viewer',- color: '#a8cf31'- },- {- type: 'epub',- viewer: '@tagspaces/extensions/ebook-viewer',- color: ''- },- {- type: 'flac',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'mov',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'acc',- viewer: '@tagspaces/extensions/media-player',- color: ''- },- {- type: 'gif',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'h',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'htm',- viewer: '@tagspaces/extensions/html-viewer',- editor: '@tagspaces/extensions/html-editor',- color: ''- },- {- type: 'html',- viewer: '@tagspaces/extensions/html-viewer',- editor: '@tagspaces/extensions/html-editor',- color: ''- },- {- type: 'ico',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'java',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'jpeg',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'jpg',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'jif',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'jfif',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'js',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: '#d7ff78'- },- {- type: 'jsm',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'json',- viewer: '@tagspaces/extensions/json-editor',- editor: '@tagspaces/extensions/json-editor',- color: ''- },- {- type: 'less',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'mkv',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'aac',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: '3g2',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: '3gp',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'md',- viewer: '@tagspaces/extensions/md-editor/build',- editor: '@tagspaces/extensions/md-editor/build',- color: '#beefed'- },- {- type: 'mdx',- viewer: '@tagspaces/extensions/md-editor/build',- editor: '@tagspaces/extensions/text-editor',- color: '#beefed'- },- {- type: 'mht',- viewer: '@tagspaces/extensions/mhtml-viewer',- color: ''- },- {- type: 'mhtml',- viewer: '@tagspaces/extensions/mhtml-viewer',- color: ''- },- {- type: 'ml',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'mp3',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'lrv',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'mp4',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'm4a',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'oga',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'ogg',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'ogv',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'ogx',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'opus',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'pdf',- viewer: '@tagspaces/extensions/pdf-viewer',- color: '#f5897f'- },- {- type: 'php',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'pl',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'png',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'tga',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'psd',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'nef',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'cr2',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'dng',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'py',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'rb',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'rtf',- viewer: '@tagspaces/extensions/rtf-viewer',- color: ''- },- {- type: 'sh',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'spx',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'sql',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'svg',- viewer: '@tagspaces/extensions/image-viewer',- editor: '@tagspaces/extensions/text-editor',- color: '#9fd5ba'- },- {- type: 'tif',- viewer: '@tagspaces/extensions/image-viewer'- },- {- type: 'tiff',- viewer: '@tagspaces/extensions/image-viewer'- },- {- type: 'txt',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor'- },- {- type: 'url',- viewer: '@tagspaces/extensions/url-viewer',- color: ''- },- {- type: 'wav',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'wave',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'webm',- viewer: '@tagspaces/extensions/media-player',- color: '#c5e4f9'- },- {- type: 'webp',- viewer: '@tagspaces/extensions/image-viewer',- color: '#9fd5ba'- },- {- type: 'website',- viewer: '@tagspaces/extensions/url-viewer',- color: ''- },- {- type: 'xhtml',- viewer: '@tagspaces/extensions/html-viewer',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'xml',- viewer: '@tagspaces/extensions/text-editor',- editor: '@tagspaces/extensions/text-editor',- color: ''- },- {- type: 'zip',- viewer: '@tagspaces/extensions/archive-viewer',- color: '#ffe766'- },- {- type: 'docx',- viewer: '@tagspaces/extensions/document-viewer',- color: '#2196f3'- },- {- type: 'xlsx',- viewer: '@tagspaces/extensions/spreadsheet-viewer',- color: '#b2f30e'- },- {- type: 'xls',- viewer: '@tagspaces/extensions/spreadsheet-viewer',- color: '#b2f30e'- },- {- type: 'csv',- viewer: '@tagspaces/extensions/spreadsheet-viewer',- color: '#b2f30e'- },- {- type: 'ods',- viewer: '@tagspaces/extensions/spreadsheet-viewer',- color: '#b2f30e'- },- {- type: 'glb',- viewer: '@tagspaces/extensions/3d-viewer',- color: '#ac21f3'- },- {- type: 'gltf',- viewer: '@tagspaces/extensions/3d-viewer',- color: '#ac21f3'- },- {- type: 'stl',- viewer: '@tagspaces/extensions/3d-viewer',- color: '#ac21f3'- },- {- type: 'obj',- viewer: '@tagspaces/extensions/3d-viewer',- color: '#ac21f3'- },- {- type: 'msg',- viewer: '@tagspaces/extensions/msg-viewer',- color: '#a8cf31'- }- ],*/mapTileServers: [{uuid: getUuid(),diff --git a/app/reducers/settings.ts b/app/reducers/settings.tsindex 16c4e8e1e..a7c0d41b4 100644--- a/app/reducers/settings.ts+++ b/app/reducers/settings.ts@@ -27,6 +27,12 @@ import { actions as AppActions } from './app';import { TS } from '-/tagspaces.namespace';import { Pro } from '../pro';import { getUuid } from '@tagspaces/tagspaces-common/utils-io';+import {+ getDefaultEditor,+ getDefaultViewer,+ mergeByProp,+ updateByProp+} from '-/services/utils-io';export const types = {UPGRADE_SETTINGS: 'SETTINGS/UPGRADE_SETTINGS',@@ -76,9 +82,7 @@ export const types = {SET_ZOOM_OUT: 'SETTINGS/SET_ZOOM_OUT',SET_SUPPORTED_FILE_TYPES: 'SETTINGS/SET_SUPPORTED_FILE_TYPES',ADD_SUPPORTED_FILE_TYPES: 'SETTINGS/ADD_SUPPORTED_FILE_TYPES',- ADD_EXTENSION: 'SETTINGS/ADD_EXTENSION',- ADD_EXTENSIONS: 'SETTINGS/ADD_EXTENSIONS',- REMOVE_EXTENSIONS: 'SETTINGS/REMOVE_EXTENSIONS',+ REMOVE_SUPPORTED_FILE_TYPES: 'SETTINGS/REMOVE_SUPPORTED_FILE_TYPES',SET_LAST_PUBLISHED_VERSION: 'SETTINGS/SET_LAST_PUBLISHED_VERSION',SET_ENTRY_PROPERTIES_SPLIT_SIZE: 'SETTINGS/SET_ENTRY_PROPERTIES_SPLIT_SIZE',SET_MAIN_VSPLIT_SIZE: 'SETTINGS/SET_MAIN_VSPLIT_SIZE',@@ -94,34 +98,6 @@ export const types = {SET_FILE_EDIT_HISTORY: 'SET_FILE_EDIT_HISTORY'};-/**- * @param a - source array- * @param b - updates array- * @param prop- */-function merge(a, b, prop) {- const reduced = a.filter(- aitem => !b.find(bitem => aitem[prop] === bitem[prop])- );- return reduced.concat(b);-}--function updateExtensions(extArray, ext) {- const exist = extArray.some(ex => ex.extensionId === ext.extensionId);- let extensions;- if (exist) {- extensions = extArray.map((ex: TS.Extension) => {- if (ex.extensionId === ext.extensionId) {- return ext;- }- return ex;- });- } else {- extensions = [...extArray, ext];- }- return extensions;-}-export default (state: any = defaultSettings, action: any) => {switch (action.type) {case types.UPGRADE_SETTINGS: {@@ -150,7 +126,7 @@ export default (state: any = defaultSettings, action: any) => {// ...defaultSettings.keyBindings, // use to reset to the default key bindings...mergedKeyBindings],- supportedFileTypes: merge(+ supportedFileTypes: mergeByProp(state.supportedFileTypes,defaultSettings.supportedFileTypes,'type'@@ -354,31 +330,28 @@ export default (state: any = defaultSettings, action: any) => {case types.ADD_SUPPORTED_FILE_TYPES: {return {...state,- supportedFileTypes: merge(+ supportedFileTypes: updateByProp(state.supportedFileTypes,action.supportedFileTypes,'type')};}- case types.ADD_EXTENSIONS: {- return {- ...state,- extensions: merge(state.extensions, action.extensions, 'extensionId')- };- }- case types.ADD_EXTENSION: {- return {- ...state,- extensions: updateExtensions(state.extensions, action.extension)- };- }- case types.REMOVE_EXTENSIONS: {+ case types.REMOVE_SUPPORTED_FILE_TYPES: {+ const supportedFileTypes = state.supportedFileTypes.map(+ (fType: TS.FileTypes) => ({+ ...fType,+ ...(fType.viewer === action.extensionId && {+ viewer: getDefaultViewer(fType.type)+ }),+ ...(fType.editor === action.extensionId && {+ editor: getDefaultEditor(fType.type)+ })+ })+ );return {...state,- extensions: state.extensions.filter(- ext => ext.extensionId !== action.extensionId- )+ supportedFileTypes: supportedFileTypes};}case types.SET_ENTRY_PROPERTIES_SPLIT_SIZE: {@@ -680,22 +653,14 @@ export const actions = {type: types.SET_GLOBAL_KEYBINDING,enableGlobalKeyboardShortcuts}),- addExtension: (extension: TS.Extension) => ({- type: types.ADD_EXTENSION,- extension- }),- addExtensions: (extensions: Array<TS.Extension>) => ({- type: types.ADD_EXTENSIONS,- extensions- }),- removeExtension: (extensionId: string) => ({- type: types.REMOVE_EXTENSIONS,- extensionId- }),addSupportedFileTypes: (supportedFileTypes: []) => ({type: types.ADD_SUPPORTED_FILE_TYPES,supportedFileTypes}),+ removeSupportedFileTypes: (extensionId: string) => ({+ type: types.REMOVE_SUPPORTED_FILE_TYPES,+ extensionId+ }),setSupportedFileTypes: (supportedFileTypes: []) => ({type: types.SET_SUPPORTED_FILE_TYPES,supportedFileTypes@@ -870,7 +835,6 @@ export const getSupportedFileTypes = (state: any) =>state.settings.supportedFileTypes.sort((a, b) =>a.type > b.type ? 1 : a.type < b.type ? -1 : 0);-export const getExtensions = (state: any) => state.settings.extensions;export const getTagColor = (state: any) => state.settings.tagBackgroundColor;export const getTagTextColor = (state: any) => state.settings.tagTextColor;export const getCurrentTheme = (state: any) => state.settings.currentTheme;diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex 5c8386827..040004235 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -64,6 +64,7 @@ import {} from '-/services/thumbsgenerator';import { base64ToArrayBuffer } from '-/utils/dom';import { Pro } from '-/pro';+import { supportedFileTypes } from '-/extension-config';const supportedImgsWS = ['jpg',@@ -1321,6 +1322,45 @@ export function normalizeUrl(url: string) {return url;}+/**+ * @param a - source array+ * @param b - updates array+ * @param prop+ */+export function mergeByProp(a, b, prop) {+ const reduced = a.filter(+ aitem => !b.find(bitem => aitem[prop] === bitem[prop])+ );+ return reduced.concat(b);+}++/**+ * Update a props from b only if empty+ * @param a - source array+ * @param b - updates array+ * @param prop+ */+export function updateByProp(a, b, prop) {+ const commonResults = [];+ const uniqueResults = [];+ for (const el of a) {+ const commonB = b.find(bitem => bitem[prop] === el[prop]);+ if (commonB) {+ const common = {};+ Object.keys(el).forEach(function(key) {+ common[key] = el[key] || commonB[key];+ });+ commonResults.push(common);+ } else {+ uniqueResults.push(el);+ }+ }+ const uniqueB = b.filter(+ bitem => !a.find(aitem => bitem[prop] === aitem[prop])+ );+ return [...commonResults, ...uniqueResults, ...uniqueB];+}+/*** https://stackoverflow.com/a/71981197/2285631* @param a@@ -1500,3 +1540,17 @@ export function createFsEntryMeta(return newFsEntryMeta.id;});}+export function getDefaultViewer(fileType) {+ const type = supportedFileTypes.find(fType => fType.type === fileType);+ if (type) {+ return type.viewer;+ }+ return undefined;+}+export function getDefaultEditor(fileType) {+ const type = supportedFileTypes.find(fType => fType.type === fileType);+ if (type) {+ return type.editor;+ }+ return undefined;+}