feat: 新增内部 API 特权插件名称列表功能, 主要用于不是内置插件但是需要调用内置的 api 准备#346
feat: 新增内部 API 特权插件名称列表功能, 主要用于不是内置插件但是需要调用内置的 api 准备#346lzx8589561 merged 2 commits intoZToolsCenter:mainfrom
Conversation
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
为了提高类型安全性,建议修改此处的类型断言。pluginName as BundledInternalPluginName 会强制编译器将任意字符串视为 BundledInternalPluginName 类型,这可能隐藏潜在的类型问题。
一个更清晰且类型安全的方式是将 BUNDLED_INTERNAL_PLUGIN_NAMES 视为一个字符串数组来进行检查。
| 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) |
There was a problem hiding this comment.
与 isBundledInternalPlugin 函数类似,为了提高类型安全性,建议修改此处的类型断言。pluginName as InternalApiPluginName 会强制编译器将任意字符串视为 InternalApiPluginName 类型。
建议将 INTERNAL_API_PLUGIN_NAMES 视为一个字符串数组来进行检查,这样更符合类型检查的意图。
| return INTERNAL_API_PLUGIN_NAMES.includes(pluginName as InternalApiPluginName) | |
| return (INTERNAL_API_PLUGIN_NAMES as readonly string[]).includes(pluginName) |
| public getPluginInfoByWebContents(webContents: WebContents): { | ||
| name: string | ||
| path: string | ||
| isInternal: boolean | ||
| canUseInternalApi: boolean | ||
| isBundledInternal: boolean | ||
| logo?: string | ||
| } | null { |
There was a problem hiding this comment.
为了提高代码的可读性和可维护性,建议为 getPluginInfoByWebContents 函数的返回值定义一个具名接口(例如 PluginInfo),而不是使用匿名对象类型。这样可以使类型意图更清晰,也便于在其他地方复用。
例如,可以在文件顶部或类外部定义一个接口:
interface PluginInfo {
name: string;
path: string;
canUseInternalApi: boolean;
isBundledInternal: boolean;
logo?: string;
}然后将函数签名修改为:
public getPluginInfoByWebContents(webContents: WebContents): PluginInfo | null {
No description provided.