Skip to content

TagSpaces is an offline, open source, document manager with tagging support

handle mutiple instances of tagspaces and tag library, history, search queries, recent files (#2151)

Stanimir28ac0f9a8c12
diff --git a/package-lock.json b/package-lock.json
index 74d4aca1c..232bf2fda 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -198,7 +198,7 @@
"yarn": "please-use-npm"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.66"
+ "@tagspacespro/tagspacespro": "5.0.69"
}
},
"node_modules/@adobe/css-tools": {
@@ -15725,9 +15725,9 @@
}
},
"node_modules/@tagspacespro/tagspacespro": {
- "version": "5.0.66",
- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.66/76b250b4128e7b4f2e43b2dc33f02c3ce43022e6",
- "integrity": "sha512-cJ7lR3FB4GuqqPJudfXE7LWLysD+iFu1q4pMuMdOriEog3pmrb+agr8YccR4ubEFSUrHHtXKK5sawHPWZzLDvQ==",
+ "version": "5.0.69",
+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.69/9dc93cc62608722193d2dc7f2885019ea25305ae",
+ "integrity": "sha512-Lh3aylkOBFSBiCLcmuOhiROZsr+5cnYF0l/a8mQJS0qtWFVtyYeKhuh4ZJ017OvxTGc6Sczdj256K0XA83A2bw==",
"license": "Proprietary",
"optional": true
},
diff --git a/package.json b/package.json
index b1844f82c..5a50499f9 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,7 @@
"build": "npm run prebuild && concurrently \"npm run build:main\" \"npm run build:renderer\" && node -r ts-node/register ./.erb/scripts/link-modules.ts",
"build-e2e": "node scripts/setup-tests.js && cross-env E2E_BUILD=true NODE_ENV=test npm run build",
"build-e2e-dev": "ts-node ./.erb/scripts/clean.js && npm run prepare-node && cross-env E2E_BUILD=true concurrently \"npm run build:main\" \"npm run build:renderer\" \"npm run build:web\"",
- "build-e2e-web": "node scripts/setup-tests.js && cross-env E2E_BUILD=true NODE_ENV=test && npm run prepare-web-pro && npm run build:web",
+ "build-e2e-web": "node scripts/setup-tests.js && cross-env E2E_BUILD=true NODE_ENV=test && npm run prepare-web-pro",
"build:cordova": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.cordova.prod.ts",
"build:cordova:dev": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.cordova.dev.ts",
"build:dll": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.ts",
@@ -234,7 +234,7 @@
"uuid": "^9.0.0"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.66"
+ "@tagspacespro/tagspacespro": "5.0.69"
},
"devDependencies": {
"@electron/notarize": "^2.3.2",
diff --git a/src/renderer/components/LocationManager.tsx b/src/renderer/components/LocationManager.tsx
index 862fc2c51..d76df9808 100644
--- a/src/renderer/components/LocationManager.tsx
+++ b/src/renderer/components/LocationManager.tsx
@@ -236,7 +236,7 @@ function LocationManager(props: Props) {
})}
confirmCallback={(result) => {
if (result && selectedLocation) {
- deleteLocation(selectedLocation);
+ deleteLocation(selectedLocation.uuid);
//dispatch(LocationActions.deleteLocation(selectedLocation));
}
}}
diff --git a/src/renderer/components/SearchAutocomplete.tsx b/src/renderer/components/SearchAutocomplete.tsx
index dae16e15f..8fe81991f 100644
--- a/src/renderer/components/SearchAutocomplete.tsx
+++ b/src/renderer/components/SearchAutocomplete.tsx
@@ -61,7 +61,6 @@ import {
} from '-/components/SearchOptions';
import CloseIcon from '@mui/icons-material/Close';
import { getTagLibrary } from '-/services/taglibrary-utils';
-import { getSearches } from '-/reducers/searches';
import { getSearchOptions } from '-/components/SearchOptionsMenu';
import { dataTidFormat } from '-/services/test';
import { useTheme } from '@mui/material/styles';
@@ -72,6 +71,7 @@ import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
import { removePrefix } from '-/services/utils-io';
import { isDesktopMode } from '-/reducers/settings';
+import { useSavedSearchesContext } from '-/hooks/useSavedSearchesContext';
interface Props {
style?: any;
@@ -106,6 +106,7 @@ function SearchAutocomplete(props: Props) {
} = useDirectoryContentContext();
const { isIndexing, searchAllLocations, searchLocationIndex } =
useLocationIndexContext();
+ const { searches } = useSavedSearchesContext();
const bookmarksContext = Pro?.contextProviders?.BookmarksContext
? useContext<TS.BookmarksContextData>(Pro.contextProviders.BookmarksContext)
: undefined;
@@ -115,7 +116,6 @@ function SearchAutocomplete(props: Props) {
const dispatch: AppDispatch = useDispatch();
const maxSearchResults = useSelector(getMaxSearchResults);
const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);
- const searches: Array<TS.SearchQuery> = useSelector(getSearches);
const openLinkDispatch = (link, options) => openLink(link, options);
diff --git a/src/renderer/components/SearchPopover.tsx b/src/renderer/components/SearchPopover.tsx
index e4a443c52..deabcf8ec 100644
--- a/src/renderer/components/SearchPopover.tsx
+++ b/src/renderer/components/SearchPopover.tsx
@@ -48,7 +48,6 @@ import {
import { FileTypeGroups, haveSearchFilters } from '-/services/search';
import { Pro } from '../pro';
import { parseGeoLocation, parseLatLon } from '-/utils/geo';
-import { getSearches } from '-/reducers/searches';
import { TS } from '-/tagspaces.namespace';
import { ProLabel, BetaLabel, ProTooltip } from '-/components/HelperComponents';
import Links from 'assets/links';
@@ -76,6 +75,7 @@ import { classes, SidePanel } from '-/components/SidePanels.css';
import { useTranslation } from 'react-i18next';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
+import { useSavedSearchesContext } from '-/hooks/useSavedSearchesContext';
const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;
@@ -98,10 +98,10 @@ function SearchPopover(props: Props) {
setSearchQuery,
exitSearchMode,
} = useDirectoryContentContext();
+ const { searches } = useSavedSearchesContext();
const { getIndex, isIndexing } = useLocationIndexContext();
- const [, forceUpdate] = useReducer((x) => x + 1, 0);
+ const [, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const maxSearchResults = useSelector(getMaxSearchResults);
- const searches = useSelector(getSearches);
const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);
// const textQuery = useRef<string>(searchQuery.textQuery);
// const tagsAND = useRef<Array<TS.Tag>>(searchQuery.tagsAND);
diff --git a/src/renderer/components/StoredSearches.tsx b/src/renderer/components/StoredSearches.tsx
index 33dc9c1ec..8b495a3c5 100644
--- a/src/renderer/components/StoredSearches.tsx
+++ b/src/renderer/components/StoredSearches.tsx
@@ -40,7 +40,6 @@ import {
getStoredSearchesVisible,
} from '-/reducers/settings';
import { Pro } from '../pro';
-import { actions as SearchActions, getSearches } from '-/reducers/searches';
import { TS } from '-/tagspaces.namespace';
import SearchMenu from '-/components/menus/SearchMenu';
import HistoryMenu from '-/components/menus/HistoryMenu';
@@ -49,13 +48,11 @@ import { classes, SidePanel } from '-/components/SidePanels.css';
import { useTranslation } from 'react-i18next';
import RenderHistory from '-/components/RenderHistory';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
-import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
+import { useSavedSearchesContext } from '-/hooks/useSavedSearchesContext';
interface Props {
style?: any;
- searches: Array<TS.SearchQuery>;
showUnixHiddenEntries: boolean;
- addSearches: (searches: Array<TS.SearchQuery>) => void;
reduceHeightBy: number;
storedSearchesVisible: boolean;
showBookmarks: boolean;
@@ -73,7 +70,8 @@ const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;
function StoredSearches(props: Props) {
const { t } = useTranslation();
- const { setSearchQuery, findFromSavedSearch } = useDirectoryContentContext();
+ const { setSearchQuery } = useDirectoryContentContext();
+ const { searches, findFromSavedSearch } = useSavedSearchesContext();
const bookmarksContext = Pro?.contextProviders?.BookmarksContext
? useContext<TS.BookmarksContextData>(
Pro?.contextProviders?.BookmarksContext,
@@ -99,7 +97,7 @@ function StoredSearches(props: Props) {
const fileInputRef = useRef<HTMLInputElement>(null);
const menuHistoryKey = useRef<string>(undefined);
const historyKeys = Pro ? Pro.keys.historyKeys : {};
- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0);
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const ExportSearchesDialog =
Pro && Pro.UI ? Pro.UI.ExportSearchesDialog : false;
@@ -115,7 +113,7 @@ function StoredSearches(props: Props) {
};
const editSearch = (uuid: string) => {
- const savedSearch = props.searches.find((search) => search.uuid === uuid);
+ const savedSearch = searches.find((search) => search.uuid === uuid);
if (!savedSearch) {
return true;
}
@@ -132,7 +130,7 @@ function StoredSearches(props: Props) {
const preventDefault = (event: React.SyntheticEvent) =>
event.preventDefault();
- const noSearchesFound = props.searches.length < 1;
+ const noSearchesFound = searches.length < 1;
const { reduceHeightBy } = props;
@@ -250,7 +248,7 @@ function StoredSearches(props: Props) {
)}
</Grid>
{props.storedSearchesVisible &&
- props.searches.map((search) => (
+ searches.map((search) => (
<ListItem dense style={{ paddingLeft: 0 }} key={search.uuid}>
<Grid item xs={10} style={{ width: 250 }}>
<Button
@@ -556,7 +554,7 @@ function StoredSearches(props: Props) {
<ExportSearchesDialog
open={isExportSearchesDialogOpened}
onClose={() => setExportSearchesDialogOpened(false)}
- searches={props.searches}
+ searches={searches}
/>
)}
{ImportSearchesDialog && importFile && (
@@ -564,8 +562,7 @@ function StoredSearches(props: Props) {
open={Boolean(importFile)}
onClose={() => setImportFile(undefined)}
importFile={importFile}
- addSearches={props.addSearches}
- searches={props.searches}
+ searches={searches}
/>
)}
</SidePanel>
@@ -574,7 +571,6 @@ function StoredSearches(props: Props) {
function mapStateToProps(state) {
return {
- searches: getSearches(state),
showUnixHiddenEntries: getShowUnixHiddenEntries(state),
storedSearchesVisible: getStoredSearchesVisible(state),
showBookmarks: getShowBookmarks(state),
@@ -587,7 +583,6 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
- addSearches: SearchActions.addSearches,
setStoredSearchesVisible: SettingsActions.setStoredSearchesVisible,
setShowBookmarks: SettingsActions.setShowBookmarks,
setFileOpenHistory: SettingsActions.setFileOpenHistory,
@@ -604,10 +599,10 @@ const areEqual = (prevProp, nextProp) =>
nextProp.fileOpenHistory === prevProp.fileOpenHistory &&
nextProp.folderOpenHistory === prevProp.folderOpenHistory &&
nextProp.fileEditHistory === prevProp.fileEditHistory &&
- nextProp.indexing === prevProp.indexing &&
- nextProp.currentDirectory === prevProp.currentDirectory &&
- nextProp.indexedEntriesCount === prevProp.indexedEntriesCount &&
- JSON.stringify(nextProp.searches) === JSON.stringify(prevProp.searches);
+ // nextProp.indexing === prevProp.indexing &&
+ nextProp.currentDirectory === prevProp.currentDirectory;
+// nextProp.indexedEntriesCount === prevProp.indexedEntriesCount &&
+// JSON.stringify(nextProp.searches) === JSON.stringify(prevProp.searches);
// JSON.stringify(nextProp.classes) === JSON.stringify(prevProp.classes);
export default connect(
diff --git a/src/renderer/components/dialogs/CreateEditLocationDialog.tsx b/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
index e7c9bd404..13dd5bfde 100644
--- a/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
+++ b/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
@@ -757,6 +757,66 @@ function CreateEditLocationDialog(props: Props) {
</FormGroup>
</AccordionDetails>
</Accordion>
+ {type === locationType.TYPE_CLOUD && (
+ <Accordion>
+ <AccordionSummary
+ data-tid="switchEncryptionTID"
+ expandIcon={<ExpandIcon />}
+ aria-controls="panelEncryption-content"
+ id="panelEncryption-header"
+ >
+ <Typography>{t('core:switchEncryption')}</Typography>
+ </AccordionSummary>
+ <AccordionDetails>
+ <FormControl fullWidth={true}>
+ <TextField
+ margin="dense"
+ name="encryptionKey"
+ type={showEncryptionKey ? 'text' : 'password'}
+ fullWidth={true}
+ inputProps={{ autoCorrect: 'off', autoCapitalize: 'none' }}
+ data-tid="encryptionKeyTID"
+ placeholder={t('s3encryptionKey')}
+ onChange={(event) => setEncryptionKey(event.target.value)}
+ value={encryptionKey}
+ label={t('core:encryptionKey')}
+ InputProps={{
+ endAdornment: (
+ <InputAdornment position="end">
+ <IconButton
+ aria-label="toggle password visibility"
+ onClick={() =>
+ setShowEncryptionKey(!showEncryptionKey)
+ }
+ size="large"
+ >
+ {showEncryptionKey ? (
+ <Visibility />
+ ) : (
+ <VisibilityOff />
+ )}
+ </IconButton>
+ <IconButton
+ aria-label="auto fill password"
+ onClick={() =>
+ setEncryptionKey(
+ CryptoJS.lib.WordArray.random(32)
+ .toString(CryptoJS.enc.Hex)
+ .slice(0, 32),
+ )
+ }
+ size="large"
+ >
+ <PasswordIcon />
+ </IconButton>
+ </InputAdornment>
+ ),
+ }}
+ />
+ </FormControl>
+ </AccordionDetails>
+ </Accordion>
+ )}
<Accordion>
<AccordionSummary
data-tid="switchAdvancedModeTID"
diff --git a/src/renderer/components/menus/SavedSearchesMenu.tsx b/src/renderer/components/menus/SavedSearchesMenu.tsx
index a6cae6958..be92775fe 100644
--- a/src/renderer/components/menus/SavedSearchesMenu.tsx
+++ b/src/renderer/components/menus/SavedSearchesMenu.tsx
@@ -17,15 +17,12 @@
*/
import React from 'react';
-import { useSelector, useDispatch } from 'react-redux';
+import { useSelector } from 'react-redux';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import { getSearches } from '-/reducers/searches';
-import { getShowUnixHiddenEntries } from '-/reducers/settings';
-import { AppDispatch } from '-/reducers/app';
import { useTranslation } from 'react-i18next';
-import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
-import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
+import { useSavedSearchesContext } from '-/hooks/useSavedSearchesContext';
interface Props {
open: boolean;
@@ -36,7 +33,7 @@ interface Props {
function SavedSearchesMenu(props: Props) {
const { open, onClose, anchorEl } = props;
const { t } = useTranslation();
- const { findFromSavedSearch } = useDirectoryContentContext();
+ const { findFromSavedSearch } = useSavedSearchesContext();
const searches = useSelector((state) => getSearches(state));
const menuItems = searches.length ? (
diff --git a/src/renderer/containers/Root.tsx b/src/renderer/containers/Root.tsx
index c97c73e3e..e033ba88c 100644
--- a/src/renderer/containers/Root.tsx
+++ b/src/renderer/containers/Root.tsx
@@ -45,10 +45,11 @@ import { EditedTagLibraryContextProvider } from '-/hooks/EditedTagLibraryContext
import { EditedKanBanMetaContextProvider } from '-/hooks/EditedKanBanMetaContextProvider';
import { PerspectiveActionsContextProvider } from '-/hooks/PerspectiveActionsContextProvider';
import { Pro } from '-/pro';
-import DialogsRoot from '-/containers/DialogsRoot';
import { ExtensionsContextProvider } from '-/hooks/ExtensionsContextProvider';
import { PanelsContextProvider } from '-/hooks/PanelsContextProvider';
import { UserContextProvider } from '-/hooks/UserContextProvider';
+import { SavedSearchesContextProvider } from '-/hooks/SavedSearchesContextProvider';
+import DialogsRoot from '-/containers/DialogsRoot';
type RootType = {
store: Store<{}>;
@@ -90,19 +91,23 @@ export default function Root({ store, persistor }: RootType) {
<ExtensionsContextProvider>
<PanelsContextProvider>
<UserContextProvider>
- <DialogsRoot>
+ <SavedSearchesContextProvider>
{Pro ? (
<Pro.contextProviders.BookmarksContextProvider>
<Pro.contextProviders.HistoryContextProvider>
<Pro.contextProviders.KanBanImportDialogContextProvider>
- <MainPage />
+ <DialogsRoot>
+ <MainPage />
+ </DialogsRoot>
</Pro.contextProviders.KanBanImportDialogContextProvider>
</Pro.contextProviders.HistoryContextProvider>
</Pro.contextProviders.BookmarksContextProvider>
) : (
- <MainPage />
+ <DialogsRoot>
+ <MainPage />
+ </DialogsRoot>
)}
- </DialogsRoot>
+ </SavedSearchesContextProvider>
</UserContextProvider>
</PanelsContextProvider>
</ExtensionsContextProvider>
diff --git a/src/renderer/hooks/CurrentLocationContextProvider.tsx b/src/renderer/hooks/CurrentLocationContextProvider.tsx
index 6acec4b36..87a5b5dab 100644
--- a/src/renderer/hooks/CurrentLocationContextProvider.tsx
+++ b/src/renderer/hooks/CurrentLocationContextProvider.tsx
@@ -40,7 +40,7 @@ import { getPersistTagsInSidecarFile } from '-/reducers/settings';
import AppConfig from '../AppConfig';
import versionMeta from '-/version.json';
import { CommonLocation } from '-/utils/CommonLocation';
-import { getDevicePaths } from '-/services/utils-io';
+import { getDevicePaths, instanceId, toTsLocation } from '-/services/utils-io';
import { TS } from '-/tagspaces.namespace';
type CurrentLocationContextData = {
@@ -63,7 +63,7 @@ type CurrentLocationContextData = {
arrLocations: Array<CommonLocation>,
override?: boolean,
) => void;
- deleteLocation: (location: CommonLocation) => void;
+ deleteLocation: (locationUUID: string) => void;
moveLocationUp: (locationUUID: string) => void;
moveLocationDown: (locationUUID: string) => void;
moveLocation: (locationUUID: string, newIndex: number) => void;
@@ -141,6 +141,8 @@ export const CurrentLocationContextProvider = ({
locationDirectoryContextMenuAnchorEl,
setLocationDirectoryContextMenuAnchorEl,
] = useState<null | HTMLElement>(null);
+ const broadcast = new BroadcastChannel('ts-sync-channel');
+ // Generate a unique ID for the tab
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
@@ -159,6 +161,28 @@ export const CurrentLocationContextProvider = ({
openLocationById(defaultLocationId);
}
}
+ // Listen for messages from other tabs
+ broadcast.onmessage = (event: MessageEvent) => {
+ const action = event.data as TS.BroadcastMessage;
+ if (instanceId !== action.uuid) {
+ if (action.type === 'addLocation') {
+ const location = action.payload as TS.Location;
+ addLocationInt(new CommonLocation(location));
+ } else if (action.type === 'editLocation') {
+ const location = action.payload as TS.Location;
+ skipInitialDirList.current = true; // don't change location dir after reflect
+ editLocationInt(new CommonLocation(location));
+ } else if (action.type === 'deleteLocation') {
+ deleteLocationInt(action.payload);
+ } else if (action.type === 'moveLocationUp') {
+ moveLocationUpInt(action.payload);
+ forceUpdate();
+ } else if (action.type === 'moveLocationDown') {
+ moveLocationDownInt(action.payload);
+ forceUpdate();
+ }
+ }
+ };
}, []);
useEffect(() => {
@@ -248,35 +272,56 @@ export const CurrentLocationContextProvider = ({
isReadOnly: false,
disableIndexing: false,
});
- addLocation(location, false);
+ addLocation(location);
});
}
return true;
})
- .catch((ex) => console.log(ex));
+ .catch((ex) => console.log('Error getDevicePaths:', ex));
}
}
- function addLocation(
+ function sendMessage(type: string, payload?: any) {
+ const message: TS.BroadcastMessage = { uuid: instanceId, type, payload };
+ broadcast.postMessage(message);
+ }
+
+ function addLocation(location: CommonLocation) {
+ addLocationInt(location); //, openAfterCreate, locationPosition);
+ sendMessage('addLocation', toTsLocation(location));
+ }
+
+ function addLocationInt(
location: CommonLocation,
openAfterCreate = true,
locationPosition: number = undefined,
) {
- dispatch(LocationActions.createLocation(location, locationPosition));
allLocations.current = [...allLocations.current, location];
if (openAfterCreate) {
openLocation(location);
}
+ dispatch(LocationActions.createLocation(location, locationPosition));
}
- function deleteLocation(location: CommonLocation) {
- dispatch(LocationActions.deleteLocation(location));
+ function deleteLocation(locationId: string) {
+ deleteLocationInt(locationId);
+ sendMessage('deleteLocation', locationId);
+ }
+
+ function deleteLocationInt(locationId: string) {
allLocations.current = allLocations.current.filter(
- (l) => l.uuid !== location.uuid,
+ (l) => l.uuid !== locationId,
);
+ dispatch(LocationActions.deleteLocation(locationId));
+ forceUpdate();
}
function moveLocationUp(locationUUID) {
+ moveLocationUpInt(locationUUID);
+ sendMessage('moveLocationUp', locationUUID);
+ }
+
+ function moveLocationUpInt(locationUUID) {
const currentIndex = allLocations.current.findIndex(
(l) => l.uuid === locationUUID,
);
@@ -295,11 +340,15 @@ export const CurrentLocationContextProvider = ({
newArray[currentIndex - 1] = temp;
allLocations.current = newArray;
-
dispatch(LocationActions.moveLocationUp(locationUUID));
}
function moveLocationDown(locationUUID) {
+ moveLocationDownInt(locationUUID);
+ sendMessage('moveLocationDown', locationUUID);
+ }
+
+ function moveLocationDownInt(locationUUID) {
const currentIndex = allLocations.current.findIndex(
(l) => l.uuid === locationUUID,
);
@@ -321,7 +370,6 @@ export const CurrentLocationContextProvider = ({
newArray[currentIndex + 1] = temp;
allLocations.current = newArray;
-
dispatch(LocationActions.moveLocationDown(locationUUID));
}
@@ -363,11 +411,11 @@ export const CurrentLocationContextProvider = ({
const locationExist: boolean = allLocations.current.some(
(location) => location.uuid === newLocation.uuid,
);
- const isLast = idx === array.length - 1;
+ //const isLast = idx === array.length - 1;
if (!locationExist) {
- addLocation(newLocation, isLast);
+ addLocation(newLocation);
} else if (override) {
- editLocation(newLocation, isLast);
+ editLocation(newLocation);
}
});
}
@@ -385,12 +433,18 @@ export const CurrentLocationContextProvider = ({
forceUpdate();
}
- function editLocation(location: CommonLocation, openAfterEdit = true) {
- dispatch(LocationActions.changeLocation(location));
+ function editLocation(location: CommonLocation) {
+ editLocationInt(location);
+ sendMessage('editLocation', toTsLocation(location));
+ }
+
+ function editLocationInt(location: CommonLocation, openAfterEdit = false) {
allLocations.current = allLocations.current.map((l) =>
l.uuid === location.uuid ? location : l,
);
- setCurrentLocation(location);
+ currentLocation.current = location.uuid;
+ dispatch(LocationActions.changeLocation(location));
+ forceUpdate();
if (openAfterEdit) {
/*
* check if location uuid is changed
@@ -403,7 +457,6 @@ export const CurrentLocationContextProvider = ({
} else {
openLocation(location);
}
- // dispatch(AppActions.setReadOnlyMode(location.isReadOnly || false));
}
}
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index 6d6dded42..ca61aac5a 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -45,15 +45,11 @@ import {
actions as SettingsActions,
getDefaultPerspective,
getShowUnixHiddenEntries,
- getTagColor,
- getTagTextColor,
} from '-/reducers/settings';
import { enhanceEntry, getUuid } from '@tagspaces/tagspaces-common/utils-io';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
-import { getSearches } from '-/reducers/searches';
-import { getTagColors } from '-/services/taglibrary-utils';
import { Pro } from '-/pro';
import { defaultSettings as defaultGridSettings } from '-/perspectives/grid';
import { defaultSettings as defaultListSettings } from '-/perspectives/list';
@@ -124,7 +120,6 @@ type DirectoryContentContextData = {
appendSearchResults: (entries: TS.FileSystemEntry[]) => void;
enterSearchMode: () => void;
exitSearchMode: () => void;
- findFromSavedSearch: (uuid: string) => void;
getDefaultPerspectiveSettings: (perspective: string) => TS.FolderSettings;
getPerspective: () => TS.PerspectiveType;
getAllPropertiesPromise: (
@@ -176,7 +171,6 @@ export const DirectoryContentContext =
appendSearchResults: () => {},
enterSearchMode: () => {},
exitSearchMode: () => {},
- findFromSavedSearch: () => {},
getDefaultPerspectiveSettings: undefined,
getPerspective: undefined,
getAllPropertiesPromise: undefined,
@@ -219,12 +213,6 @@ export const DirectoryContentContextProvider = ({
//const useGenerateThumbnails = useSelector(getUseGenerateThumbnails);
const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);
const defaultPerspective = useSelector(getDefaultPerspective);
- //const editedEntryPaths = useSelector(getEditedEntryPaths);
- const searches = useSelector(getSearches);
- const defaultBackgroundColor = useSelector(getTagColor);
- const defaultTextColor = useSelector(getTagTextColor);
-
- //const enableWS = useSelector(getEnableWS);
const currentDirectoryEntries = useRef<TS.FileSystemEntry[]>([]);
const searchQuery = useRef<TS.SearchQuery>({});
@@ -283,6 +271,7 @@ export const DirectoryContentContextProvider = ({
currentLocationPath.current = locationPath;
if (!skipInitialDirList) {
if (isLoading.current) {
+ //cancel loading KanBan S3 folders on location-folder change
abort();
}
isLoading.current = true;
@@ -292,7 +281,10 @@ export const DirectoryContentContextProvider = ({
isLoading.current = false;
return success;
})
- .catch((ex) => console.log(ex));
+ .catch((ex) => {
+ isLoading.current = false;
+ console.log('Error openDirectory:', ex);
+ });
}
});
} else {
@@ -1035,42 +1027,6 @@ export const DirectoryContentContextProvider = ({
}
}
- function updateTagColors(tags: TS.Tag[]) {
- return tags.map((tag) => {
- const tagColors = getTagColors(
- tag.title,
- defaultTextColor,
- defaultBackgroundColor,
- );
- return {
- ...tag,
- ...tagColors,
- };
- });
- }
-
- function findFromSavedSearch(uuid: string) {
- const savedSearch = searches.find((search) => search.uuid === uuid);
- if (!savedSearch) {
- return true;
- }
-
- setSearchQuery({
- ...savedSearch,
- ...(savedSearch.tagsAND && {
- tagsAND: updateTagColors(savedSearch.tagsAND),
- }),
- ...(savedSearch.tagsNOT && {
- tagsNOT: updateTagColors(savedSearch.tagsNOT),
- }),
- ...(savedSearch.tagsOR && {
- tagsOR: updateTagColors(savedSearch.tagsOR),
- }),
- showUnixHiddenEntries,
- executeSearch: true,
- });
- }
-
/**
* get full entry properties - with full description
*/
@@ -1441,7 +1397,6 @@ export const DirectoryContentContextProvider = ({
appendSearchResults,
enterSearchMode,
exitSearchMode,
- findFromSavedSearch,
getDefaultPerspectiveSettings,
getAllPropertiesPromise,
loadCurrentDirMeta,
diff --git a/src/renderer/hooks/EditedTagLibraryContextProvider.tsx b/src/renderer/hooks/EditedTagLibraryContextProvider.tsx
index 59d2459ff..53e263314 100644
--- a/src/renderer/hooks/EditedTagLibraryContextProvider.tsx
+++ b/src/renderer/hooks/EditedTagLibraryContextProvider.tsx
@@ -16,18 +16,27 @@
*
*/
-import React, { createContext, useMemo, useReducer, useRef } from 'react';
+import React, {
+ createContext,
+ useEffect,
+ useMemo,
+ useReducer,
+ useRef,
+} from 'react';
import { TS } from '-/tagspaces.namespace';
import { getTagLibrary } from '-/services/taglibrary-utils';
+import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
type EditedTagLibraryContextData = {
tagGroups: TS.TagGroup[];
+ broadcast: BroadcastChannel;
reflectTagLibraryChanged: (tg: TS.TagGroup[]) => void;
};
export const EditedTagLibraryContext =
createContext<EditedTagLibraryContextData>({
tagGroups: undefined,
+ broadcast: undefined,
reflectTagLibraryChanged: undefined,
});
@@ -41,15 +50,37 @@ export const EditedTagLibraryContextProvider = ({
const tagGroups = useRef<TS.TagGroup[]>(getTagLibrary());
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
+ const broadcast = new BroadcastChannel('tag-library-sync');
+ // Generate a unique ID for the tab
+ const instanceId = getUuid();
+
+ useEffect(() => {
+ // Listen for messages from other tabs
+ broadcast.onmessage = (event: MessageEvent) => {
+ const action = event.data as TS.BroadcastMessage;
+ if (instanceId !== action.uuid) {
+ if (action.type === 'tagLibraryChanged') {
+ tagGroups.current = getTagLibrary();
+ forceUpdate();
+ }
+ }
+ };
+ }, []);
function reflectTagLibraryChanged(tg: TS.TagGroup[]) {
tagGroups.current = tg;
+ const message: TS.BroadcastMessage = {
+ uuid: instanceId,
+ type: 'tagLibraryChanged',
+ };
+ broadcast.postMessage(message);
forceUpdate();
}
const context = useMemo(() => {
return {
tagGroups: tagGroups.current,
+ broadcast: broadcast,
reflectTagLibraryChanged,
};
}, [tagGroups.current]);
diff --git a/src/renderer/hooks/SavedSearchesContextProvider.tsx b/src/renderer/hooks/SavedSearchesContextProvider.tsx
new file mode 100644
index 000000000..3da8920cb
--- /dev/null
+++ b/src/renderer/hooks/SavedSearchesContextProvider.tsx
@@ -0,0 +1,204 @@
+/*
+Copyright (c) 2024-present The TagSpaces UG (Haftungsbeschraenkt). All rights reserved.
+*/
+
+import React, {
+ createContext,
+ useEffect,
+ useMemo,
+ useReducer,
+ useRef,
+} from 'react';
+import { TS } from '-/tagspaces.namespace';
+import { instanceId } from '-/services/utils-io';
+import { useSelector } from 'react-redux';
+import { getSearches } from '-/reducers/searches';
+import { getTagColors } from '-/services/taglibrary-utils';
+import {
+ getShowUnixHiddenEntries,
+ getTagColor,
+ getTagTextColor,
+} from '-/reducers/settings';
+import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
+
+type SavedSearchesContextData = {
+ searches: TS.SearchQuery[];
+ addSearch: (newSearch: TS.SearchQuery) => void;
+ editSearch: (newSearch: TS.SearchQuery) => void;
+ addSearches: (newSearches: TS.SearchQuery[]) => void;
+ delAllSearches: () => void;
+ removeSearch: (uuid: string) => void;
+ findFromSavedSearch: (uuid: string) => void;
+};
+
+export const SavedSearchesContext = createContext<SavedSearchesContextData>({
+ searches: undefined,
+ addSearch: undefined,
+ editSearch: undefined,
+ addSearches: undefined,
+ delAllSearches: undefined,
+ removeSearch: undefined,
+ findFromSavedSearch: undefined,
+});
+
+export type SavedSearchesContextProviderProps = {
+ children: React.ReactNode;
+};
+
+export const SavedSearchesContextProvider = ({
+ children,
+}: SavedSearchesContextProviderProps) => {
+ const searchesKey = 'tsSavedSearches';
+ const { setSearchQuery } = useDirectoryContentContext();
+ const reduxSearches = useSelector(getSearches);
+ const defaultBackgroundColor = useSelector(getTagColor);
+ const defaultTextColor = useSelector(getTagTextColor);
+ const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);
+ const searches = useRef<TS.SearchQuery[]>(getAllSearches());
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
+ const broadcast = new BroadcastChannel('searches-sync');
+
+ useEffect(() => {
+ // Listen for messages from other tabs
+ broadcast.onmessage = (event: MessageEvent) => {
+ const action = event.data as TS.BroadcastMessage;
+ if (instanceId !== action.uuid) {
+ if (action.type === 'searchesChanged') {
+ searches.current = getAllSearches();
+ forceUpdate();
+ }
+ }
+ };
+ }, []);
+
+ function sendMessage() {
+ const message: TS.BroadcastMessage = {
+ uuid: instanceId,
+ type: 'searchesChanged',
+ };
+ broadcast.postMessage(message);
+ }
+
+ function getAllSearches(): TS.SearchQuery[] {
+ const item = localStorage.getItem(searchesKey);
+ if (item) {
+ return JSON.parse(item);
+ }
+ if (reduxSearches.length > 0) {
+ //import from redux
+ localStorage.setItem(searchesKey, JSON.stringify(reduxSearches));
+ }
+ return reduxSearches;
+ //return [];
+ }
+
+ function addSearch(newSearch: TS.SearchQuery) {
+ if (searches.current) {
+ searches.current = searches.current.filter(
+ (item) => item.uuid !== newSearch.uuid,
+ );
+ searches.current.unshift(newSearch);
+ } else {
+ searches.current.push(newSearch);
+ }
+
+ localStorage.setItem(searchesKey, JSON.stringify(searches.current));
+ sendMessage();
+ forceUpdate();
+ }
+
+ function addSearches(newSearches: TS.SearchQuery[]) {
+ if (searches.current) {
+ searches.current = searches.current.filter((item) =>
+ newSearches.some((newItem) => newItem.uuid === item.uuid),
+ );
+ searches.current.unshift(...newSearches);
+ } else {
+ searches.current.push(...newSearches);
+ }
+
+ localStorage.setItem(searchesKey, JSON.stringify(searches.current));
+ sendMessage();
+ forceUpdate();
+ }
+
+ function editSearch(newSearch: TS.SearchQuery) {
+ searches.current = searches.current.map((item) =>
+ newSearch.uuid === item.uuid ? newSearch : item,
+ );
+
+ localStorage.setItem(searchesKey, JSON.stringify(searches.current));
+ sendMessage();
+ forceUpdate();
+ }
+
+ function delAllSearches() {
+ localStorage.removeItem(searchesKey);
+ searches.current = [];
+ sendMessage();
+ forceUpdate();
+ }
+
+ function removeSearch(uuid: string) {
+ if (searches.current) {
+ searches.current = searches.current.filter((item) => item.uuid !== uuid);
+ localStorage.setItem(searchesKey, JSON.stringify(searches.current));
+ sendMessage();
+ forceUpdate();
+ }
+ }
+
+ function updateTagColors(tags: TS.Tag[]) {
+ return tags.map((tag) => {
+ const tagColors = getTagColors(
+ tag.title,
+ defaultTextColor,
+ defaultBackgroundColor,
+ );
+ return {
+ ...tag,
+ ...tagColors,
+ };
+ });
+ }
+
+ function findFromSavedSearch(uuid: string) {
+ const savedSearch = searches.current.find((search) => search.uuid === uuid);
+ if (!savedSearch) {
+ return true;
+ }
+
+ setSearchQuery({
+ ...savedSearch,
+ ...(savedSearch.tagsAND && {
+ tagsAND: updateTagColors(savedSearch.tagsAND),
+ }),
+ ...(savedSearch.tagsNOT && {
+ tagsNOT: updateTagColors(savedSearch.tagsNOT),
+ }),
+ ...(savedSearch.tagsOR && {
+ tagsOR: updateTagColors(savedSearch.tagsOR),
+ }),
+ showUnixHiddenEntries,
+ executeSearch: true,
+ });
+ }
+
+ const context = useMemo(() => {
+ return {
+ searches: searches.current,
+ addSearch,
+ addSearches,
+ editSearch,
+ delAllSearches,
+ removeSearch,
+ findFromSavedSearch,
+ };
+ }, [searches.current]);
+
+ return (
+ <SavedSearchesContext.Provider value={context}>
+ {children}
+ </SavedSearchesContext.Provider>
+ );
+};
diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsx
index f34d5def0..b19366202 100644
--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx
+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx
@@ -153,7 +153,8 @@ export const TaggingActionsContextProvider = ({
const { t } = useTranslation();
const { findLocation, currentLocation, persistTagsInSidecarFile } =
useCurrentLocationContext();
- const { tagGroups, reflectTagLibraryChanged } = useEditedTagLibraryContext();
+ const { tagGroups, reflectTagLibraryChanged, broadcast } =
+ useEditedTagLibraryContext();
const {
createLocationTagGroup,
editLocationTagGroup,
@@ -1008,7 +1009,8 @@ export const TaggingActionsContextProvider = ({
}
function saveTagLibrary(tg: TS.TagGroup[]) {
- reflectTagLibraryChanged(setTagLibrary(tg));
+ const tagGroups = setTagLibrary(tg);
+ reflectTagLibraryChanged(tagGroups);
}
function saveTags(tags: TS.Tag[], indexForEditing: number) {
diff --git a/src/renderer/hooks/useSavedSearchesContext.tsx b/src/renderer/hooks/useSavedSearchesContext.tsx
new file mode 100644
index 000000000..df04b0317
--- /dev/null
+++ b/src/renderer/hooks/useSavedSearchesContext.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 { SavedSearchesContext } from '-/hooks/SavedSearchesContextProvider';
+
+export const useSavedSearchesContext = () => useContext(SavedSearchesContext);
diff --git a/src/renderer/reducers/locations.ts b/src/renderer/reducers/locations.ts
index e30094801..9f5860583 100644
--- a/src/renderer/reducers/locations.ts
+++ b/src/renderer/reducers/locations.ts
@@ -17,9 +17,9 @@
*/
import { immutablySwapItems } from '@tagspaces/tagspaces-common/misc';
-import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import { CommonLocation } from '-/utils/CommonLocation';
import { TS } from '-/tagspaces.namespace';
+import { toTsLocation } from '-/services/utils-io';
export const types = {
ADD_LOCATION: 'APP/ADD_LOCATION',
@@ -32,53 +32,6 @@ export const types = {
export const initialState = [];
-function toTsLocation(location: CommonLocation): TS.S3Location {
- return {
- uuid: location.uuid || getUuid(),
- name: location.name,
- type: location.type,
- ...(location.authType && { authType: location.authType }),
- ...(location.username && { username: location.username }),
- ...(location.password && { password: location.password }),
- ...(location.path && { path: location.path }),
- ...(location.isDefault && { isDefault: location.isDefault }),
- ...(location.isReadOnly && { isReadOnly: location.isReadOnly }),
- ...(location.isNotEditable && { isNotEditable: location.isNotEditable }),
- ...(location.watchForChanges && {
- watchForChanges: location.watchForChanges,
- }),
- ...(location.disableIndexing && {
- disableIndexing: location.disableIndexing,
- }),
- ...(location.disableThumbnailGeneration && {
- disableThumbnailGeneration: location.disableThumbnailGeneration,
- }),
- ...(location.fullTextIndex && { fullTextIndex: location.fullTextIndex }),
- ...(location.maxIndexAge && { maxIndexAge: location.maxIndexAge }),
- ...(location.maxLoops && { maxLoops: location.maxLoops }),
- ...(location.persistTagsInSidecarFile && {
- persistTagsInSidecarFile: location.persistTagsInSidecarFile,
- }),
- ...(location.ignorePatternPaths && {
- ignorePatternPaths: location.ignorePatternPaths,
- }),
- ...(location.autoOpenedFilename && {
- autoOpenedFilename: location.autoOpenedFilename,
- }),
- ...(location.creationDate && { creationDate: location.creationDate }),
- ...(location.lastEditedDate && { lastEditedDate: location.lastEditedDate }),
- ...(location.accessKeyId && { accessKeyId: location.accessKeyId }),
- ...(location.secretAccessKey && {
- secretAccessKey: location.secretAccessKey,
- }),
- ...(location.sessionToken && { sessionToken: location.sessionToken }),
- ...(location.bucketName && { bucketName: location.bucketName }),
- ...(location.region && { region: location.region }),
- ...(location.endpointURL && { endpointURL: location.endpointURL }),
- ...(location.encryptionKey && { encryptionKey: location.encryptionKey }),
- };
-}
-
export default (state: Array<TS.S3Location> = initialState, action: any) => {
switch (action.type) {
case types.ADD_LOCATION: {
@@ -171,7 +124,7 @@ export default (state: Array<TS.S3Location> = initialState, action: any) => {
case types.REMOVE_LOCATION: {
let indexForRemoving = -1;
state.forEach((location, index) => {
- if (location.uuid === action.location.uuid) {
+ if (location.uuid === action.locationId) {
indexForRemoving = index;
}
});
@@ -212,9 +165,9 @@ export const actions = {
type: types.EDIT_LOCATION,
location,
}),
- deleteLocation: (location: CommonLocation) => ({
+ deleteLocation: (locationId: string) => ({
type: types.REMOVE_LOCATION,
- location,
+ locationId,
}),
};
diff --git a/src/renderer/reducers/searches.ts b/src/renderer/reducers/searches.ts
index b2aaf5139..40ac0da6d 100644
--- a/src/renderer/reducers/searches.ts
+++ b/src/renderer/reducers/searches.ts
@@ -99,7 +99,7 @@ export default (state: Array<TS.SearchQuery> = initialState, action: any) => {
}
};
-export const actions = {
+/*export const actions = {
addSearch: (search: TS.SearchQuery) => ({
type: types.ADD_SEARCH,
search,
@@ -132,11 +132,7 @@ export const actions = {
type: types.REMOVE_SEARCH,
uuid,
}),
- /* getSearch: (uuid: string) => (
- dispatch: (actions: Object) => void,
- getState: () => any
- ) => getState().searches.find(search => search.uuid === uuid) */
-};
+};*/
// Selectors
export const getSearches = (state: any): Array<TS.SearchQuery> =>
diff --git a/src/renderer/reducers/taglibrary-default.ts b/src/renderer/reducers/taglibrary-default.ts
index 4926f8a61..dde58ab13 100644
--- a/src/renderer/reducers/taglibrary-default.ts
+++ b/src/renderer/reducers/taglibrary-default.ts
@@ -17,6 +17,7 @@
*/
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
+import { TS } from '-/tagspaces.namespace';
export default [
{
@@ -131,4 +132,4 @@ export default [
},
],
},
-] as any;
+] as TS.TagGroup[];
diff --git a/src/renderer/services/platform-facade.ts b/src/renderer/services/platform-facade.ts
deleted file mode 100644
index a23d18aeb..000000000
--- a/src/renderer/services/platform-facade.ts
+++ /dev/null
@@ -1,925 +0,0 @@
-/**
- * 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 * as cordovaIO from '@tagspaces/tagspaces-common-cordova';
-import AppConfig from '-/AppConfig';
-import { TS } from '-/tagspaces.namespace';
-import { Pro } from '-/pro';
-import { openUrlForWeb } from '-/services/utils-io';
-
-let objectStoreAPI, webDavAPI;
-const urlCache = {};
-
-export default class PlatformFacade {
- static getPath(param) {
- if (typeof param === 'object' && param !== null) {
- return param.path;
- } else if (param) {
- return param;
- }
- return '';
- }
-
- static enableObjectStoreSupport = (objectStoreConfig: any): Promise<any> => {
- // DisableWebdavSupport
- webDavAPI = undefined;
- return new Promise((resolve, reject) => {
- if (
- objectStoreAPI !== undefined &&
- objectStoreAPI.config().bucketName === objectStoreConfig.bucketName &&
- objectStoreAPI.config().secretAccessKey ===
- objectStoreConfig.secretAccessKey &&
- objectStoreAPI.config().region === objectStoreConfig.region &&
- objectStoreAPI.config().endpointURL === objectStoreConfig.endpointURL &&
- objectStoreAPI.config().accessKeyId === objectStoreConfig.accessKeyId
- ) {
- resolve(true);
- } else {
- objectStoreAPI = require('@tagspaces/tagspaces-common-aws/io-objectstore');
- objectStoreAPI.configure(objectStoreConfig);
- resolve(true);
- }
- });
- };
-
- static disableObjectStoreSupport = (): void => (objectStoreAPI = undefined);
-
- static enableWebdavSupport = (webDavConfig: any): void => {
- objectStoreAPI = undefined;
- if (
- webDavAPI === undefined ||
- webDavAPI.username !== webDavConfig.username ||
- webDavAPI.password !== webDavConfig.password ||
- webDavAPI.port !== webDavConfig.port
- ) {
- //webDavAPI = require("@tagspaces/tagspaces-common-webdav/io-webdav");
- //webDavAPI.configure(webDavConfig);
- }
- };
-
- static disableWebdavSupport = (): void => (webDavAPI = undefined);
-
- static haveObjectStoreSupport = (): boolean => objectStoreAPI !== undefined;
-
- static haveWebDavSupport = (): boolean => webDavAPI !== undefined;
-
- static isMinio = (): boolean =>
- objectStoreAPI !== undefined && objectStoreAPI.config().endpointURL;
-
- static getDirSeparator = (): string => {
- // TODO rethink usage for S3 on Win
- return objectStoreAPI !== undefined || webDavAPI !== undefined
- ? '/'
- : AppConfig.dirSeparator;
- };
-
- static setLanguage = (language: string): void => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('set-language', language);
- }
- };
-
- static setZoomFactorElectron = (zoomLevel) => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('setZoomFactor', zoomLevel);
- }
- };
-
- static setGlobalShortcuts = (globalShortcutsEnabled) => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage(
- 'global-shortcuts-enabled',
- globalShortcutsEnabled,
- );
- }
- };
-
- static showMainWindow = (): void => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('show-main-window');
- }
- };
-
- static createNewInstance = (url?: string): void => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('create-new-window', url);
- } else {
- if (url) {
- window.open(url, '_blank');
- } else {
- window.open('index.html', '_blank');
- }
- }
- };
-
- static quitApp = (): void => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('quitApp');
- } /!*else {
- platformQuitApp();
- }*!/
- };
-
- /!*static watchDirectory = (dirPath: string, listener): void =>
- platformWatchDirectory(dirPath, listener);*!/
-
- static focusWindow = (): void => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('focus-window');
- }
- };
-
- static getDevicePaths = (): Promise<any> => {
- if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke('getDevicePaths');
- } else if (AppConfig.isCordova) {
- return cordovaIO.getDevicePaths();
- } else {
- console.log('getDevicePaths not supported');
- return Promise.resolve(undefined);
- }
- };
-
- /!**
- * ObjectStore and webDav only
- * Function to generate or retrieve cached URL with expiration date
- * @param path
- * @param expirationInSeconds
- *!/
- static getURLforPath = (
- path: string,
- expirationInSeconds: number = 900,
- ): string => {
- const currentTime = new Date().getTime();
-
- // Check if URL is cached and not expired
- if (urlCache[path] && urlCache[path].expirationTime > currentTime) {
- return urlCache[path].url;
- } else {
- // Generate new URL and cache it with expiration time
- return this.generateURLforPath(path, expirationInSeconds);
- }
- };
-
- static generateURLforPath = (path, expirationInSeconds) => {
- let url;
- if (objectStoreAPI) {
- const param = {
- path,
- bucketName: objectStoreAPI.config().bucketName,
- };
- url = objectStoreAPI.getURLforPath(param, expirationInSeconds);
- } else if (webDavAPI) {
- url = webDavAPI.getURLforPath(path);
- }
- if (url) {
- urlCache[path] = {
- url: url,
- expirationTime: new Date().getTime() + expirationInSeconds * 1000,
- };
- }
- return url;
- };
-
- /!**
- * needs to run in init this function always return false first time
- *!/
- static isWorkerAvailable = (): Promise<boolean> => {
- if (
- AppConfig.isElectron &&
- objectStoreAPI === undefined &&
- webDavAPI === undefined
- ) {
- return window.electronIO.ipcRenderer.invoke('isWorkerAvailable');
- }
- return Promise.resolve(false);
- };
-
- static readMacOSTags = (filename: string): Promise<TS.Tag[]> => {
- if (
- AppConfig.isElectron &&
- objectStoreAPI === undefined &&
- webDavAPI === undefined
- ) {
- return window.electronIO.ipcRenderer.invoke('readMacOSTags', filename);
- }
- return Promise.resolve(undefined);
- };
-
- static watchFolder = (locationPath, depth) => {
- if (
- AppConfig.isElectron &&
- Pro &&
- objectStoreAPI === undefined &&
- webDavAPI === undefined
- ) {
- window.electronIO.ipcRenderer.sendMessage(
- 'watchFolder',
- locationPath,
- depth,
- );
- }
- };
-
- /!*static tiffJs = () => {
- return platformTiffJs();
- };*!/
-
- static createDirectoryIndexInWorker = (
- directoryPath: string,
- extractText: boolean,
- ignorePatterns: Array<string>,
- ): Promise<any> => {
- if (
- AppConfig.isElectron &&
- objectStoreAPI === undefined &&
- webDavAPI === undefined
- ) {
- const payload = JSON.stringify({
- directoryPath,
- extractText,
- ignorePatterns,
- });
- return window.electronIO.ipcRenderer.invoke(
- 'postRequest',
- payload,
- '/indexer',
- );
- }
- return Promise.reject(
- new Error('createDirectoryIndexInWorker not Electron!'),
- );
- };
-
- static createThumbnailsInWorker = (
- tmbGenerationList: Array<string>,
- ): Promise<any> => {
- if (
- AppConfig.isElectron &&
- objectStoreAPI === undefined &&
- webDavAPI === undefined
- ) {
- const payload = JSON.stringify(tmbGenerationList);
- return window.electronIO.ipcRenderer.invoke(
- 'postRequest',
- payload,
- '/thumb-gen',
- );
- }
- return Promise.reject(new Error('createThumbnailsInWorker not Electron!'));
- };
-
- /!**
- * Promise === undefined on error
- * @param path
- * @param mode = ['extractTextContent', 'extractThumbPath']
- * @param ignorePatterns
- * @param resultsLimit
- *!/
- static listDirectoryPromise = (
- path: string,
- mode = ['extractThumbPath'],
- ignorePatterns: Array<string> = [],
- resultsLimit: any = {},
- ): Promise<Array<any>> => {
- if (objectStoreAPI) {
- const param = {
- path,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.listDirectoryPromise(
- param,
- mode,
- ignorePatterns,
- resultsLimit,
- );
- } else if (webDavAPI) {
- return webDavAPI.listDirectoryPromise(path, mode, ignorePatterns);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'listDirectoryPromise',
- path,
- mode,
- ignorePatterns,
- resultsLimit,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.listDirectoryPromise(path, mode, ignorePatterns);
- }
-
- return Promise.reject(new Error('listDirectoryPromise not implemented!'));
- };
-
- static listMetaDirectoryPromise = (path: string): Promise<Array<any>> => {
- if (objectStoreAPI) {
- const param = {
- path,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.listMetaDirectoryPromise(param);
- } else if (webDavAPI) {
- return webDavAPI.listMetaDirectoryPromise(path);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'listMetaDirectoryPromise',
- path,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.listMetaDirectoryPromise(path);
- }
-
- return Promise.reject(
- new Error('listMetaDirectoryPromise not implemented!'),
- );
- };
-
- static listObjectStoreDir = (
- param: Object,
- mode = ['extractThumbPath'],
- ignorePatterns: Array<string> = [],
- ): Promise<Array<any>> => {
- if (objectStoreAPI) {
- return objectStoreAPI.listDirectoryPromise(
- { ...param, bucketName: objectStoreAPI.config().bucketName },
- mode,
- ignorePatterns,
- );
- } else {
- return Promise.reject(
- new Error('platformListObjectStoreDir: no objectStoreAPI'),
- );
- }
- };
-
- static getPropertiesPromise = (path: string): Promise<any> => {
- if (objectStoreAPI) {
- const param = {
- path,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.getPropertiesPromise(param);
- } else if (webDavAPI) {
- return webDavAPI.getPropertiesPromise(path);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke('getPropertiesPromise', path);
- } else if (AppConfig.isCordova) {
- return cordovaIO.getPropertiesPromise(path);
- }
- return Promise.reject(new Error('getPropertiesPromise: not implemented'));
- };
-
- static checkDirExist = (dir: string): Promise<boolean> => {
- if (objectStoreAPI) {
- return objectStoreAPI
- .getPropertiesPromise({
- path: dir,
- bucketName: objectStoreAPI.config().bucketName,
- })
- .then((stats) => stats && !stats.isFile);
- } else if (webDavAPI) {
- return webDavAPI
- .getPropertiesPromise(dir)
- .then((stats) => stats && !stats.isFile);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke('checkDirExist', dir);
- } else if (AppConfig.isCordova) {
- // In cordova this check is too expensive for dirs like /.ts
- return cordovaIO.checkDirExist(dir);
- }
- return Promise.reject(new Error('checkDirExist: not implemented'));
- };
-
- static checkFileExist = (file: string): Promise<boolean> => {
- if (file === undefined) {
- return Promise.resolve(false);
- }
- if (objectStoreAPI) {
- return objectStoreAPI.isFileExist({
- path: file,
- bucketName: objectStoreAPI.config().bucketName,
- });
- //.then((stats) => stats && stats.isFile);
- } else if (webDavAPI) {
- return webDavAPI
- .getPropertiesPromise(file)
- .then((stats) => stats && stats.isFile);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke('checkFileExist', file);
- } else if (AppConfig.isCordova) {
- return cordovaIO.checkFileExist(file);
- }
-
- return Promise.reject(new Error('checkFileExist: not implemented'));
- };
-
- static createDirectoryPromise = (dirPath: string): Promise<any> => {
- if (objectStoreAPI) {
- const param = {
- path: dirPath,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.createDirectoryPromise(param);
- } else if (webDavAPI) {
- return webDavAPI.createDirectoryPromise(dirPath);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'createDirectoryPromise',
- dirPath,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.createDirectoryPromise(dirPath);
- }
- return Promise.reject(new Error('createDirectoryPromise: not implemented'));
- };
-
- /!**
- * @param sourceFilePath
- * @param targetFilePath - if exist overwrite it
- *!/
- static copyFilePromiseOverwrite = (
- sourceFilePath: string,
- targetFilePath: string,
- ): Promise<any> => {
- if (objectStoreAPI) {
- const param = {
- path: sourceFilePath,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.copyFilePromise(param, targetFilePath);
- } else if (webDavAPI) {
- return webDavAPI.copyFilePromise(sourceFilePath, targetFilePath);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'copyFilePromiseOverwrite',
- sourceFilePath,
- targetFilePath,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.copyFilePromise(sourceFilePath, targetFilePath);
- }
- return Promise.reject(new Error('createDirectoryPromise: not implemented'));
- };
-
- static renameFilePromise = (
- filePath: string,
- newFilePath: string,
- onProgress = undefined,
- ): Promise<any> => {
- if (objectStoreAPI) {
- const param = {
- path: filePath,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.renameFilePromise(param, newFilePath, onProgress);
- // .then(result => result);
- } else if (webDavAPI) {
- return webDavAPI.renameFilePromise(filePath, newFilePath, onProgress);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'renameFilePromise',
- filePath,
- newFilePath,
- onProgress !== undefined,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.renameFilePromise(filePath, newFilePath, onProgress);
- }
- return Promise.reject(new Error('renameFilePromise: not implemented'));
- };
-
- static renameDirectoryPromise = (
- dirPath: string,
- newDirName: string,
- ): Promise<any> => {
- if (objectStoreAPI) {
- const param = {
- path: dirPath,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.renameDirectoryPromise(param, newDirName);
- } else if (webDavAPI) {
- return webDavAPI.renameDirectoryPromise(dirPath, newDirName);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'renameDirectoryPromise',
- dirPath,
- newDirName,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.renameDirectoryPromise(dirPath, newDirName);
- }
- return Promise.reject(new Error('renameDirectoryPromise: not implemented'));
- };
-
- static uploadAbort = (path?: string): Promise<any> => {
- if (AppConfig.isElectron && !objectStoreAPI && !webDavAPI) {
- return window.electronIO.ipcRenderer.invoke('uploadAbort', path);
- }
- return Promise.resolve(false);
- };
-
- static copyDirectoryPromise = (
- param: any,
- newDirPath: string,
- onProgress = undefined,
- ): Promise<any> => {
- if (objectStoreAPI) {
- const params = {
- ...param,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.copyDirectoryPromise(
- params,
- newDirPath,
- onProgress,
- );
- } else if (webDavAPI) {
- return webDavAPI.copyDirectoryPromise(param, newDirPath, onProgress);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'copyDirectoryPromise',
- param,
- newDirPath,
- onProgress !== undefined,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.copyDirectoryPromise(param, newDirPath, onProgress);
- }
- return Promise.reject(new Error('copyDirectoryPromise: not implemented'));
- };
-
- static moveDirectoryPromise = (
- param: any,
- newDirPath: string,
- onProgress = undefined,
- ): Promise<any> => {
- if (objectStoreAPI) {
- return objectStoreAPI.moveDirectoryPromise(
- {
- ...param,
- bucketName: objectStoreAPI.config().bucketName,
- },
- newDirPath,
- onProgress,
- );
- } else if (webDavAPI) {
- return webDavAPI.moveDirectoryPromise(param, newDirPath, onProgress);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'moveDirectoryPromise',
- param,
- newDirPath,
- onProgress !== undefined,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.moveDirectoryPromise(param, newDirPath, onProgress);
- }
- return Promise.reject(new Error('moveDirectoryPromise: not implemented'));
- };
-
- static loadTextFilePromise = (
- param: any,
- isPreview?: boolean,
- ): Promise<string> => {
- let filePath = this.getPath(param);
- try {
- filePath = decodeURIComponent(filePath);
- } catch (ex) {}
- if (objectStoreAPI) {
- return objectStoreAPI.loadTextFilePromise(
- {
- path: filePath,
- bucketName: objectStoreAPI.config().bucketName,
- },
- isPreview,
- );
- } else if (webDavAPI) {
- return webDavAPI.loadTextFilePromise(filePath, isPreview);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'loadTextFilePromise',
- filePath,
- isPreview,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.loadTextFilePromise(filePath, isPreview);
- }
- return Promise.reject(new Error('loadTextFilePromise: not implemented'));
- };
-
- static getFileContentPromise = (
- filePath: string,
- type?: string,
- ): Promise<any> => {
- if (objectStoreAPI) {
- const param = {
- path: filePath,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.getFileContentPromise(param, type);
- } else if (webDavAPI) {
- return webDavAPI.getFileContentPromise(filePath, type);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'getFileContentPromise',
- filePath,
- type,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.getFileContentPromise(filePath, type);
- }
- return Promise.reject(new Error('getFileContentPromise: not implemented'));
- };
-
- static getLocalFileContentPromise = (
- filePath: string,
- type?: string,
- ): Promise<any> => {
- return window.electronIO.ipcRenderer.invoke(
- 'getFileContentPromise',
- filePath,
- type,
- );
- };
-
- static saveFilePromise = (
- param: any,
- content: any,
- overwrite: boolean,
- ): Promise<any> => {
- if (objectStoreAPI) {
- return objectStoreAPI.saveFilePromise(
- {
- ...param,
- bucketName: objectStoreAPI.config().bucketName,
- },
- content,
- overwrite,
- );
- } else if (webDavAPI) {
- return webDavAPI.saveFilePromise(param, content, overwrite);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'saveFilePromise',
- param,
- content,
- overwrite,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.saveFilePromise(param, content, overwrite);
- }
- return Promise.reject(new Error('saveFilePromise: not implemented'));
- };
-
- static saveTextFilePromise = (
- param: any,
- content: string,
- overwrite: boolean,
- ): Promise<any> => {
- if (objectStoreAPI) {
- return objectStoreAPI.saveTextFilePromise(
- {
- ...param,
- bucketName: objectStoreAPI.config().bucketName,
- },
- content,
- overwrite,
- );
- } else if (webDavAPI) {
- return webDavAPI.saveTextFilePromise(param, content, overwrite);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'saveTextFilePromise',
- param,
- content,
- overwrite,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.saveTextFilePromise(param, content, overwrite);
- }
- return Promise.reject(new Error('saveTextFilePromise: not implemented'));
- };
-
- static saveBinaryFilePromise = (
- param: any,
- content: any,
- overwrite: boolean,
- onUploadProgress?: (
- progress: any, // ManagedUpload.Progress,
- response: any, // AWS.Response<AWS.S3.PutObjectOutput, AWS.AWSError>
- ) => void,
- ): Promise<TS.FileSystemEntry> => {
- if (objectStoreAPI) {
- return objectStoreAPI.saveBinaryFilePromise(
- {
- ...param,
- bucketName: objectStoreAPI.config().bucketName,
- },
- content,
- overwrite,
- onUploadProgress,
- );
- } else if (webDavAPI) {
- return webDavAPI.saveBinaryFilePromise(
- param,
- content,
- overwrite,
- onUploadProgress,
- );
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'saveBinaryFilePromise',
- param,
- content,
- overwrite,
- !!onUploadProgress,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO
- .saveBinaryFilePromise(param, content, overwrite)
- .then((succeeded) => {
- if (succeeded && onUploadProgress) {
- onUploadProgress(
- { key: param.path, loaded: 1, total: 1 },
- undefined,
- );
- }
- return succeeded;
- });
- }
- return Promise.reject(new Error('saveBinaryFilePromise: not implemented'));
- };
-
- static deleteFilePromise = (
- path: string,
- useTrash?: boolean,
- ): Promise<any> => {
- if (objectStoreAPI) {
- const param = {
- path,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.deleteFilePromise(param);
- } else if (webDavAPI) {
- return webDavAPI.deleteFilePromise(path);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'deleteFilePromise',
- path,
- useTrash,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.deleteFilePromise(path);
- }
- return Promise.reject(new Error('deleteFilePromise: not implemented'));
- };
-
- static deleteDirectoryPromise = (
- path: string,
- useTrash?: boolean,
- ): Promise<any> => {
- if (objectStoreAPI) {
- const param = {
- path,
- bucketName: objectStoreAPI.config().bucketName,
- };
- return objectStoreAPI.deleteDirectoryPromise(param);
- } else if (webDavAPI) {
- return webDavAPI.deleteDirectoryPromise(path);
- } else if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'deleteDirectoryPromise',
- path,
- useTrash,
- );
- } else if (AppConfig.isCordova) {
- return cordovaIO.deleteDirectoryPromise(path);
- }
- return Promise.reject(new Error('deleteDirectoryPromise: not implemented'));
- };
-
- static openDirectory = (dirPath: string): void => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('openDirectory', dirPath);
- } else {
- console.error('Is supported only in Electron');
- }
- };
-
- static openFile = (
- filePath: string,
- warningOpeningFilesExternally: boolean,
- ): void => {
- if (
- !warningOpeningFilesExternally ||
- // eslint-disable-next-line no-restricted-globals
- confirm(
- 'Do you really want to open "' +
- filePath +
- '"? Execution of some files can be potentially dangerous!',
- )
- ) {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('openFile', filePath);
- } else {
- console.error('Is supported only in Electron');
- }
- }
- };
-
- static openUrl = (url: string): void => {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('openUrl', url);
- } else {
- // web or cordova
- openUrlForWeb(url);
- }
- };
-
- static selectDirectoryDialog = (): Promise<any> => {
- if (AppConfig.isElectron && !objectStoreAPI && !webDavAPI) {
- return window.electronIO.ipcRenderer.invoke('selectDirectoryDialog');
- } else if (AppConfig.isCordova) {
- return cordovaIO.selectDirectoryDialog();
- }
- return Promise.reject(new Error('selectDirectoryDialog: not implemented'));
- };
-
- /!**
- * cordova only
- * @param files
- *!/
- static shareFiles = (files: Array<string>): void => {
- if (AppConfig.isCordova) {
- cordovaIO.shareFiles(files);
- } else {
- console.log('shareFiles is implemented in Cordova only.');
- }
- };
-
- /!**
- * Load extensions is supported only on Electron
- *!/
- static loadExtensions() {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('load-extensions');
- }
- }
-
- static removeExtension(extensionId: string) {
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('removeExtension', extensionId);
- } else {
- console.error('remove extensions is supported only on Electron.');
- }
- }
-
- static getUserDataDir(): Promise<string> {
- if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke('getUserDataDir');
- } else {
- return Promise.reject('getUserDataDir is supported only on Electron.');
- }
- }
-
- static unZip(filePath, targetPath): Promise<string> {
- if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke(
- 'unZip',
- filePath,
- targetPath,
- );
- } else {
- console.log('UnZip is supported only on Electron.');
- }
- }
-
- static getDirProperties(path): Promise<TS.DirProp> {
- if (AppConfig.isElectron) {
- return window.electronIO.ipcRenderer.invoke('getDirProperties', path);
- } else {
- return Promise.reject(
- new Error(
- 'platformDirProperties is supported on Electron local storage.',
- ),
- );
- }
- }
-}
-*/
diff --git a/src/renderer/services/taglibrary-utils.ts b/src/renderer/services/taglibrary-utils.ts
index f1be13419..05c96319a 100644
--- a/src/renderer/services/taglibrary-utils.ts
+++ b/src/renderer/services/taglibrary-utils.ts
@@ -25,6 +25,7 @@ export function setTagLibrary(
): Array<TS.TagGroup> {
if (tagGroups && tagGroups.length > 0) {
localStorage.setItem(tagLibraryKey, JSON.stringify(tagGroups));
+ //broadcast.postMessage({ type: 'tagLibraryChanged' });
}
return tagGroups;
}
diff --git a/src/renderer/services/utils-io.ts b/src/renderer/services/utils-io.ts
index 7586401f8..cb3c017ca 100644
--- a/src/renderer/services/utils-io.ts
+++ b/src/renderer/services/utils-io.ts
@@ -29,6 +29,9 @@ import versionMeta from '../version.json';
import { TS } from '-/tagspaces.namespace';
import { supportedFileTypes } from '-/extension-config';
import removeMd from 'remove-markdown';
+import { CommonLocation } from '-/utils/CommonLocation';
+
+export const instanceId = getUuid();
export function getAllTags(entry: TS.FileSystemEntry): Array<TS.Tag> {
const tags = [];
@@ -1110,3 +1113,50 @@ export function getMimeType(extension: string): string | undefined {
};
return mimeTypes[extension.toLowerCase()];
}
+
+export function toTsLocation(location: CommonLocation): TS.S3Location {
+ return {
+ uuid: location.uuid || getUuid(),
+ name: location.name,
+ type: location.type,
+ ...(location.authType && { authType: location.authType }),
+ ...(location.username && { username: location.username }),
+ ...(location.password && { password: location.password }),
+ ...(location.path && { path: location.path }),
+ ...(location.isDefault && { isDefault: location.isDefault }),
+ ...(location.isReadOnly && { isReadOnly: location.isReadOnly }),
+ ...(location.isNotEditable && { isNotEditable: location.isNotEditable }),
+ ...(location.watchForChanges && {
+ watchForChanges: location.watchForChanges,
+ }),
+ ...(location.disableIndexing && {
+ disableIndexing: location.disableIndexing,
+ }),
+ ...(location.disableThumbnailGeneration && {
+ disableThumbnailGeneration: location.disableThumbnailGeneration,
+ }),
+ ...(location.fullTextIndex && { fullTextIndex: location.fullTextIndex }),
+ ...(location.maxIndexAge && { maxIndexAge: location.maxIndexAge }),
+ ...(location.maxLoops && { maxLoops: location.maxLoops }),
+ ...(location.persistTagsInSidecarFile && {
+ persistTagsInSidecarFile: location.persistTagsInSidecarFile,
+ }),
+ ...(location.ignorePatternPaths && {
+ ignorePatternPaths: location.ignorePatternPaths,
+ }),
+ ...(location.autoOpenedFilename && {
+ autoOpenedFilename: location.autoOpenedFilename,
+ }),
+ ...(location.creationDate && { creationDate: location.creationDate }),
+ ...(location.lastEditedDate && { lastEditedDate: location.lastEditedDate }),
+ ...(location.accessKeyId && { accessKeyId: location.accessKeyId }),
+ ...(location.secretAccessKey && {
+ secretAccessKey: location.secretAccessKey,
+ }),
+ ...(location.sessionToken && { sessionToken: location.sessionToken }),
+ ...(location.bucketName && { bucketName: location.bucketName }),
+ ...(location.region && { region: location.region }),
+ ...(location.endpointURL && { endpointURL: location.endpointURL }),
+ ...(location.encryptionKey && { encryptionKey: location.encryptionKey }),
+ };
+}
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index cb1cb3e0e..67543abfc 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -226,6 +226,13 @@ export namespace TS {
focused?: boolean; // TODO make it mandatory once support for multiple files is added
}
+ interface BroadcastMessage {
+ // unique ID for the tab instance
+ uuid: string;
+ type: string;
+ payload?: any;
+ }
+
interface CustomOrder {
folders?: Array<OrderVisibilitySettings>;
files?: Array<OrderVisibilitySettings>;