mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Plugins: Add support for workspace.onSyncStart event
This commit is contained in:
parent
8d90cc234f
commit
efb3546675
@ -7,8 +7,13 @@ joplin.plugins.register({
|
||||
console.info('Alarm was triggered for note: ', note);
|
||||
});
|
||||
|
||||
joplin.workspace.onSyncComplete(async () => {
|
||||
joplin.workspace.onSyncStart(async (event:any) => {
|
||||
console.info('Sync has started...');
|
||||
});
|
||||
|
||||
joplin.workspace.onSyncComplete(async (event:any) => {
|
||||
console.info('Sync has completed');
|
||||
console.info('With errors:', event.withErrors);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
@ -121,6 +121,10 @@ export default class Synchronizer {
|
||||
}
|
||||
}
|
||||
|
||||
private static reportHasErrors(report: any): boolean {
|
||||
return !!report && !!report.errors && !!report.errors.length;
|
||||
}
|
||||
|
||||
static reportToLines(report: any) {
|
||||
const lines = [];
|
||||
if (report.createLocal) lines.push(_('Created local items: %d.', report.createLocal));
|
||||
@ -132,7 +136,7 @@ export default class Synchronizer {
|
||||
if (report.fetchingTotal && report.fetchingProcessed) lines.push(_('Fetched items: %d/%d.', report.fetchingProcessed, report.fetchingTotal));
|
||||
if (report.cancelling && !report.completedTime) lines.push(_('Cancelling...'));
|
||||
if (report.completedTime) lines.push(_('Completed: %s', time.formatMsToLocal(report.completedTime)));
|
||||
if (report.errors && report.errors.length) lines.push(_('Last error: %s', report.errors[report.errors.length - 1].toString().substr(0, 500)));
|
||||
if (this.reportHasErrors(report)) lines.push(_('Last error: %s', report.errors[report.errors.length - 1].toString().substr(0, 500)));
|
||||
|
||||
return lines;
|
||||
}
|
||||
@ -193,7 +197,7 @@ export default class Synchronizer {
|
||||
this.logger().info(`Total notes: ${noteCount}`);
|
||||
this.logger().info(`Total resources: ${resourceCount}`);
|
||||
|
||||
if (report.errors && report.errors.length) {
|
||||
if (Synchronizer.reportHasErrors(report)) {
|
||||
this.logger().warn('There was some errors:');
|
||||
for (let i = 0; i < report.errors.length; i++) {
|
||||
const e = report.errors[i];
|
||||
@ -315,6 +319,7 @@ export default class Synchronizer {
|
||||
const outputContext = Object.assign({}, lastContext);
|
||||
|
||||
this.dispatch({ type: 'SYNC_STARTED' });
|
||||
eventManager.emit('syncStart');
|
||||
|
||||
this.logSyncOperation('starting', null, null, `Starting synchronisation to target ${syncTargetId}... [${synchronizationId}]`);
|
||||
|
||||
@ -899,11 +904,14 @@ export default class Synchronizer {
|
||||
|
||||
await this.logSyncSummary(this.progressReport_);
|
||||
|
||||
eventManager.emit('syncComplete', {
|
||||
withErrors: Synchronizer.reportHasErrors(this.progressReport_),
|
||||
});
|
||||
|
||||
this.onProgress_ = function() {};
|
||||
this.progressReport_ = {};
|
||||
|
||||
this.dispatch({ type: 'SYNC_COMPLETED', isFullSync: this.isFullSync(syncSteps) });
|
||||
eventManager.emit('syncComplete');
|
||||
|
||||
this.state_ = 'idle';
|
||||
|
||||
|
@ -19,7 +19,14 @@ interface ItemChangeEvent {
|
||||
event: ItemChangeEventType;
|
||||
}
|
||||
|
||||
interface SyncStartEvent {
|
||||
// Tells whether there were errors during sync or not. The log will
|
||||
// have the complete information about any error.
|
||||
withErrors: boolean;
|
||||
}
|
||||
|
||||
type ItemChangeHandler = (event: ItemChangeEvent)=> void;
|
||||
type SyncStartHandler = (event: SyncStartEvent)=> void;
|
||||
|
||||
/**
|
||||
* The workspace service provides access to all the parts of Joplin that
|
||||
@ -80,8 +87,15 @@ export default class JoplinWorkspace {
|
||||
/**
|
||||
* Called when an alarm associated with a to-do is triggered.
|
||||
*/
|
||||
public async onNoteAlarmTrigger(callback: Function): Promise<Disposable> {
|
||||
return makeListener(eventManager, 'noteAlarmTrigger', callback);
|
||||
public async onNoteAlarmTrigger(handler: Function): Promise<Disposable> {
|
||||
return makeListener(eventManager, 'noteAlarmTrigger', handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the synchronisation process is starting.
|
||||
*/
|
||||
public async onSyncStart(handler: SyncStartHandler): Promise<Disposable> {
|
||||
return makeListener(eventManager, 'syncStart', handler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user