You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
Sync in background for RN
This commit is contained in:
@@ -5,9 +5,16 @@ import { parameters } from 'lib/parameters.js';
|
||||
import { FileApi } from 'lib/file-api.js';
|
||||
import { Synchronizer } from 'lib/synchronizer.js';
|
||||
import { FileApiDriverOneDrive } from 'lib/file-api-driver-onedrive.js';
|
||||
import { EventDispatcher } from 'lib/event-dispatcher.js';
|
||||
|
||||
const reg = {};
|
||||
|
||||
reg.dispatcher = () => {
|
||||
if (this.dispatcher_) return this.dispatcher_;
|
||||
this.dispatcher_ = new EventDispatcher();
|
||||
return this.dispatcher_;
|
||||
}
|
||||
|
||||
reg.logger = () => {
|
||||
if (!reg.logger_) {
|
||||
console.warn('Calling logger before it is initialized');
|
||||
@@ -70,9 +77,37 @@ reg.synchronizer = async () => {
|
||||
let fileApi = await reg.fileApi();
|
||||
reg.synchronizer_ = new Synchronizer(reg.db(), fileApi, Setting.value('appType'));
|
||||
reg.synchronizer_.setLogger(reg.logger());
|
||||
|
||||
reg.synchronizer_.on('progress', (report) => {
|
||||
reg.dispatcher().dispatch('synchronizer_progress', report);
|
||||
});
|
||||
|
||||
reg.synchronizer_.on('complete', () => {
|
||||
reg.dispatcher().dispatch('synchronizer_complete');
|
||||
});
|
||||
|
||||
return reg.synchronizer_;
|
||||
}
|
||||
|
||||
reg.scheduleSync = async () => {
|
||||
if (reg.scheduleSyncId_) return;
|
||||
|
||||
reg.logger().info('Scheduling sync operation...');
|
||||
|
||||
reg.scheduleSyncId_ = setTimeout(async () => {
|
||||
reg.scheduleSyncId_ = null;
|
||||
reg.logger().info('Doing scheduled sync');
|
||||
|
||||
if (!reg.oneDriveApi().auth()) {
|
||||
reg.logger().info('Synchronizer is missing credentials - manual sync required to authenticate.');
|
||||
return;
|
||||
}
|
||||
|
||||
const sync = await reg.synchronizer();
|
||||
sync.start();
|
||||
}, 1000 * 10);
|
||||
}
|
||||
|
||||
reg.setDb = (v) => {
|
||||
reg.db_ = v;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user