MCPcopy
hub / github.com/ZToolsCenter/ZTools / deletePlugin

Method deletePlugin

src/main/api/renderer/plugins.ts:457–516  ·  view source on GitHub ↗

* 删除插件 * @param pluginPath 插件路径 * @param options 删除选项 当 options.deleteData 显式设置为 false 时,保留插件数据

(pluginPath: string, options: DeletePluginOptions = {})

Source from the content-addressed store, hash-verified

455 * @param options 删除选项 当 options.deleteData 显式设置为 false 时,保留插件数据
456 */
457 public async deletePlugin(pluginPath: string, options: DeletePluginOptions = {}): Promise<any> {
458 try {
459 const plugins: any = databaseAPI.dbGet('plugins')
460 if (!plugins || !Array.isArray(plugins)) {
461 return { success: false, error: '插件列表不存在' }
462 }
463
464 const pluginIndex = plugins.findIndex((p: any) => p.path === pluginPath)
465 if (pluginIndex === -1) {
466 return { success: false, error: '插件不存在' }
467 }
468
469 const pluginInfo = plugins[pluginIndex]
470
471 // ✅ 检查是否为内置插件
472 if (isBundledInternalPlugin(pluginInfo.name)) {
473 return {
474 success: false,
475 error: '内置插件不能卸载'
476 }
477 }
478
479 this.pluginManager?.killPlugin(pluginPath)
480
481 plugins.splice(pluginIndex, 1)
482 databaseAPI.dbPut('plugins', plugins)
483
484 this.devProjects.removePluginUsageData(pluginInfo.name)
485
486 if (options.deleteData !== false) {
487 await databaseAPI.clearPluginData(pluginInfo.name)
488 this.removePluginNameConfigs(PLUGIN_NAME_SETTING_KEYS, pluginInfo.name)
489 }
490
491 // 删除禁用插件标识
492 const disabledPlugins = this.getDisabledPluginSet()
493 if (disabledPlugins.delete(pluginPath)) {
494 this.disabledPluginPathSet = disabledPlugins
495 databaseAPI.dbPut(DISABLED_PLUGINS_KEY, [...disabledPlugins])
496 }
497
498 this.notifyPluginsChanged()
499
500 if (!pluginInfo.isDevelopment) {
501 try {
502 await fs.rm(pluginPath, { recursive: true, force: true })
503 console.log('[Plugins] 已删除插件目录:', pluginPath)
504 } catch (error) {
505 console.error('[Plugins] 删除插件目录失败:', error)
506 }
507 } else {
508 console.log('[Plugins] 开发中插件,保留目录:', pluginPath)
509 }
510
511 return { success: true }
512 } catch (error: unknown) {
513 console.error('[Plugins] 删除插件失败:', error)
514 return { success: false, error: error instanceof Error ? error.message : '未知错误' }

Callers 3

setupIPCMethod · 0.95
setupIPCMethod · 0.80

Calls 9

getDisabledPluginSetMethod · 0.95
notifyPluginsChangedMethod · 0.95
isBundledInternalPluginFunction · 0.90
removePluginUsageDataMethod · 0.80
clearPluginDataMethod · 0.80
dbGetMethod · 0.45
killPluginMethod · 0.45
dbPutMethod · 0.45

Tested by

no test coverage detected