You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
Mobile: Add support for plugin editor views (#11831)
Co-authored-by: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com>
This commit is contained in:
52
packages/lib/services/plugins/EditorPluginHandler.ts
Normal file
52
packages/lib/services/plugins/EditorPluginHandler.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
// The goal of this class is to simplify the integration of the `joplin.views.editor` plugin logic
|
||||
// in the desktop and mobile app. See here for more information:
|
||||
//
|
||||
// packages/lib/services/plugins/api/JoplinViewsEditor.ts
|
||||
|
||||
import Logger from '@joplin/utils/Logger';
|
||||
import AsyncActionQueue, { IntervalType } from '../../AsyncActionQueue';
|
||||
import eventManager from '../../eventManager';
|
||||
import { EditorActivationCheckFilterObject } from './api/types';
|
||||
import type PluginService from './PluginService';
|
||||
import WebviewController from './WebviewController';
|
||||
|
||||
const logger = Logger.create('EditorPluginHandler');
|
||||
|
||||
const makeNoteUpdateAction = (pluginService: PluginService, shownEditorViewIds: string[]) => {
|
||||
return async () => {
|
||||
for (const viewId of shownEditorViewIds) {
|
||||
const controller = pluginService.viewControllerByViewId(viewId) as WebviewController;
|
||||
if (controller) controller.emitUpdate();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default class {
|
||||
|
||||
private pluginService_: PluginService;
|
||||
private viewUpdateAsyncQueue_ = new AsyncActionQueue(100, IntervalType.Fixed);
|
||||
|
||||
public constructor(pluginService: PluginService) {
|
||||
this.pluginService_ = pluginService;
|
||||
}
|
||||
|
||||
public emitUpdate(shownEditorViewIds: string[]) {
|
||||
logger.info('emitUpdate:', shownEditorViewIds);
|
||||
this.viewUpdateAsyncQueue_.push(makeNoteUpdateAction(this.pluginService_, shownEditorViewIds));
|
||||
}
|
||||
|
||||
public async emitActivationCheck() {
|
||||
let filterObject: EditorActivationCheckFilterObject = {
|
||||
activatedEditors: [],
|
||||
};
|
||||
filterObject = await eventManager.filterEmit('editorActivationCheck', filterObject);
|
||||
|
||||
logger.info('emitActivationCheck: responses:', filterObject);
|
||||
|
||||
for (const editor of filterObject.activatedEditors) {
|
||||
const controller = this.pluginService_.pluginById(editor.pluginId).viewController(editor.viewId) as WebviewController;
|
||||
controller.setActive(editor.isActive);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user