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

Method setPluginDisabled

src/main/api/renderer/plugins.ts:257–300  ·  view source on GitHub ↗
(
    pluginPath: string,
    disabled: boolean
  )

Source from the content-addressed store, hash-verified

255 }
256
257 public async setPluginDisabled(
258 pluginPath: string,
259 disabled: boolean
260 ): Promise<{ success: boolean; error?: string }> {
261 try {
262 const plugins = databaseAPI.dbGet('plugins')
263 if (!Array.isArray(plugins)) {
264 return { success: false, error: '插件列表不存在' }
265 }
266
267 const plugin = plugins.find((item: any) => item.path === pluginPath)
268 if (!plugin) {
269 return { success: false, error: '插件不存在' }
270 }
271 if (isBundledInternalPlugin(plugin.name)) {
272 return { success: false, error: '内置插件不能禁用' }
273 }
274
275 const disabledPlugins = this.getDisabledPluginSet()
276 const isCurrentlyDisabled = disabledPlugins.has(pluginPath)
277 if (isCurrentlyDisabled === disabled) {
278 return { success: true }
279 }
280
281 if (disabled) {
282 disabledPlugins.add(pluginPath)
283 } else {
284 disabledPlugins.delete(pluginPath)
285 }
286 this.disabledPluginPathSet = disabledPlugins
287 databaseAPI.dbPut(DISABLED_PLUGINS_KEY, [...disabledPlugins])
288
289 if (disabled && this.pluginManager) {
290 this.pluginManager.killPlugin(pluginPath)
291 }
292
293 this.mainWindow?.webContents.send('plugins-changed')
294 this.mainWindow?.webContents.send('super-panel-pinned-changed')
295 return { success: true }
296 } catch (error: unknown) {
297 console.error('[Plugins] 更新插件禁用状态失败:', error)
298 return { success: false, error: error instanceof Error ? error.message : '未知错误' }
299 }
300 }
301
302 // 获取所有插件列表(包括 system 插件,用于生成搜索指令)
303 public async getAllPlugins(): Promise<any[]> {

Callers 2

setupIPCMethod · 0.95
setupIPCMethod · 0.80

Calls 5

getDisabledPluginSetMethod · 0.95
isBundledInternalPluginFunction · 0.90
dbGetMethod · 0.45
dbPutMethod · 0.45
killPluginMethod · 0.45

Tested by

no test coverage detected