Desktop

作者 lobehub6a3eba96b010无许可证83K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Electron desktop development guide — IPC handlers, controllers, preload scripts, window/menu management.

AI 生成的概览

指导 LobeHub 的 Electron 桌面开发:IPC 处理程序、控制器、预加载脚本以及窗口和菜单管理。

功能
该技能提供架构概览和分步说明,用于为 Electron 应用添加桌面功能,涵盖控制器、IPC 类型定义、渲染进程服务、store 操作和测试。它指向关于功能实现、本地工具、菜单配置和窗口管理的参考文档。它产出的是指导和代码模式,而不是生成的文件。
适用场景
在实现或扩展 Electron 桌面功能时使用,例如新的 IPC 方法、控制器、预加载暴露、菜单或窗口。它面向在 LobeHub 桌面代码库中工作的开发者。
运行要求
不附带脚本,仅为说明文档。它假定存在具有所述目录结构的 Electron 项目和 TypeScript 工具链。

Desktop Development Guide

Architecture Overview

LobeHub desktop is built on Electron with main-renderer architecture:

  1. Main Process (apps/desktop/src/main): App lifecycle, system APIs, window management
  2. Renderer Process: Reuses web code from src/
  3. Preload Scripts (apps/desktop/src/preload): Securely expose main process to renderer

Adding New Desktop Features

1. Create Controller

Location: apps/desktop/src/main/controllers/

typescript
import { ControllerModule, IpcMethod } from '@/controllers';
export default class NewFeatureCtr extends ControllerModule {  static override readonly groupName = 'newFeature';
  @IpcMethod()  async doSomething(params: SomeParams): Promise<SomeResult> {    // Implementation    return { success: true };  }}

Register in apps/desktop/src/main/controllers/registry.ts.

2. Define IPC Types

Location: packages/electron-client-ipc/src/types/<domain>.ts, re-exported from types/index.ts

typescript
export interface SomeParams {  /* ... */}export interface SomeResult {  success: boolean;  error?: string;}

3. Create Renderer Service

Location: src/services/electron/

typescript
import { ensureElectronIpc } from '@/utils/electron/ipc';
const ipc = ensureElectronIpc();
export const newFeatureService = async (params: SomeParams) => {  return ipc.newFeature.doSomething(params);};

4. Implement Store Action

Location: src/store/

5. Add Tests

Location: apps/desktop/src/main/controllers/__tests__/

Detailed Guides

See references/ for specific topics:

  • Feature implementation: references/feature-implementation.md
  • Local tools workflow: references/local-tools.md
  • Menu configuration: references/menu-config.md
  • Window management: references/window-management.md

来源与署名

来源:lobehub/lobehub位于.agents/skills/desktop提交6a3eba9

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架