feat: image rendering, sidebar toggle, contribute section; fix: private repo update check; bump v0.2.1

This commit is contained in:
晴天
2026-03-04 20:47:00 +08:00
parent 59c84b5eaf
commit a6e1f40a59
14 changed files with 454 additions and 83 deletions

View File

@@ -14,7 +14,7 @@ const SCOPES: &[&str] = &[
];
/// 获取或生成设备密钥
fn get_or_create_key() -> Result<(String, String, SigningKey), String> {
pub(crate) fn get_or_create_key() -> Result<(String, String, SigningKey), String> {
let dir = super::openclaw_dir();
let path = dir.join(DEVICE_KEY_FILE);

View File

@@ -3,27 +3,12 @@
#[tauri::command]
pub fn auto_pair_device() -> Result<String, String> {
// 读取设备密钥
let device_key_path = crate::commands::openclaw_dir().join("clawpanel-device-key.json");
if !device_key_path.exists() {
return Err("设备密钥文件不存在".into());
}
// 无论是否已配对,都确保 gateway.controlUi.allowedOrigins 已写入
// 必须在最前面,避免因设备密钥不存在而跳过
patch_gateway_origins();
let device_key_content =
std::fs::read_to_string(&device_key_path).map_err(|e| format!("读取设备密钥失败: {e}"))?;
let device_key: serde_json::Value =
serde_json::from_str(&device_key_content).map_err(|e| format!("解析设备密钥失败: {e}"))?;
let device_id = device_key["deviceId"]
.as_str()
.ok_or("设备 ID 不存在")?
.to_string();
let public_key = device_key["publicKey"]
.as_str()
.ok_or("公钥不存在")?
.to_string();
// 获取或生成设备密钥(首次安装时自动创建)
let (device_id, public_key, _) = super::device::get_or_create_key()?;
// 读取或创建 paired.json
let paired_path = crate::commands::openclaw_dir()
@@ -44,9 +29,6 @@ pub fn auto_pair_device() -> Result<String, String> {
serde_json::json!({})
};
// 无论是否已配对,都确保 gateway.controlUi.allowedOrigins 已写入
patch_gateway_origins();
let os_platform = std::env::consts::OS; // "windows" | "macos" | "linux"
// 如果已配对,档查 platform 字段是否正确;不正确则覆盖更新,
@@ -116,9 +98,6 @@ pub fn auto_pair_device() -> Result<String, String> {
std::fs::write(&paired_path, new_content).map_err(|e| format!("写入 paired.json 失败: {e}"))?;
// 同步写入 controlUi.allowedOrigins允许 Tauri 的 origin 连接 Gateway
patch_gateway_origins();
Ok("设备配对成功".into())
}