Plugins: Adds `joplin.workspace.onResourceChange`

pull/5938/head
Laurent Cozic 2021-12-30 11:25:39 +01:00
parent 59cdcaf8d1
commit 2660ff3af6
2 changed files with 22 additions and 2 deletions

View File

@ -63,6 +63,7 @@ import ShareService from '@joplin/lib/services/share/ShareService';
import checkForUpdates from './checkForUpdates';
import { AppState } from './app.reducer';
import syncDebugLog from '@joplin/lib/services/synchronizer/syncDebugLog';
import eventManager from '../lib/eventManager';
// import { runIntegrationTests } from '@joplin/lib/services/e2ee/ppkTestUtils';
const pluginClasses = [
@ -234,7 +235,7 @@ class Application extends BaseApplication {
});
}
async loadCustomCss(filePath: string) {
public async loadCustomCss(filePath: string) {
let cssString = '';
if (await fs.pathExists(filePath)) {
try {
@ -523,6 +524,12 @@ class Application extends BaseApplication {
ResourceEditWatcher.instance().initialize(reg.logger(), (action: any) => { this.store().dispatch(action); }, (path: string) => bridge().openItem(path));
// Forwards the local event to the global event manager, so that it can
// be picked up by the plugin manager.
ResourceEditWatcher.instance().on('resourceChange', (event: any) => {
eventManager.emit('resourceChange', event);
});
RevisionService.instance().runInBackground();
// Make it available to the console window - useful to call revisionService.collectRevisions()

View File

@ -38,8 +38,13 @@ interface SyncStartEvent {
withErrors: boolean;
}
interface ResourceChangeEvent {
id: string;
}
type ItemChangeHandler = (event: ItemChangeEvent)=> void;
type SyncStartHandler = (event: SyncStartEvent)=> void;
type ResourceChangeHandler = (event: ResourceChangeEvent)=> void;
/**
* The workspace service provides access to all the parts of Joplin that
@ -54,7 +59,7 @@ export default class JoplinWorkspace {
private store: any;
constructor(store: any) {
public constructor(store: any) {
this.store = store;
}
@ -98,6 +103,14 @@ export default class JoplinWorkspace {
return makeListener(eventManager, 'itemChange', wrapperHandler);
}
/**
* Called when a resource is changed. Currently this handled will not be
* called when a resource is added or deleted.
*/
public async onResourceChange(handler: ResourceChangeHandler): Promise<void> {
makeListener(eventManager, 'resourceChange', handler);
}
/**
* Called when an alarm associated with a to-do is triggered.
*/