1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

All: Fixes #536: Allow changing sync target file path

This commit is contained in:
Laurent Cozic 2018-05-21 16:26:01 +01:00
parent ed70cf571c
commit 429f2d5aab
3 changed files with 19 additions and 15 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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];