diff --git a/packages/app-desktop/app.ts b/packages/app-desktop/app.ts index 6e53d52de5..6090048c10 100644 --- a/packages/app-desktop/app.ts +++ b/packages/app-desktop/app.ts @@ -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() diff --git a/packages/lib/services/plugins/api/JoplinWorkspace.ts b/packages/lib/services/plugins/api/JoplinWorkspace.ts index 7a0ea8812a..07af3cd98f 100644 --- a/packages/lib/services/plugins/api/JoplinWorkspace.ts +++ b/packages/lib/services/plugins/api/JoplinWorkspace.ts @@ -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 { + makeListener(eventManager, 'resourceChange', handler); + } + /** * Called when an alarm associated with a to-do is triggered. */