Skip to content

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

adding support for watching directories

Ilian Sapundshiev86a6394aad60
diff --git a/app/reducers/app.js b/app/reducers/app.js
index 54b171c65..b2c0c5d53 100644
--- a/app/reducers/app.js
+++ b/app/reducers/app.js
@@ -41,7 +41,7 @@ import {
} from '../utils/paths';
import { sortByCriteria, formatDateTime4Tag } from '../utils/misc';
import i18n from '../services/i18n';
-// import { Pro } from '../pro';
+import { Pro } from '../pro';
import { getThumbnailURLPromise } from '../services/thumbsgenerator';
export const types = {
@@ -53,7 +53,9 @@ export const types = {
LOGOUT: 'APP/LOGOUT',
LOAD_DIRECTORY_SUCCESS: 'APP/LOAD_DIRECTORY_SUCCESS',
LOAD_DIRECTORY_FAILURE: 'APP/LOAD_DIRECTORY_FAILURE',
+ CLEAR_DIRECTORY_CONTENT: 'APP/CLEAR_DIRECTORY_CONTENT',
INDEX_DIRECTORY: 'APP/INDEX_DIRECTORY',
+ INDEX_DIRECTORY_CLEAR: 'APP/INDEX_DIRECTORY_CLEAR',
INDEX_DIRECTORY_START: 'APP/INDEX_DIRECTORY_START',
INDEX_DIRECTORY_CANCEL: 'APP/INDEX_DIRECTORY_CANCEL',
INDEX_DIRECTORY_SUCCESS: 'APP/INDEX_DIRECTORY_SUCCESS',
@@ -161,6 +163,13 @@ export default (state: Object = initialState, action: Object) => {
currentDirectoryPath: action.directoryPath
};
}
+ case types.CLEAR_DIRECTORY_CONTENT: {
+ return {
+ ...state,
+ currentDirectoryEntries: [],
+ currentDirectoryPath: ''
+ };
+ }
case types.INDEX_DIRECTORY_START: {
return {
...state,
@@ -168,6 +177,13 @@ export default (state: Object = initialState, action: Object) => {
isIndexing: true
};
}
+ case types.INDEX_DIRECTORY_CLEAR: {
+ return {
+ ...state,
+ currentDirectoryIndex: [],
+ isIndexing: false
+ };
+ }
case types.INDEX_DIRECTORY_CANCEL: {
window.walkCanceled = true;
return { ...state, isIndexing: false };
@@ -364,12 +380,31 @@ export default (state: Object = initialState, action: Object) => {
lmdt: (new Date()).getTime(),
path: action.path
};
+ let currentDirectoryEntries = state.currentDirectoryEntries;
+ // TODO Case changed current directory
+ if (state.currentDirectoryPath === action.path) {
+ // Reindex ??
+ }
+
+ // Workarround for double update caused by the watcher
+ let entryAlreadyAdded = false;
+ state.currentDirectoryEntries.forEach((entry) => {
+ if (entry.path === action.path) {
+ entryAlreadyAdded = true;
+ }
+ });
+ if (
+ !entryAlreadyAdded &&
+ extractParentDirectoryPath(action.path) === state.currentDirectoryPath
+ ) {
+ currentDirectoryEntries = [ // TODO evtl. apply sorting
+ ...state.currentDirectoryEntries,
+ newEntry
+ ];
+ }
return {
...state,
- currentDirectoryEntries: [ // TODO evtl. apply sorting
- newEntry,
- ...state.currentDirectoryEntries
- ],
+ currentDirectoryEntries,
currentDirectoryIndex: [
newEntry,
...state.currentDirectoryIndex
@@ -868,7 +903,7 @@ export const actions = {
type: types.INDEX_DIRECTORY_SEARCH,
searchQuery
}),
- setCurrentLocationId: (locationId: string) => ({
+ setCurrentLocationId: (locationId: string | null) => ({
type: types.SET_CURRENLOCATIONID,
locationId
}),
@@ -885,6 +920,27 @@ export const actions = {
if (locationId !== currentLocationId) {
dispatch(actions.createDirectoryIndex(location.paths[0]));
}
+ if (Pro && Pro.Watcher) {
+ Pro.Watcher.watchFolder(location.paths[0], dispatch);
+ }
+ }
+ return true;
+ });
+ },
+ closeLocation: (locationId: string) => (
+ dispatch: (actions: Object) => void,
+ getState: () => Object
+ ) => {
+ const locations: Array<Location> = getState().locations;
+ locations.map(location => {
+ if (location.uuid === locationId) {
+ // location needed evtl. to unwatch many loc. root folders if available
+ dispatch(actions.setCurrentLocationId(null));
+ dispatch(actions.clearDirectoryContent());
+ dispatch(actions.clearDirectoryIndex());
+ if (Pro && Pro.Watcher) {
+ Pro.Watcher.stopWatching();
+ }
}
return true;
});
@@ -903,6 +959,12 @@ export const actions = {
// dispatch(actions.startDirectoryIndexing());
});
},
+ clearDirectoryIndex: () => ({
+ type: types.INDEX_DIRECTORY_CLEAR
+ }),
+ clearDirectoryContent: () => ({
+ type: types.CLEAR_DIRECTORY_CONTENT
+ }),
indexDirectorySuccess: (directoryIndex: Array<Object>) => ({
type: types.INDEX_DIRECTORY_SUCCESS,
directoryIndex
diff --git a/package.json b/package.json
index 0c06a0106..3dc5a030a 100644
--- a/package.json
+++ b/package.json
@@ -172,6 +172,7 @@
},
"dependencies": {
"autosuggest-highlight": "^3.1.1",
+ "chokidar": "^2.0.3",
"classnames": "^2.2.5",
"date-fns": "^1.29.0",
"electron-debug": "^1.5.0",
diff --git a/yarn.lock b/yarn.lock
index c00875a57..c7e368a9d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2328,7 +2328,7 @@ cheerio@^0.22.0:
lodash.reject "^4.4.0"
lodash.some "^4.4.0"
-chokidar@^2.0.0, chokidar@^2.0.2:
+chokidar@^2.0.0, chokidar@^2.0.2, chokidar@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.0.3.tgz#dcbd4f6cbb2a55b4799ba8a840ac527e5f4b1176"
dependencies: