hololake-system-architecture/product-source/hololake-desktop/electron/preload.ts

45 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* HoloLake Desktop · Preload 脚本
*
* 在渲染进程和主进程之间建立安全桥梁。
* 渲染进程不能直接访问 Node.js API只能通过这个桥梁通信。
*/
import { contextBridge, ipcRenderer } from 'electron';
// 暴露给渲染进程的安全 API
contextBridge.exposeInMainWorld('hololake', {
// 应用信息
platform: process.platform,
version: '0.8.0',
// 数据目录
getDataPath: () => ipcRenderer.invoke('get-data-path'),
knowledge: {
importFolder: () => ipcRenderer.invoke('knowledge:import-folder'),
},
agent: {
getConfig: () => ipcRenderer.invoke('agent:get-config'),
saveConfig: (config: { baseUrl: string; model: string; apiKey?: string }) =>
ipcRenderer.invoke('agent:save-config', config),
testConfig: () => ipcRenderer.invoke('agent:test-config'),
},
server: {
list: () => ipcRenderer.invoke('server:list'),
connect: (nodeId: string) => ipcRenderer.invoke('server:connect', nodeId),
domainRegistry: () => ipcRenderer.invoke('server:domain-registry'),
session: (nodeId?: string) => ipcRenderer.invoke('server:session', nodeId),
login: (input: { nodeId: string; username: string; password: string }) =>
ipcRenderer.invoke('server:login', input),
logout: () => ipcRenderer.invoke('server:logout'),
repositories: () => ipcRenderer.invoke('server:repositories'),
createRepository: (input: { name: string; description?: string }) =>
ipcRenderer.invoke('server:create-repository', input),
gitRemote: (fullName: string) => ipcRenderer.invoke('server:git-remote', fullName),
},
// Forgejo 通过本地知识库 API 管理;此桥只保留非敏感应用信息。
});