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

View File

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