桌面客户端开发_desktop

以下为本文档的中文说明

desktop 技能是 LobeHub 开源 AI 助手平台的桌面客户端应用开发工具包。LobeHub 是一个功能丰富的开源 AI 助手平台,支持多模型接入、插件扩展和个性化配置。该技能专注于平台桌面版本(基于 Electron 框架)的功能开发和维护。使用场景包括:开发或修改 LobeHub 桌面应用的用户界面组件和布局、实现桌面平台特有的功能(如系统托盘最小化、全局快捷键绑定、原生菜单栏等)、优化桌面应用的启动性能、内存占用和电池续航等方面的表现。核心特点包括:提供 LobeHub 桌面应用项目的完整目录结构和代码组织规范,帮助新开发者快速理解项目架构;详细说明 Electron 主进程(Main Process)和渲染进程(Renderer Process)之间的进程间通信(IPC)机制;支持系统托盘(Tray)图标的创建、上下文菜单配置和通知消息显示;实现全局快捷键(Global Shortcut)的注册、冲突检测和事件处理;包含自动更新(Auto Update)机制的配置方法,支持 Windows、macOS 和 Linux 三平台;提供各操作系统原生集成的最佳实践指南,如 macOS 的菜单栏和 Dock 图标行为、Windows 的任务栏缩略图工具栏和跳转列表。该技能帮助开发者高效地维护和增强 LobeHub 的桌面端用户体验。


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 fromsrc/
  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/

import{ControllerModule,IpcMethod}from'@/controllers';exportdefaultclassNewFeatureCtrextendsControllerModule{staticoverridereadonlygroupName='newFeature';@IpcMethod()asyncdoSomething(params:SomeParams):Promise<SomeResult>{// Implementationreturn{success:true};}}

Register inapps/desktop/src/main/controllers/registry.ts.

2. Define IPC Types

Location:packages/electron-client-ipc/src/types.ts

exportinterfaceSomeParams{/* ... */}exportinterfaceSomeResult{success:boolean;error?:string;}

3. Create Renderer Service

Location:src/services/electron/

import{ensureElectronIpc}from'@/utils/electron/ipc';constipc=ensureElectronIpc();exportconstnewFeatureService=async(params:SomeParams)=>{returnipc.newFeature.doSomething(params);};

4. Implement Store Action

Location:src/store/

5. Add Tests

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

Detailed Guides

Seereferences/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

Best Practices

  1. Security: Validate inputs, limit exposed APIs
  2. Performance: Use async methods, batch data transfers
  3. UX: Add progress indicators, provide error feedback
  4. Code organization: Follow existing patterns, add documentation