桌面应用

LibreFang 桌面应用使用 Tauri 2.0 构建,提供原生桌面体验。


概述

LibreFang 桌面应用特点:

  • Tauri 2.0 原生应用
  • 系统托盘集成
  • 桌面通知
  • 全局快捷键
  • 单实例运行

安装

从源码构建

# 克隆仓库
git clone https://github.com/librefang/librefang.git
cd librefang

# 开发模式
cargo tauri dev

# 构建发布版本
cargo tauri build

功能

系统托盘

桌面应用包含系统托盘菜单:

选项说明
显示显示主窗口
浏览器打开仪表板
状态查看运行状态
退出退出应用

桌面通知

LibreFang 发送桌面通知:

  • Agent 完成消息
  • 工作流状态更新
  • 错误警报

全局快捷键

快捷键功能
Ctrl+Shift+L打开/关闭 LibreFang
Ctrl+Shift+C快速聊天

单实例

桌面应用强制单实例运行:

  • 第二个实例激活现有窗口
  • 防止重复进程

配置

托盘设置

[desktop]
tray_enabled = true
tray_icon = "default"

[notifications]
enabled = true
sound = true

快捷键设置

[shortcuts]
toggle = "Ctrl+Shift+L"
quick_chat = "Ctrl+Shift+C"

架构

工作原理

┌─────────────────────────────────────┐
           Desktop App
├─────────────────────────────────────┤
  Tauri 2.0
  ├── WebView (前端)                │
  ├── System Tray
  ├── Notifications
  └── Global Shortcuts
├─────────────────────────────────────┤
  Rust Backend
  ├── Kernel (进程内)               │
  ├── Axum Server (后台线程)        │
  └── IPC Commands
└─────────────────────────────────────┘

启动流程

  1. 应用启动
  2. 在进程内启动 LibreFang 内核
  3. 后台线程启动 Axum 服务器
  4. WebView 连接到本地服务器
  5. 系统托盘图标出现

开发

前端开发

# 安装依赖
cd librefang-desktop
npm install

# 开发模式
npm run tauri dev

# 构建
npm run tauri build

IPC 命令

// 获取端口
const port = await invoke<string>("get_port");

// 获取状态
const status = await invoke<Status>("get_status");

构建

Windows

cargo tauri build --target x86_64-pc-windows-msvc

macOS

cargo tauri build --target x86_64-apple-darwin
cargo tauri build --target aarch64-apple-darwin

Linux

cargo tauri build --target x86_64-unknown-linux-gnu

故障排除

应用不启动

# 查看日志
tail -f ~/.librefang/logs/desktop.log

# 检查依赖
cargo tauri info

托盘图标不显示

确保系统托盘支持已启用:

[desktop]
tray_enabled = true

通知不工作

检查通知权限:

# macOS
open SystemPreferences > Notifications

# Linux
notify-send "test" "LibreFang"