From 5f5b0a76d9a4335bd61251915bb4e49786e8cca7 Mon Sep 17 00:00:00 2001 From: Wenzhao Hu Date: Mon, 22 Apr 2024 08:06:19 +0800 Subject: [PATCH] fix: fix univer plugin not started --- .../src/services/plugin/plugin.service.ts | 26 +++++++++++-------- packages/core/src/univer.ts | 6 +---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/core/src/services/plugin/plugin.service.ts b/packages/core/src/services/plugin/plugin.service.ts index bedb63264b..3ef5fd4c1f 100644 --- a/packages/core/src/services/plugin/plugin.service.ts +++ b/packages/core/src/services/plugin/plugin.service.ts @@ -37,7 +37,7 @@ export class PluginService implements IDisposable { } dispose(): void { - this._clearFlushLazyPluginsTimer(); + this._clearFlushTimer(); for (const holder of this._pluginHoldersForTypes.values()) { holder.dispose(); @@ -93,27 +93,31 @@ export class PluginService implements IDisposable { } } - private _initLazyPluginsTimer?: number; + private _flushTimer?: number; private _scheduleInitPlugin() { - if (this._initLazyPluginsTimer === undefined) { - this._initLazyPluginsTimer = setTimeout( + if (this._flushTimer === undefined) { + this._flushTimer = setTimeout( () => { - this._flushLazyPlugins(); - this._clearFlushLazyPluginsTimer(); + if (!this._pluginHolderForUniver.started) { + this._pluginHolderForUniver.start(); + } + + this._flushPlugins(); + this._clearFlushTimer(); }, INIT_LAZY_PLUGINS_TIMEOUT ) as unknown as number; } } - private _clearFlushLazyPluginsTimer() { - if (this._initLazyPluginsTimer) { - clearTimeout(this._initLazyPluginsTimer); - this._initLazyPluginsTimer = undefined; + private _clearFlushTimer() { + if (this._flushTimer) { + clearTimeout(this._flushTimer); + this._flushTimer = undefined; } } - private _flushLazyPlugins() { + private _flushPlugins() { this._pluginHolderForUniver.flush(); for (const [_, holder] of this._pluginHoldersForTypes) { if (holder.started) { diff --git a/packages/core/src/univer.ts b/packages/core/src/univer.ts index af96a85576..4b1bcc8136 100644 --- a/packages/core/src/univer.ts +++ b/packages/core/src/univer.ts @@ -119,7 +119,7 @@ export class Univer { const univerInstanceService = injector.get(IUniverInstanceService) as UniverInstanceService; univerInstanceService.__setCreateHandler( (type: UnitType, data, ctor) => { - this._tryProgressToStart(); + this._pluginService.start(); if (!this._startedTypes.has(type)) { this._pluginService.startPluginForType(type); @@ -140,10 +140,6 @@ export class Univer { ); } - private _tryProgressToStart(): void { - this._pluginService.start(); - } - private _tryProgressToReady(): void { const lifecycleService = this._injector.get(LifecycleService); if (lifecycleService.stage < LifecycleStages.Ready) {