refactor: simplify the plugin startup logic (#6113)

#### What type of PR is this?

/area ui
/kind improvement
/milestone 2.17.x

#### What this PR does / why we need it:

简化插件启动的接口,改为之前单独提供的修改插件状态的接口,而不是修改 `spec.enabled`。

#### Special notes for your reviewer:

需要测试:

1. 手动安装插件之后,启动插件。

#### Does this PR introduce a user-facing change?

```release-note
None
```
This commit is contained in:
Ryan Wang
2024-06-24 11:58:43 +08:00
committed by GitHub
parent f45ffdeca1
commit 6a1ade375d
3 changed files with 16 additions and 27 deletions

View File

@@ -1,7 +1,6 @@
import type { ComputedRef, Ref } from "vue";
import { computed } from "vue";
import { type Plugin, PluginStatusPhaseEnum } from "@halo-dev/api-client";
import { cloneDeep } from "lodash-es";
import { apiClient } from "@/utils/api-client";
import { Dialog, Toast } from "@halo-dev/components";
import { useI18n } from "vue-i18n";
@@ -117,14 +116,12 @@ export function usePluginLifeCycle(
if (!plugin.value) return;
try {
if (enabled) {
const pluginToUpdate = cloneDeep(plugin.value);
pluginToUpdate.spec.enabled = false;
await apiClient.extension.plugin.updatePluginHaloRunV1alpha1Plugin({
name: pluginToUpdate.metadata.name,
plugin: pluginToUpdate,
});
}
await apiClient.plugin.changePluginRunningState({
name: plugin.value.metadata.name,
pluginRunningStateRequest: {
enable: false,
},
});
await apiClient.extension.plugin.deletePluginHaloRunV1alpha1Plugin({
name: plugin.value.metadata.name,