Skip to content

Commit

Permalink
feat: 过滤无效源
Browse files Browse the repository at this point in the history
  • Loading branch information
maotoumao committed Aug 31, 2023
1 parent 136d4ff commit a3a6e4e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/renderer/core/plugin-delegate/internal/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ export function useSupportedPlugin(
.filter((_) => _.supportedMethod.includes(featureMethod));
}

export function getSearchablePlugins(
supportedSearchType?: IMedia.SupportMediaType
) {
return getSupportedPlugin("search").filter((_) =>
supportedSearchType && _.supportedSearchType
? _.supportedSearchType.includes(supportedSearchType)
: true
);
}

export function getPluginByHash(hash: string) {
return delegatePluginsStore.getValue().find((item) => item.hash === hash);
}
Expand All @@ -38,10 +48,10 @@ export async function callPluginDelegateMethod<
method: T,
...args: Parameters<IPlugin.IPluginInstanceMethods[T]>
) {
return await ipcRendererInvoke("call-plugin-method", {
return (await ipcRendererInvoke("call-plugin-method", {
hash: pluginDelegate.hash,
platform: pluginDelegate.platform,
method,
args,
}) as ReturnType<IPlugin.IPluginInstanceMethods[T]>;
})) as ReturnType<IPlugin.IPluginInstanceMethods[T]>;
}
3 changes: 2 additions & 1 deletion src/renderer/pages/main-page/views/search-view/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
getSearchablePlugins,
getSupportedPlugin,
useSupportedPlugin,
} from "@/renderer/core/plugin-delegate";
Expand Down Expand Up @@ -68,7 +69,7 @@ export default function SearchView() {
<Tab.Panel className="tab-panel-container" key={type}>
<SearchResult
type={type}
plugins={plugins}
plugins={getSearchablePlugins(type)}
query={query}
></SearchResult>
</Tab.Panel>
Expand Down
2 changes: 2 additions & 0 deletions src/types/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ declare namespace IPlugin {
primaryKey?: string[];
/** 默认搜索类型 */
defaultSearchType?: IMedia.SupportMediaType;
/** 有效搜索类型 */
supportedSearchType?: ICommon.SupportMediaType[];
/** 插件缓存控制 */
cacheControl?: 'cache' | 'no-cache' | 'no-store';
/** 用户自定义输入 */
Expand Down

0 comments on commit a3a6e4e

Please sign in to comment.