Skip to content

feat: 新增内部 API 特权插件名称列表功能, 主要用于不是内置插件但是需要调用内置的 api 准备#346

Merged
lzx8589561 merged 2 commits intoZToolsCenter:mainfrom
xiaou66:main
Mar 29, 2026
Merged

feat: 新增内部 API 特权插件名称列表功能, 主要用于不是内置插件但是需要调用内置的 api 准备#346
lzx8589561 merged 2 commits intoZToolsCenter:mainfrom
xiaou66:main

Conversation

@xiaou66
Copy link
Copy Markdown
Collaborator

@xiaou66 xiaou66 commented Mar 29, 2026

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the plugin management system to distinguish between bundled internal plugins and those with internal API privileges. It introduces new constants and functions to handle these categories separately and updates the plugin information structure across the API and manager layers. The review feedback suggests enhancing type safety in plugin name checks by avoiding unsafe type assertions and recommends using a named interface for plugin metadata to improve code maintainability.

* @returns 是否为随包内置插件
*/
export function isBundledInternalPlugin(pluginName: string): boolean {
return BUNDLED_INTERNAL_PLUGIN_NAMES.includes(pluginName as BundledInternalPluginName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高类型安全性,建议修改此处的类型断言。pluginName as BundledInternalPluginName 会强制编译器将任意字符串视为 BundledInternalPluginName 类型,这可能隐藏潜在的类型问题。
一个更清晰且类型安全的方式是将 BUNDLED_INTERNAL_PLUGIN_NAMES 视为一个字符串数组来进行检查。

Suggested change
return BUNDLED_INTERNAL_PLUGIN_NAMES.includes(pluginName as BundledInternalPluginName)
return (BUNDLED_INTERNAL_PLUGIN_NAMES as readonly string[]).includes(pluginName)

export function isInternalPlugin(pluginName: string): boolean {
return INTERNAL_PLUGIN_NAMES.includes(pluginName as InternalPluginName)
export function canPluginUseInternalApi(pluginName: string): boolean {
return INTERNAL_API_PLUGIN_NAMES.includes(pluginName as InternalApiPluginName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

isBundledInternalPlugin 函数类似,为了提高类型安全性,建议修改此处的类型断言。pluginName as InternalApiPluginName 会强制编译器将任意字符串视为 InternalApiPluginName 类型。
建议将 INTERNAL_API_PLUGIN_NAMES 视为一个字符串数组来进行检查,这样更符合类型检查的意图。

Suggested change
return INTERNAL_API_PLUGIN_NAMES.includes(pluginName as InternalApiPluginName)
return (INTERNAL_API_PLUGIN_NAMES as readonly string[]).includes(pluginName)

Comment on lines 1826 to 1832
public getPluginInfoByWebContents(webContents: WebContents): {
name: string
path: string
isInternal: boolean
canUseInternalApi: boolean
isBundledInternal: boolean
logo?: string
} | null {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的可读性和可维护性,建议为 getPluginInfoByWebContents 函数的返回值定义一个具名接口(例如 PluginInfo),而不是使用匿名对象类型。这样可以使类型意图更清晰,也便于在其他地方复用。

例如,可以在文件顶部或类外部定义一个接口:

interface PluginInfo {
  name: string;
  path: string;
  canUseInternalApi: boolean;
  isBundledInternal: boolean;
  logo?: string;
}

然后将函数签名修改为:

public getPluginInfoByWebContents(webContents: WebContents): PluginInfo | null {

@lzx8589561 lzx8589561 merged commit f01c106 into ZToolsCenter:main Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants