TagSpaces is an offline, open source, document manager with tagging support
add installable extensions (#1884)
Stanimirec53260b31be
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex fb0d2c0a0..90e4b142f 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -1037,7 +1037,7 @@ function EntryProperties(props: Props) {),endAdornment: (<InputAdornment position="end">- <Tooltip title="core:copyLinkToClipboard">+ <Tooltip title={i18n.t('core:copyLinkToClipboard')}><Buttoncolor="primary"onClick={() => {diff --git a/app/components/dialogs/settings/SettingsAdvanced.tsx b/app/components/dialogs/settings/SettingsAdvanced.tsxindex dc5313126..95305c437 100644--- a/app/components/dialogs/settings/SettingsAdvanced.tsx+++ b/app/components/dialogs/settings/SettingsAdvanced.tsx@@ -39,7 +39,8 @@ import {actions as SettingsActions,getSettings,getMapTileServers,- getEnableWS+ getEnableWS,+ isDevMode} from '-/reducers/settings';import { TS } from '-/tagspaces.namespace';import MapTileServerDialog from '-/components/dialogs/settings/MapTileServerDialog';@@ -68,6 +69,8 @@ interface Props {classes: any;settings: any;setDesktopMode: (desktopMode: boolean) => void;+ setDevMode: (devMode: boolean) => void;+ isDevMode: boolean;setEnableWS: (enableWS: boolean) => void;setWarningOpeningFilesExternally: (warningOpeningFilesExternally: boolean@@ -130,6 +133,15 @@ function SettingsAdvanced(props: Props) {checked={!props.settings.desktopMode}/></ListItem>+ <ListItem className={classes.listItem}>+ <ListItemText primary={i18n.t('enableDevMode')} />+ <Switch+ data-tid="settingsEnableDevMode"+ disabled={window.ExtDevMode && window.ExtDevMode === true}+ onClick={() => props.setDevMode(!props.settings.devMode)}+ checked={props.isDevMode}+ />+ </ListItem><ListItem className={classes.listItem}><ListItemText primary={i18n.t('enableWS')} /><Switch@@ -371,7 +383,8 @@ function mapStateToProps(state) {return {settings: getSettings(state),tileServers: getMapTileServers(state),- enableWS: getEnableWS(state)+ enableWS: getEnableWS(state),+ isDevMode: isDevMode(state)};}@@ -381,6 +394,7 @@ function mapActionCreatorsToProps(dispatch) {setWarningOpeningFilesExternally:SettingsActions.setWarningOpeningFilesExternally,setDesktopMode: SettingsActions.setDesktopMode,+ setDevMode: SettingsActions.setDevMode,setEnableWS: SettingsActions.setEnableWS,setSaveTagInLocation: SettingsActions.setSaveTagInLocation,setGeoTaggingFormat: SettingsActions.setGeoTaggingFormat,diff --git a/app/components/dialogs/settings/SettingsDialog.tsx b/app/components/dialogs/settings/SettingsDialog.tsxindex 8150f964b..a1e2797bf 100644--- a/app/components/dialogs/settings/SettingsDialog.tsx+++ b/app/components/dialogs/settings/SettingsDialog.tsx@@ -40,6 +40,7 @@ import { clearAllURLParams } from '-/utils/dom';import SettingsAdvanced from '-/components/dialogs/settings/SettingsAdvanced';import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import Links from '-/content/links';+import SettingsExtensions from '-/components/dialogs/settings/SettingsExtensions';const styles: any = () => ({mainContent: {@@ -91,6 +92,10 @@ function SettingsDialog(props: Props) {data-tid="keyBindingsSettingsDialog"label={i18n.t('core:keyBindingsTab')}/>+ <Tab+ data-tid="extensionsSettingsDialog"+ label={i18n.t('core:extensionsTab')}+ /><Tabdata-tid="advancedSettingsDialogTID"label={i18n.t('core:advancedSettingsTab')}@@ -133,7 +138,8 @@ function SettingsDialog(props: Props) {{currentTab === 0 && <SettingsGeneral />}{currentTab === 1 && <SettingsFileTypes />}{currentTab === 2 && <SettingsKeyBindings />}- {currentTab === 3 && (+ {currentTab === 3 && <SettingsExtensions />}+ {currentTab === 4 && (<SettingsAdvancedshowResetSettings={setIsResetSettingsDialogOpened}/>@@ -145,7 +151,7 @@ function SettingsDialog(props: Props) {const renderActions = () => (<DialogActionsstyle={{- justifyContent: currentTab === 1 ? 'space-between' : 'flex-end'+ justifyContent: 'space-between'}}><Buttondiff --git a/app/components/dialogs/settings/SettingsExtensions.tsx b/app/components/dialogs/settings/SettingsExtensions.tsxnew file mode 100644index 000000000..7e652ffdb--- /dev/null+++ b/app/components/dialogs/settings/SettingsExtensions.tsx@@ -0,0 +1,193 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-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, { useRef } from 'react';+import { connect } from 'react-redux';+import { bindActionCreators } from 'redux';+import { Accordion, AccordionDetails, AccordionSummary } from '@mui/material';+import Typography from '@mui/material/Typography';+import Tooltip from '-/components/Tooltip';+import ExpandMoreIcon from '@mui/icons-material/ExpandMore';+import Box from '@mui/material/Box';+import List from '@mui/material/List';+import ListItem from '@mui/material/ListItem';+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 IOActions from '-/reducers/io-actions';+import { TS } from '-/tagspaces.namespace';+import i18n from '-/services/i18n';+import PlatformFacade from '-/services/platform-facade';++interface Props {+ extension: Array<TS.Extension>;+ isDevMode: boolean;+ removeExtension: (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+ ) => any;+}++function SettingsExtensions(props: Props) {+ const fileInputRef = useRef<HTMLInputElement>(null);++ function handleFileInputChange(selection: any) {+ const files: File[] = Array.from(selection.currentTarget.files);+ PlatformFacade.getUserDataDir().then(dataDir => {+ props.resetProgress();+ props.toggleUploadDialog();+ const destinationPath =+ dataDir + PlatformFacade.getDirSeparator() + 'tsplugins';+ props+ .uploadFilesAPI(files, destinationPath, props.onUploadProgress)+ .then(fsEntries => {+ const targetPath =+ destinationPath ++ PlatformFacade.getDirSeparator() ++ '@tagspaces' ++ PlatformFacade.getDirSeparator() ++ 'extensions';+ const promises = fsEntries.map(fsEntry =>+ PlatformFacade.unZip(fsEntry.path, targetPath)+ );+ // fsEntries.name.substring(0, fsEntries.extension.length + 1);+ return Promise.all(promises).then(paths => {+ PlatformFacade.loadExtensions();+ paths.forEach(path => PlatformFacade.deleteFilePromise(path));+ return true;+ });+ })+ .catch(error => {+ console.log('uploadFiles', error);+ });+ });+ }++ return (+ <div style={{ minHeight: 400 }}>+ <Accordion defaultExpanded>+ <AccordionSummary+ expandIcon={<ExpandMoreIcon />}+ aria-controls="internal-content"+ id="internal-header"+ >+ <Typography variant="h6">Core Extensions</Typography>+ </AccordionSummary>+ <AccordionDetails>+ <List>+ {props.extension+ .filter(ext => !ext.extensionExternal)+ .map(ext => (+ <ListItem key={ext.extensionId} disablePadding>+ {ext.extensionName} ({ext.version})+ </ListItem>+ ))}+ </List>+ </AccordionDetails>+ </Accordion>+ <Accordion>+ <AccordionSummary+ expandIcon={<ExpandMoreIcon />}+ aria-controls="installed-content"+ id="installed-header"+ >+ <Typography variant="h6">Installed Extensions</Typography>+ </AccordionSummary>+ <AccordionDetails>+ <List>+ {props.extension+ .filter(ext => ext.extensionExternal)+ .map(ext => (+ <ListItem key={ext.extensionId} disablePadding>+ {ext.extensionName} ({ext.version})+ <Tooltip title={i18n.t('core:removeExtension')}>+ <IconButton+ aria-label={i18n.t('core:delete')}+ onClick={() => {+ props.removeExtension(ext.extensionId);+ PlatformFacade.removeExtension(ext.extensionId);+ }}+ data-tid="revisionsTID"+ size="large"+ >+ <DeleteIcon color={'action'} />+ </IconButton>+ </Tooltip>+ </ListItem>+ ))}+ </List>+ {props.isDevMode && (+ <Box style={{ textAlign: 'center' }}>+ <Button+ data-tid="installExtensionTID"+ onClick={() => fileInputRef.current.click()}+ color="secondary"+ >+ {i18n.t('core:installExtension')}+ </Button>+ <input+ style={{ display: 'none' }}+ ref={fileInputRef}+ accept="zip"+ type="file"+ onChange={handleFileInputChange}+ />+ </Box>+ )}+ </AccordionDetails>+ </Accordion>+ </div>+ );+}++function mapStateToProps(state) {+ return {+ extension: getExtensions(state),+ isDevMode: isDevMode(state)+ };+}++function mapActionCreatorsToProps(dispatch) {+ return bindActionCreators(+ {+ removeExtension: SettingsActions.removeExtension,+ onUploadProgress: AppActions.onUploadProgress,+ uploadFilesAPI: IOActions.uploadFilesAPI,+ toggleUploadDialog: AppActions.toggleUploadDialog,+ resetProgress: AppActions.resetProgress+ },+ dispatch+ );+}++export default connect(+ mapStateToProps,+ mapActionCreatorsToProps+)(SettingsExtensions);diff --git a/app/components/dialogs/settings/SettingsFileTypes.tsx b/app/components/dialogs/settings/SettingsFileTypes.tsxindex 729d91fe3..ade75ac9a 100644--- a/app/components/dialogs/settings/SettingsFileTypes.tsx+++ b/app/components/dialogs/settings/SettingsFileTypes.tsx@@ -46,9 +46,14 @@ import i18n from '-/services/i18n';import TransparentBackground from '-/components/TransparentBackground';import { TS } from '-/tagspaces.namespace';import AppConfig from '-/AppConfig';-import { actions, getSupportedFileTypes } from '-/reducers/settings';+import {+ actions,+ getExtensions,+ getSupportedFileTypes+} from '-/reducers/settings';import ConfirmDialog from '-/components/dialogs/ConfirmDialog';-import { extensionsFound } from '-/extension-config';+import PlatformFacade from '-/services/platform-facade';+// import { extensionsFound } from '-/extension-config';const styles: any = (theme: any) => ({fileTypeColorDialog: {@@ -72,6 +77,7 @@ interface Props {supportedFileTypes: Array<TS.FileTypes>;setSupportedFileTypes?: (fileTypes: Array<any>) => void;classes: any;+ extensions: Array<TS.Extension>;}function SettingsFileTypes(props: Props) {@@ -334,12 +340,26 @@ function SettingsFileTypes(props: Props) {value={item.viewer}sx={{ width: 180 }}input={<Input id="" />}- onChange={event =>- updateItems(item, 'viewer', event.target.value)- }+ onChange={event => {+ const extension: TS.Extension = props.extensions.find(+ ext => ext.extensionId === event.target.value+ );+ if (extension.extensionExternal) {+ PlatformFacade.getUserDataDir().then(dataDir => {+ const externalExtensionPath =+ dataDir + PlatformFacade.getDirSeparator() + 'tsplugins';+ updateItems(+ item,+ 'extensionExternalPath',+ externalExtensionPath+ );+ });+ }+ updateItems(item, 'viewer', extension.extensionId);+ }}><MenuItem value="" />- {extensionsFound.map(+ {props.extensions.map(extension =>(extension.extensionTypes.includes('viewer') ||extension.extensionTypes.includes('editor')) && (@@ -362,7 +382,7 @@ function SettingsFileTypes(props: Props) {onChange={event => updateItems(item, 'editor', event.target.value)}><MenuItem value="">{i18n.t('clearEditor')}</MenuItem>- {extensionsFound+ {props.extensions.filter(extension =>extension.extensionTypes &&@@ -476,7 +496,8 @@ function SettingsFileTypes(props: Props) {}const mapStateToProps = state => ({- supportedFileTypes: getSupportedFileTypes(state)+ supportedFileTypes: getSupportedFileTypes(state),+ extensions: getExtensions(state)});const mapDispatchToProps = dispatch => ({diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex bf5a29df2..717d2d095 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -68,6 +68,8 @@"fileTypeTab": "File Types","keyBindingsTab": "Key Bindings","advancedSettingsTab": "Advanced",+ "extensionsTab": "Extensions",+ "enableDevMode": "Enable Developer Mode","fileViewer": "File Viewer","reloadDocument": "Reload Document","selectAllFiles": "Select all files",@@ -749,5 +751,6 @@"days": "days","change": "Change","fileSaved": "Saved",+ "installExtension": "Install Extension","-": "-"}diff --git a/app/main.dev.ts b/app/main.dev.tsindex 88d9c106b..78735cd17 100644--- a/app/main.dev.ts+++ b/app/main.dev.ts@@ -586,6 +586,30 @@ app.on('ready', async () => {.catch(err => console.error('load-extensions', err));});+ ipcMain.on('remove-extension', (e, extensionId) => {+ try {+ const extBuildIndex = extensionId.indexOf('/build');+ fs.rmSync(+ path.join(+ app.getPath('userData'),+ 'tsplugins',+ extBuildIndex > -1+ ? extensionId.substring(0, extBuildIndex)+ : extensionId+ ),+ {+ recursive: true+ }+ );+ } catch (e) {+ console.debug(e);+ }+ });++ ipcMain.handle('get-user-data', () => {+ return app.getPath('userData');+ });+ipcMain.on('focus-window', () => {if (mainWindow) {mainWindow.focus();diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.tsindex 7f50b8be9..de1345794 100644--- a/app/reducers/settings-default.ts+++ b/app/reducers/settings-default.ts@@ -49,6 +49,7 @@ export default {tagDelimiter: ' ',maxSearchResult: 1000,desktopMode,+ devMode: window.ExtDevMode ? window.ExtDevMode : false,saveTagInLocation: false,newHTMLFileContent:'<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body></body></html>',diff --git a/app/reducers/settings.ts b/app/reducers/settings.tsindex 55512faa1..16c4e8e1e 100644--- a/app/reducers/settings.ts+++ b/app/reducers/settings.ts@@ -33,6 +33,7 @@ export const types = {SET_LANGUAGE: 'SETTINGS/SET_LANGUAGE',TOGGLE_SHOWUNIXHIDDENENTRIES: 'SETTINGS/TOGGLE_SHOWUNIXHIDDENENTRIES',SET_DESKTOPMODE: 'SETTINGS/SET_DESKTOPMODE',+ SET_DEVMODE: 'SETTINGS/SET_DEVMODE',SET_ENABLE_WS: 'SETTINGS/SET_ENABLE_WS',WARNING_OPENING_FILES_EXTERNALLY: 'SETTINGS/WARNING_OPENING_FILES_EXTERNALLY',SET_SAVE_TAGS_IN_LOCATION: 'SETTINGS/SET_SAVE_TAGS_IN_LOCATION',@@ -77,6 +78,7 @@ export const 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',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',@@ -170,6 +172,9 @@ export default (state: any = defaultSettings, action: any) => {case types.SET_DESKTOPMODE: {return { ...state, desktopMode: action.desktopMode };}+ case types.SET_DEVMODE: {+ return { ...state, devMode: action.devMode };+ }case types.SET_ENABLE_WS: {return { ...state, enableWS: action.enableWS };}@@ -368,6 +373,14 @@ export default (state: any = defaultSettings, action: any) => {extensions: updateExtensions(state.extensions, action.extension)};}+ case types.REMOVE_EXTENSIONS: {+ return {+ ...state,+ extensions: state.extensions.filter(+ ext => ext.extensionId !== action.extensionId+ )+ };+ }case types.SET_ENTRY_PROPERTIES_SPLIT_SIZE: {return {...state,@@ -521,6 +534,10 @@ export const actions = {type: types.SET_DESKTOPMODE,desktopMode}),+ setDevMode: (devMode: boolean) => ({+ type: types.SET_DEVMODE,+ devMode+ }),setEnableWS: (enableWS: boolean) => ({type: types.SET_ENABLE_WS,enableWS@@ -671,6 +688,10 @@ export const actions = {type: types.ADD_EXTENSIONS,extensions}),+ removeExtension: (extensionId: string) => ({+ type: types.REMOVE_EXTENSIONS,+ extensionId+ }),addSupportedFileTypes: (supportedFileTypes: []) => ({type: types.ADD_SUPPORTED_FILE_TYPES,supportedFileTypes@@ -802,6 +823,8 @@ export const getDesktopMode = (state: any) => {}return window.ExtDisplayMode !== 'mobile';};+export const isDevMode = (state: any) =>+ window.ExtDevMode ? window.ExtDevMode : state.settings.devMode;export const isRevisionsEnabled = (state: any) =>state.settings.isRevisionsEnabled;export const getWarningOpeningFilesExternally = (state: any) =>diff --git a/app/services/platform-facade.ts b/app/services/platform-facade.tsindex 201ea33bb..dfb7df763 100644--- a/app/services/platform-facade.ts+++ b/app/services/platform-facade.ts@@ -71,7 +71,10 @@ import {platformCreateNewInstance,platformCheckFileExist,platformCheckDirExist,- platformLoadExtensions+ platformLoadExtensions,+ platformRemoveExtension,+ platformGetUserDataDir,+ platformUnZip} from '@tagspaces/tagspaces-platforms/platform-io';import AppConfig from '-/AppConfig';import { Pro } from '../pro';@@ -520,4 +523,16 @@ export default class PlatformFacade {static loadExtensions() {return platformLoadExtensions();}++ static removeExtension(extensionId: string) {+ return platformRemoveExtension(extensionId);+ }++ static getUserDataDir(): Promise<string> {+ return platformGetUserDataDir();+ }++ static unZip(filePath, targetPath): Promise<boolean> {+ return platformUnZip(filePath, targetPath);+ }}diff --git a/app/tagspaces.d.ts b/app/tagspaces.d.tsindex 3d3e334b7..b5da0ae50 100644--- a/app/tagspaces.d.ts+++ b/app/tagspaces.d.ts@@ -33,6 +33,7 @@ declare interface Window {ExtLogoURL?: string;ExtDefaultVerticalPanel?: string;ExtDisplayMode?: string;+ ExtDevMode?: boolean;ExtDefaultPerspective?: string;ExtTagLibrary?: Array<any>;ExtLocations?: Array<any>;diff --git a/package.json b/package.jsonindex 241853246..b8d9708d5 100644--- a/package.json+++ b/package.json@@ -185,7 +185,6 @@"i18next": "^20.3.5","i18next-browser-languagedetector": "^6.1.2","i18next-http-backend": "^1.2.8",- "jszip": "^3.7.1","leaflet": "^1.7.1","marked": "^4.0.12","mgrs": "^1.0.0",