1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-27 10:32:58 +02:00

Desktop: Resolves #5770: Performance improvement when switching note while plugins are running (#6409)

This commit is contained in:
Kenichi Kobayashi 2022-04-17 20:41:27 +09:00 committed by GitHub
parent 1797e847aa
commit 5d9b43ee31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -8,7 +8,7 @@ import NoteEditor from '../NoteEditor/NoteEditor';
import NoteContentPropertiesDialog from '../NoteContentPropertiesDialog';
import ShareNoteDialog from '../ShareNoteDialog';
import CommandService from '@joplin/lib/services/CommandService';
import { PluginStates, utils as pluginUtils } from '@joplin/lib/services/plugins/reducer';
import { PluginHtmlContents, PluginStates, utils as pluginUtils } from '@joplin/lib/services/plugins/reducer';
import Sidebar from '../Sidebar/Sidebar';
import UserWebview from '../../services/plugins/UserWebview';
import UserWebviewDialog from '../../services/plugins/UserWebviewDialog';
@ -53,6 +53,7 @@ interface LayerModalState {
interface Props {
plugins: PluginStates;
pluginHtmlContents: PluginHtmlContents;
pluginsLoaded: boolean;
hasNotesBeingSaved: boolean;
dispatch: Function;
@ -723,12 +724,13 @@ class MainScreenComponent extends React.Component<Props, State> {
}
} else {
const { view, plugin } = viewInfo;
const html = this.props.pluginHtmlContents[plugin.id]?.[view.id] ?? '';
return <UserWebview
key={view.id}
viewId={view.id}
themeId={this.props.themeId}
html={view.html}
html={html}
scripts={view.scripts}
pluginId={plugin.id}
borderBottom={true}
@ -762,12 +764,13 @@ class MainScreenComponent extends React.Component<Props, State> {
const { plugin, view } = info;
if (view.containerType !== ContainerType.Dialog) continue;
if (!view.opened) continue;
const html = this.props.pluginHtmlContents[plugin.id]?.[view.id] ?? '';
output.push(<UserWebviewDialog
key={view.id}
viewId={view.id}
themeId={this.props.themeId}
html={view.html}
html={html}
scripts={view.scripts}
pluginId={plugin.id}
buttons={view.buttons}
@ -865,6 +868,7 @@ const mapStateToProps = (state: AppState) => {
selectedNoteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null,
pluginsLegacy: state.pluginsLegacy,
plugins: state.pluginService.plugins,
pluginHtmlContents: state.pluginService.pluginHtmlContents,
customCss: state.customCss,
editorNoteStatuses: state.editorNoteStatuses,
hasNotesBeingSaved: stateUtils.hasNotesBeingSaved(state),

View File

@ -33,14 +33,24 @@ export interface PluginStates {
[key: string]: PluginState;
}
export interface PluginHtmlContent {
[viewId: string]: string;
}
export interface PluginHtmlContents {
[pluginId: string]: PluginHtmlContent;
}
export interface State {
plugins: PluginStates;
pluginHtmlContents: PluginHtmlContents;
}
export const stateRootKey = 'pluginService';
export const defaultState: State = {
plugins: {},
pluginHtmlContents: {},
};
export const utils = {
@ -139,7 +149,12 @@ const reducer = (draftRoot: Draft<any>, action: any) => {
case 'PLUGIN_VIEW_PROP_SET':
(draft.plugins[action.pluginId].views[action.id] as any)[action.name] = action.value;
if (action.name !== 'html') {
(draft.plugins[action.pluginId].views[action.id] as any)[action.name] = action.value;
} else {
draft.pluginHtmlContents[action.pluginId] ??= {};
draft.pluginHtmlContents[action.pluginId][action.id] = action.value;
}
break;
case 'PLUGIN_VIEW_PROP_PUSH':