1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

All: Started moving sync target logic under SyncTarget classes

This commit is contained in:
Laurent Cozic
2017-11-24 18:37:40 +00:00
parent 946ad7c71a
commit cc7cbc2ecf
7 changed files with 117 additions and 63 deletions

View File

@ -8,18 +8,13 @@ const { FileApiDriverOneDrive } = require('lib/file-api-driver-onedrive.js');
const { shim } = require('lib/shim.js');
const { time } = require('lib/time-utils.js');
const { FileApiDriverMemory } = require('lib/file-api-driver-memory.js');
const SyncTargetRegistry = require('lib/SyncTargetRegistry.js');
const { _ } = require('lib/locale.js');
const reg = {};
reg.initSynchronizerStates_ = {};
reg.syncTargetClasses_ = {
1: require('lib/SyncTarget1.js'),
// 2: require('lib/SyncTarget2.js'),
3: require('lib/SyncTarget3.js'),
};
reg.syncTargets_ = {};
//reg.synchronizers_ = {};
reg.logger = () => {
if (!reg.logger_) {
@ -38,7 +33,7 @@ reg.syncTarget = (syncTargetId = null) => {
if (syncTargetId === null) syncTargetId = Setting.value('sync.target');
if (reg.syncTargets_[syncTargetId]) return reg.syncTargets_[syncTargetId];
const SyncTargetClass = reg.syncTargetClasses_[syncTargetId];
const SyncTargetClass = SyncTargetRegistry.classById(syncTargetId);
if (!reg.db()) throw new Error('Cannot initialize sync without a db');
const target = new SyncTargetClass(reg.db());
@ -47,43 +42,6 @@ reg.syncTarget = (syncTargetId = null) => {
return target;
}
// reg.synchronizer = async (syncTargetId) => {
// 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]);
// }
// if (reg.initSynchronizerStates_[syncTargetId] == 'error') {
// clearInterval(iid);
// reject(new Error('Could not initialise synchroniser'));
// }
// }, 1000);
// });
// } else {
// reg.initSynchronizerStates_[syncTargetId] = 'started';
// try {
// const sync = await reg.initSynchronizer_(syncTargetId);
// reg.synchronizers_[syncTargetId] = sync;
// reg.initSynchronizerStates_[syncTargetId] = 'ready';
// return sync;
// } catch (error) {
// reg.initSynchronizerStates_[syncTargetId] = 'error';
// throw error;
// }
// }
// }
// reg.syncHasAuth = (syncTargetId) => {
// return reg.syncTarget(syncTargetId).isAuthenticated();
// }
reg.scheduleSync = async (delay = null) => {
if (delay === null) delay = 1000 * 3;
@ -141,10 +99,6 @@ reg.scheduleSync = async (delay = null) => {
}
}
// reg.syncStarted = async () => {
// return reg.syncTarget().syncStarted();
// }
reg.setupRecurrentSync = () => {
if (reg.recurrentSyncId_) {
shim.clearInterval(reg.recurrentSyncId_);