1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-03-26 21:12:59 +02:00

Fixed multiple sync init issue

This commit is contained in:
Laurent Cozic 2017-07-31 18:32:51 +00:00
parent e5d4c649ad
commit 2882aef8e4
3 changed files with 31 additions and 8 deletions

View File

@ -105,7 +105,7 @@ function getFooter() {
output.push(_('WEBSITE'));
output.push('');
output.push(INDENT + 'https://joplin.cozic.net');
output.push(INDENT + 'http://joplin.cozic.net');
output.push('');

View File

@ -95,6 +95,8 @@ class SideMenuContentComponent extends Component {
}
async synchronize_press() {
const action = this.props.syncStarted ? 'cancel' : 'start';
if (Setting.value('sync.target') == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
@ -114,7 +116,7 @@ class SideMenuContentComponent extends Component {
return;
}
if (this.props.syncStarted) {
if (action == 'cancel') {
sync.cancel();
} else {
reg.scheduleSync(0);

View File

@ -12,6 +12,8 @@ import { PoorManIntervals } from 'lib/poor-man-intervals.js';
const reg = {};
reg.initSynchronizerStates_ = {};
reg.logger = () => {
if (!reg.logger_) {
console.warn('Calling logger before it is initialized');
@ -54,10 +56,7 @@ reg.oneDriveApi = () => {
return reg.oneDriveApi_;
}
reg.synchronizer = async (syncTargetId) => {
if (!reg.synchronizers_) reg.synchronizers_ = [];
if (reg.synchronizers_[syncTargetId]) return reg.synchronizers_[syncTargetId];
reg.initSynchronizer_ = async (syncTargetId) => {
if (!reg.db()) throw new Error('Cannot initialize synchronizer: db not initialized');
let fileApi = null;
@ -92,11 +91,33 @@ reg.synchronizer = async (syncTargetId) => {
sync.setLogger(reg.logger());
sync.dispatch = reg.dispatch;
reg.synchronizers_[syncTargetId] = sync;
return sync;
}
reg.synchronizer = async (syncTargetId) => {
if (!reg.synchronizers_) reg.synchronizers_ = [];
if (reg.synchronizers_[syncTargetId]) return reg.synchronizers_[syncTargetId];
if (!reg.db()) throw new Error('Cannot initialize synchronizer: db not initialized');
if (reg.initSynchronizerStates_[syncTargetId] == 'started') {
// Synchronizer is already being initialized, so wait here till it's done.
return new Promise((resolve, reject) => {
const iid = setInterval(() => {
if (reg.initSynchronizerStates_[syncTargetId] == 'ready') {
clearInterval(iid);
resolve(reg.synchronizers_[syncTargetId]);
}
}, 1000);
});
} else {
reg.initSynchronizerStates_[syncTargetId] = 'started';
const sync = await reg.initSynchronizer_(syncTargetId);
reg.synchronizers_[syncTargetId] = sync;
reg.initSynchronizerStates_[syncTargetId] = 'ready';
return sync;
}
}
reg.syncHasAuth = (syncTargetId) => {
if (syncTargetId == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
return false;