13 lines
581 B
TypeScript
13 lines
581 B
TypeScript
// 渲染层 IPC 调用封装:类型安全,禁止接触绝对路径
|
|
import type { BridgeApi, IpcMap } from '@hunter/shared';
|
|
|
|
declare global { interface Window { dsh?: BridgeApi } }
|
|
|
|
function getBridge(): BridgeApi {
|
|
if (!window.dsh) throw new Error('IPC bridge 未就绪:window.dsh 不存在(preload 可能未加载)');
|
|
return window.dsh;
|
|
}
|
|
|
|
export const invoke: BridgeApi['invoke'] = (channel, args) => getBridge().invoke(channel, args as never) as Promise<never>;
|
|
export const send: BridgeApi['send'] = (channel, args) => getBridge().send(channel, args as never);
|