From 429f2d5aabd05ce4fd2a79ea98e637cec4f4f7bd Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 21 May 2018 16:26:01 +0100 Subject: [PATCH] All: Fixes #536: Allow changing sync target file path --- .../shared/reduxSharedMiddleware.js | 6 +++++ ReactNativeClient/lib/file-api.js | 23 +++++++------------ ReactNativeClient/lib/registry.js | 5 ++++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ReactNativeClient/lib/components/shared/reduxSharedMiddleware.js b/ReactNativeClient/lib/components/shared/reduxSharedMiddleware.js index ba98c23fa..692eeff71 100644 --- a/ReactNativeClient/lib/components/shared/reduxSharedMiddleware.js +++ b/ReactNativeClient/lib/components/shared/reduxSharedMiddleware.js @@ -1,4 +1,5 @@ const Setting = require('lib/models/Setting'); +const { reg } = require('lib/registry.js'); const reduxSharedMiddleware = function(store, next, action) { const newState = store.getState(); @@ -6,6 +7,11 @@ const reduxSharedMiddleware = function(store, next, action) { if (action.type == 'FOLDER_SET_COLLAPSED' || action.type == 'FOLDER_TOGGLE') { Setting.setValue('collapsedFolderIds', newState.collapsedFolderIds); } + + if (action.type === 'SETTING_UPDATE_ONE' && !!action.key.match(/^sync\.\d+\.path$/)) { + reg.resetSyncTarget(); + } + } module.exports = reduxSharedMiddleware; \ No newline at end of file diff --git a/ReactNativeClient/lib/file-api.js b/ReactNativeClient/lib/file-api.js index b98362ab6..c611a4110 100644 --- a/ReactNativeClient/lib/file-api.js +++ b/ReactNativeClient/lib/file-api.js @@ -51,6 +51,10 @@ class FileApi { return 0; } + baseDir() { + return this.baseDir_; + } + tempDirName() { if (this.tempDirName_ === null) throw Error('Temp dir not set!'); return this.tempDirName_; @@ -88,7 +92,7 @@ class FileApi { fullPath_(path) { let output = []; - if (this.baseDir_) output.push(this.baseDir_); + if (this.baseDir()) output.push(this.baseDir()); if (path) output.push(path); return output.join('/'); } @@ -99,9 +103,9 @@ class FileApi { if (!('includeHidden' in options)) options.includeHidden = false; if (!('context' in options)) options.context = null; - this.logger().debug('list ' + this.baseDir_); + this.logger().debug('list ' + this.baseDir()); - const result = await tryAndRepeat(() => this.driver_.list(this.baseDir_, options), this.requestRepeatCount()); + const result = await tryAndRepeat(() => this.driver_.list(this.baseDir(), options), this.requestRepeatCount()); if (!options.includeHidden) { let temp = []; @@ -112,17 +116,6 @@ class FileApi { } return result; - - // return this.driver_.list(this.baseDir_, options).then((result) => { - // if (!options.includeHidden) { - // let temp = []; - // for (let i = 0; i < result.items.length; i++) { - // if (!isHidden(result.items[i].path)) temp.push(result.items[i]); - // } - // result.items = temp; - // } - // return result; - // }); } // Deprectated @@ -187,7 +180,7 @@ class FileApi { } clearRoot() { - return tryAndRepeat(() => this.driver_.clearRoot(this.baseDir_), this.requestRepeatCount()); + return tryAndRepeat(() => this.driver_.clearRoot(this.baseDir()), this.requestRepeatCount()); } delta(path, options = null) { diff --git a/ReactNativeClient/lib/registry.js b/ReactNativeClient/lib/registry.js index ea9d8d818..7aa78b2a3 100644 --- a/ReactNativeClient/lib/registry.js +++ b/ReactNativeClient/lib/registry.js @@ -30,6 +30,11 @@ reg.showErrorMessageBox = (message) => { reg.showErrorMessageBoxHandler_(message); } +reg.resetSyncTarget = (syncTargetId = null) => { + if (syncTargetId === null) syncTargetId = Setting.value('sync.target'); + delete reg.syncTargets_[syncTargetId]; +} + reg.syncTarget = (syncTargetId = null) => { if (syncTargetId === null) syncTargetId = Setting.value('sync.target'); if (reg.syncTargets_[syncTargetId]) return reg.syncTargets_[syncTargetId];