mirror of
https://github.com/laurent22/joplin.git
synced 2025-03-29 21:21:15 +02:00
Fixed multiple sync init issue
This commit is contained in:
parent
e5d4c649ad
commit
2882aef8e4
@ -105,7 +105,7 @@ function getFooter() {
|
|||||||
|
|
||||||
output.push(_('WEBSITE'));
|
output.push(_('WEBSITE'));
|
||||||
output.push('');
|
output.push('');
|
||||||
output.push(INDENT + 'https://joplin.cozic.net');
|
output.push(INDENT + 'http://joplin.cozic.net');
|
||||||
|
|
||||||
output.push('');
|
output.push('');
|
||||||
|
|
||||||
|
@ -95,6 +95,8 @@ class SideMenuContentComponent extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async synchronize_press() {
|
async synchronize_press() {
|
||||||
|
const action = this.props.syncStarted ? 'cancel' : 'start';
|
||||||
|
|
||||||
if (Setting.value('sync.target') == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
|
if (Setting.value('sync.target') == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
|
||||||
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
|
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
|
||||||
|
|
||||||
@ -114,7 +116,7 @@ class SideMenuContentComponent extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.syncStarted) {
|
if (action == 'cancel') {
|
||||||
sync.cancel();
|
sync.cancel();
|
||||||
} else {
|
} else {
|
||||||
reg.scheduleSync(0);
|
reg.scheduleSync(0);
|
||||||
|
@ -12,6 +12,8 @@ import { PoorManIntervals } from 'lib/poor-man-intervals.js';
|
|||||||
|
|
||||||
const reg = {};
|
const reg = {};
|
||||||
|
|
||||||
|
reg.initSynchronizerStates_ = {};
|
||||||
|
|
||||||
reg.logger = () => {
|
reg.logger = () => {
|
||||||
if (!reg.logger_) {
|
if (!reg.logger_) {
|
||||||
console.warn('Calling logger before it is initialized');
|
console.warn('Calling logger before it is initialized');
|
||||||
@ -54,10 +56,7 @@ reg.oneDriveApi = () => {
|
|||||||
return reg.oneDriveApi_;
|
return reg.oneDriveApi_;
|
||||||
}
|
}
|
||||||
|
|
||||||
reg.synchronizer = async (syncTargetId) => {
|
reg.initSynchronizer_ = 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.db()) throw new Error('Cannot initialize synchronizer: db not initialized');
|
||||||
|
|
||||||
let fileApi = null;
|
let fileApi = null;
|
||||||
@ -92,11 +91,33 @@ reg.synchronizer = async (syncTargetId) => {
|
|||||||
sync.setLogger(reg.logger());
|
sync.setLogger(reg.logger());
|
||||||
sync.dispatch = reg.dispatch;
|
sync.dispatch = reg.dispatch;
|
||||||
|
|
||||||
reg.synchronizers_[syncTargetId] = sync;
|
|
||||||
|
|
||||||
return 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) => {
|
reg.syncHasAuth = (syncTargetId) => {
|
||||||
if (syncTargetId == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
|
if (syncTargetId == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user