TagSpaces is an offline, open source, document manager with tagging support
createThumbnailsInWorker is called twice on change location (#1479)
Stanimir89a9f3506583
diff --git a/app/components/DirectoryTreeView.tsx b/app/components/DirectoryTreeView.tsxindex f7ea4ef6b..a64ecc3c2 100644--- a/app/components/DirectoryTreeView.tsx+++ b/app/components/DirectoryTreeView.tsx@@ -29,7 +29,7 @@ import { locationType } from '-/utils/misc';interface Props {classes: any;- loadDirectoryContent: (path: string) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;location: TS.Location;data?: any;isReadOnlyMode?: boolean;@@ -64,7 +64,7 @@ const DirectoryTreeView = forwardRef(PlatformIO.enableObjectStoreSupport(location).then(() => {loadSubDirectories(location, 1);- props.loadDirectoryContent(getLocationPath(location));+ props.loadDirectoryContent(getLocationPath(location), true);}).catch(error => {console.log('enableObjectStoreSupport', error);@@ -72,7 +72,7 @@ const DirectoryTreeView = forwardRef(} else if (location.type === locationType.TYPE_LOCAL) {PlatformIO.disableObjectStoreSupport();loadSubDirectories(location, 1);- props.loadDirectoryContent(getLocationPath(location));+ props.loadDirectoryContent(getLocationPath(location), true);}}},@@ -166,7 +166,7 @@ const DirectoryTreeView = forwardRef(.then(() => {loadSubDirectories(subDir, 1);props.changeLocation(subDir);- props.loadDirectoryContent(subDir.path);+ props.loadDirectoryContent(subDir.path, true);}).catch(error => {console.log('enableObjectStoreSupport', error);@@ -175,7 +175,7 @@ const DirectoryTreeView = forwardRef(PlatformIO.disableObjectStoreSupport();loadSubDirectories(subDir, 1);props.changeLocation(subDir);- props.loadDirectoryContent(subDir.path);+ props.loadDirectoryContent(subDir.path, true);}};diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex 72b56fb8a..a380d60a7 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -217,7 +217,7 @@ interface Props {showInFileManager: () => void;openFsEntry: (fsEntry: TS.FileSystemEntry) => void;reflectCreateEntry: (path: string, isFile: boolean) => void;- loadDirectoryContent: (path: string) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;loadParentDirectoryContent: () => void;setSelectedEntries: (selectedEntries: Array<Object>) => void;isReadOnlyMode: boolean;@@ -466,7 +466,7 @@ const FolderContainer = (props: Props) => {pathParts.map(pathPart => (<Buttonkey={pathPart}- onClick={() => loadDirectoryContent(pathPart)}+ onClick={() => loadDirectoryContent(pathPart, false)}title={'Navigate to: ' + pathPart}style={{paddingLeft: 3,diff --git a/app/components/LocationView.tsx b/app/components/LocationView.tsxindex 75a7011d1..b057a6551 100644--- a/app/components/LocationView.tsx+++ b/app/components/LocationView.tsx@@ -57,7 +57,7 @@ interface Props {location: TS.Location;currentLocationId: string;openLocation: (location: TS.Location) => void;- loadDirectoryContent: (path: string) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;setSelectedEntries: (selectedEntries: Array<Object>) => void;hideDrawer: () => void;isReadOnlyMode: boolean;@@ -98,7 +98,7 @@ const LocationView = (props: Props) => {directoryTreeRef.current.changeLocation(location);if (location.uuid === props.currentLocationId) {// the same location click- props.loadDirectoryContent(getLocationPath(location));+ props.loadDirectoryContent(getLocationPath(location), false);} else {// this.directoryTreeRef[location.uuid].loadSubDir(location, 1);props.setSelectedEntries([]);diff --git a/app/components/Search.tsx b/app/components/Search.tsxindex b534dc11a..ec9f88d54 100644--- a/app/components/Search.tsx+++ b/app/components/Search.tsx@@ -88,7 +88,7 @@ interface Props {searchLocationIndex: (searchQuery: TS.SearchQuery) => void;createLocationsIndexes: () => void;searchAllLocations: (searchQuery: TS.SearchQuery) => void;- loadDirectoryContent: (path: string) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;openURLExternally: (url: string) => void;hideDrawer?: () => void;searchQuery: TS.SearchQuery; // () => any;@@ -484,7 +484,7 @@ const Search = (props: Props) => {function openCurrentDirectory() {if (props.currentDirectory) {- props.loadDirectoryContent(props.currentDirectory);+ props.loadDirectoryContent(props.currentDirectory, false);} else {props.setSearchResults([]);}diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsxindex 584b2629b..1321dfc46 100644--- a/app/components/menus/DirectoryMenu.tsx+++ b/app/components/menus/DirectoryMenu.tsx@@ -75,7 +75,7 @@ interface Props {onClose: (param?: any) => void;anchorEl: Element;directoryPath: string;- loadDirectoryContent: (path: string) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;openDirectory: (path: string) => void;openFsEntry: (fsEntry: TS.FileSystemEntry) => void;reflectCreateEntry?: (path: string, isFile: boolean) => void;@@ -123,12 +123,12 @@ const DirectoryMenu = (props: Props) => {function reloadDirectory() {props.onClose();- props.loadDirectoryContent(props.directoryPath);+ props.loadDirectoryContent(props.directoryPath, false);}function openDirectory() {props.onClose();- props.loadDirectoryContent(props.directoryPath);+ props.loadDirectoryContent(props.directoryPath, true);}function showProperties() {diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsxindex 47b92d5ff..b5c0271e9 100644--- a/app/components/menus/FileMenu.tsx+++ b/app/components/menus/FileMenu.tsx@@ -62,7 +62,7 @@ interface Props {openMoveCopyFilesDialog: () => void;openAddRemoveTagsDialog: () => void;openFsEntry: (fsEntry: TS.FileSystemEntry) => void;- loadDirectoryContent: (path: string) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;openFileNatively: (path: string) => void;showInFileManager: (path: string) => void;showNotification: (@@ -161,7 +161,7 @@ const FileMenu = (props: Props) => {PlatformIO.copyFilePromise(props.selectedFilePath, newFilePath).then(() => {- props.loadDirectoryContent(dirPath);+ props.loadDirectoryContent(dirPath, true);return true;}).catch(error => {@@ -184,7 +184,7 @@ const FileMenu = (props: Props) => {props.selectedFilePath,PlatformIO.getDirSeparator());- props.loadDirectoryContent(parentFolder);+ props.loadDirectoryContent(parentFolder, false);}}diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex a65efc03b..a084326be 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -77,7 +77,7 @@ interface Props {openNextFile: () => any;openPrevFile: () => any;openRenameEntryDialog: () => void;- loadDirectoryContent: (path: string) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;openDirectory: (path: string) => void;showInFileManager: (path: string) => void;openFileNatively: (path?: string) => void;@@ -420,7 +420,7 @@ const GridPerspective = (props: Props) => {props.openFsEntry(fsEntry);} else {console.log('Handle Grid cell db click, selected path : ', fsEntry.path);- props.loadDirectoryContent(fsEntry.path);+ props.loadDirectoryContent(fsEntry.path, true);}};diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 164ef5f6a..1ab00865b 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -851,7 +851,7 @@ export const actions = {// && currentLocation.type === locationType.TYPE_AMPLIFY) {const { currentDirectoryPath } = getState().app;dispatch(actions.clearUploadDialogInt());- dispatch(actions.loadDirectoryContent(currentDirectoryPath));+ dispatch(actions.loadDirectoryContent(currentDirectoryPath, false));}},clearUploadDialogInt: () => ({@@ -880,7 +880,7 @@ export const actions = {);// console.log('parentDirectory: ' + parentDirectory + ' - currentLocationPath: ' + currentLocationPath);if (parentDirectory.includes(currentLocationPath)) {- dispatch(actions.loadDirectoryContent(parentDirectory));+ dispatch(actions.loadDirectoryContent(parentDirectory, false));} else {dispatch(actions.showNotification(@@ -902,6 +902,7 @@ export const actions = {},loadDirectoryContentInt: (directoryPath: string,+ generateThumbnails: boolean,fsEntryMeta?: TS.FileSystemEntryMeta) => (dispatch: (actions: Object) => void, getState: () => any) => {const { settings } = getState();@@ -929,7 +930,8 @@ export const actions = {settings,dispatch,getState,- fsEntryMeta+ fsEntryMeta,+ generateThumbnails);}return true;@@ -939,10 +941,10 @@ export const actions = {dispatch(actions.loadDirectoryFailure(error)); // Currently this is never called, due the promise always resolve});},- loadDirectoryContent: (directoryPath: string) => (- dispatch: (actions: Object) => void,- getState: () => any- ) => {+ loadDirectoryContent: (+ directoryPath: string,+ generateThumbnails: boolean+ ) => (dispatch: (actions: Object) => void, getState: () => any) => {console.time('listDirectoryPromise');window.walkCanceled = false;@@ -955,7 +957,13 @@ export const actions = {normalizePath(directoryPath) + PlatformIO.getDirSeparator()).then(fsEntryMeta => {- dispatch(actions.loadDirectoryContentInt(directoryPath, fsEntryMeta));+ dispatch(+ actions.loadDirectoryContentInt(+ directoryPath,+ generateThumbnails,+ fsEntryMeta+ )+ );/* if (fsEntryMeta.color) { // TODO rethink this states changes are expensivedispatch(actions.setCurrentDirectoryColor(fsEntryMeta.color));}@@ -967,7 +975,9 @@ export const actions = {}).catch(err => {console.log('Error loading meta of the current folder' + err);- dispatch(actions.loadDirectoryContentInt(directoryPath));+ dispatch(+ actions.loadDirectoryContentInt(directoryPath, generateThumbnails)+ );});},loadDirectorySuccess: (@@ -1159,7 +1169,7 @@ export const actions = {.then(newDirPath => {const { currentDirectoryPath, openedFiles } = getState().app;if (currentDirectoryPath === directoryPath) {- dispatch(actions.loadDirectoryContent(newDirPath));+ dispatch(actions.loadDirectoryContent(newDirPath, false));if (openedFiles && openedFiles.length > 0) {if (openedFiles[0].path === directoryPath) {const openedFile = openedFiles[0];@@ -1396,7 +1406,9 @@ export const actions = {);dispatch(actions.setReadOnlyMode(location.isReadOnly || false));dispatch(actions.changeLocation(location));- dispatch(actions.loadDirectoryContent(getLocationPath(location)));+ dispatch(+ actions.loadDirectoryContent(getLocationPath(location), false)+ );return true;}).catch(() => {@@ -1413,7 +1425,7 @@ export const actions = {PlatformIO.disableObjectStoreSupport();dispatch(actions.setReadOnlyMode(location.isReadOnly || false));dispatch(actions.changeLocation(location));- dispatch(actions.loadDirectoryContent(getLocationPath(location)));+ dispatch(actions.loadDirectoryContent(getLocationPath(location), false));if (Pro && Pro.Watcher && location.watchForChanges) {const perspective = getCurrentDirectoryPerspective(getState());const depth = perspective === perspectives.KANBAN ? 3 : 1;@@ -1579,7 +1591,7 @@ export const actions = {return;}if (!fsEntry.isFile) {- dispatch(actions.loadDirectoryContent(fsEntry.path));+ dispatch(actions.loadDirectoryContent(fsEntry.path, false));return;}}@@ -1919,7 +1931,7 @@ export const actions = {if (fsEntry.isFile) {dispatch(actions.openFsEntry(fsEntry));} else {- dispatch(actions.loadDirectoryContent(fsEntry.path));+ dispatch(actions.loadDirectoryContent(fsEntry.path, false));}return true;})@@ -1951,7 +1963,7 @@ export const actions = {if (isCloudLocation) {if (directoryPath && directoryPath.length > 0) {const dirFullPath = directoryPath;- dispatch(actions.loadDirectoryContent(dirFullPath));+ dispatch(actions.loadDirectoryContent(dirFullPath, false));}if (entryPath) {@@ -1991,7 +2003,7 @@ export const actions = {}const dirFullPath =locationPath + PlatformIO.getDirSeparator() + directoryPath;- dispatch(actions.loadDirectoryContent(dirFullPath));+ dispatch(actions.loadDirectoryContent(dirFullPath, false));}if (entryPath && entryPath.length > 0) {diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex f8cc88312..9cce9293b 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -184,7 +184,8 @@ export function prepareDirectoryContent(settings,dispatch,getState,- dirEntryMeta+ dirEntryMeta,+ generateThumbnails) {const currentLocation: TS.Location = getLocation(getState(),@@ -233,18 +234,20 @@ export function prepareDirectoryContent();}- dispatch(AppActions.setGeneratingThumbnails(false));- if (tmbGenerationList.length > 0) {- dispatch(AppActions.setGeneratingThumbnails(true));- PlatformIO.createThumbnailsInWorker(tmbGenerationList)- .then(handleTmbGenerationResults)- .catch(handleTmbGenerationFailed);- }- if (tmbGenerationPromises.length > 0) {- dispatch(AppActions.setGeneratingThumbnails(true));- Promise.all(tmbGenerationPromises)- .then(handleTmbGenerationResults)- .catch(handleTmbGenerationFailed);+ if (generateThumbnails) {+ dispatch(AppActions.setGeneratingThumbnails(false));+ if (tmbGenerationList.length > 0) {+ dispatch(AppActions.setGeneratingThumbnails(true));+ PlatformIO.createThumbnailsInWorker(tmbGenerationList)+ .then(handleTmbGenerationResults)+ .catch(handleTmbGenerationFailed);+ }+ if (tmbGenerationPromises.length > 0) {+ dispatch(AppActions.setGeneratingThumbnails(true));+ Promise.all(tmbGenerationPromises)+ .then(handleTmbGenerationResults)+ .catch(handleTmbGenerationFailed);+ }}console.log('Dir ' + directoryPath + ' contains ' + directoryContent.length);