```
feat(protocol): Observation坐标字段可选化及协议v2扩展 - 将Observation中longitude/latitude/altitude_m/heading_deg改为Option类型, 支持无位置信息的观测数据 - 新增DeviceTelemetry结构体承载设备遥测扩展字段(serial, mac, model, rssi, speed, vertical_speed, pressure_altitude, geometric_altitude, height_agl, pilot_position等) - 新增LegacyObservation兼容结构体及From转换,保持旧接收器协议输入兼容 - PROTOCOL_VERSION从1升至2 - 新增coordinates()辅助方法统一提取有效坐标 - validate()适配Option类型,允许坐标字段同时缺失 - Store新增position_generation机制追踪位置可用性变化,确保合并帧间的 位置丢失仍能正确断开轨迹 - geofence-map-adapter过滤无效坐标避免渲染异常 - 新增appearance.css外观主题系统,支持blue/graphite/white三套配色 ```
This commit is contained in:
@@ -13,6 +13,7 @@ use web_sys::{
|
||||
|
||||
struct State {
|
||||
prefs: Value,
|
||||
saved: Value,
|
||||
generation: u64,
|
||||
busy: bool,
|
||||
ready: bool,
|
||||
@@ -67,7 +68,7 @@ fn each(selector: &str, mut f: impl FnMut(Element)) {
|
||||
fn apply(state: &Shared) {
|
||||
let s = state.borrow();
|
||||
let p = &s.prefs;
|
||||
let theme = p["theme"].as_str().unwrap_or("graphite");
|
||||
let theme = p["theme"].as_str().unwrap_or("blue");
|
||||
if let Some(body) = document().body() {
|
||||
let _ = body.set_attribute("data-theme", theme);
|
||||
let _ = body.set_attribute(
|
||||
@@ -78,13 +79,12 @@ fn apply(state: &Shared) {
|
||||
"false"
|
||||
},
|
||||
);
|
||||
// Legacy preference values remain intact; all use the approved dark material.
|
||||
let _ = body.set_attribute("class", "b R2 theme-graphite");
|
||||
let _ = body.set_attribute("class", &format!("b R2 theme-{theme}"));
|
||||
}
|
||||
let image = p["image"].as_str().map(str::to_owned).unwrap_or_else(|| {
|
||||
format!(
|
||||
"/wallpapers/{}-wallpaper.svg",
|
||||
p["wallpaper"].as_str().unwrap_or("B4")
|
||||
p["wallpaper"].as_str().unwrap_or("B5")
|
||||
)
|
||||
});
|
||||
if let Some(w) = el("workspace-wallpaper") {
|
||||
@@ -119,7 +119,32 @@ fn apply(state: &Shared) {
|
||||
if let Some(fit) = el("fit").and_then(|e| e.dyn_into::<HtmlSelectElement>().ok()) {
|
||||
fit.set_value(p["fit"].as_str().unwrap_or("cover"));
|
||||
}
|
||||
text("theme-name", "深海蓝玻璃");
|
||||
let (name, material, opacity) = match theme {
|
||||
"graphite" => ("石墨灰玻璃", "石墨灰 · 柔透", "72%"),
|
||||
"white" => ("透明白玻璃", "透明白 · 轻透", "84%"),
|
||||
_ => ("深海蓝玻璃", "深海蓝 · 高透", "40%"),
|
||||
};
|
||||
text("theme-name", name);
|
||||
text("appearance-theme-name", name);
|
||||
text("appearance-material", material);
|
||||
text("appearance-opacity", opacity);
|
||||
if let Some(button) = el("theme-shortcut") {
|
||||
let _ = button.set_attribute("aria-label", &format!("当前色调:{name},打开色调选择"));
|
||||
}
|
||||
each("[data-appearance-theme]", |e| {
|
||||
let active = e.get_attribute("data-appearance-theme").as_deref() == Some(theme);
|
||||
let _ = e.set_attribute("aria-pressed", if active { "true" } else { "false" });
|
||||
});
|
||||
each(
|
||||
"#appearance-wallpaper-controls button, #appearance-display input, #appearance-display select, #reset-wallpaper",
|
||||
|e| {
|
||||
if s.ready {
|
||||
let _ = e.remove_attribute("disabled");
|
||||
} else {
|
||||
let _ = e.set_attribute("disabled", "");
|
||||
}
|
||||
},
|
||||
);
|
||||
each("[data-wall]", |e| {
|
||||
let active = p["image"].is_null()
|
||||
&& e.get_attribute("data-wall").as_deref() == p["wallpaper"].as_str();
|
||||
@@ -153,7 +178,7 @@ fn apply(state: &Shared) {
|
||||
let wallpaper_name = if p["image"].is_string() {
|
||||
"自定义壁纸"
|
||||
} else {
|
||||
match p["wallpaper"].as_str().unwrap_or("B4") {
|
||||
match p["wallpaper"].as_str().unwrap_or("B5") {
|
||||
"B1" => "黑曜石柔光",
|
||||
"B2" => "午夜蓝丝绸",
|
||||
"B3" => "石墨空间玻璃",
|
||||
@@ -181,7 +206,7 @@ async fn fetch_preferences(state: Shared) {
|
||||
let r = Request::get("/api/appearance")
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(|_| "无法连接本机应用,请重新打开设置重试".to_owned())?;
|
||||
if !r.ok() {
|
||||
return Err("无法读取本机外观设置".into());
|
||||
}
|
||||
@@ -198,10 +223,17 @@ async fn fetch_preferences(state: Shared) {
|
||||
{
|
||||
return;
|
||||
}
|
||||
s.saved = p.clone();
|
||||
s.prefs = p;
|
||||
s.ready = true;
|
||||
drop(s);
|
||||
apply(&state);
|
||||
if el("wall-message").is_some_and(|e| {
|
||||
e.get_attribute("class")
|
||||
.is_some_and(|classes| classes.split_whitespace().any(|c| c == "error"))
|
||||
}) {
|
||||
message("已重新加载本机外观,可以继续调整。", false);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let s = state.borrow();
|
||||
@@ -240,7 +272,7 @@ fn queue_save(state: Shared) {
|
||||
.map_err(|e| e.to_string())?
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(|_| "无法连接本机应用".to_owned())?;
|
||||
let p = r.json::<Value>().await.map_err(|e| e.to_string())?;
|
||||
if !r.ok() {
|
||||
return Err(p["error"].as_str().unwrap_or("保存失败").to_owned());
|
||||
@@ -252,6 +284,7 @@ fn queue_save(state: Shared) {
|
||||
Ok(saved) => {
|
||||
let mut s = state.borrow_mut();
|
||||
s.prefs["revision"] = saved["revision"].clone();
|
||||
s.saved = saved;
|
||||
if s.generation == version {
|
||||
s.busy = false;
|
||||
s.dirty = false;
|
||||
@@ -268,9 +301,16 @@ fn queue_save(state: Shared) {
|
||||
let mut s = state.borrow_mut();
|
||||
s.busy = false;
|
||||
s.dirty = false;
|
||||
s.generation += 1;
|
||||
s.prefs = s.saved.clone();
|
||||
s.ready = false;
|
||||
}
|
||||
apply(&state);
|
||||
fetch_preferences(state.clone()).await;
|
||||
message(&e, true);
|
||||
message(
|
||||
&format!("保存未完成:{e}。已恢复已保存的外观,请重新打开设置重试。"),
|
||||
true,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -536,7 +576,8 @@ pub fn init(realtime: bool) {
|
||||
}
|
||||
restored.forget();
|
||||
let state = Rc::new(RefCell::new(State {
|
||||
prefs: json!({"theme":"graphite","wallpaper":"B4","dim":14,"blur":0,"fit":"cover","image":null,"revision":0}),
|
||||
prefs: json!({"theme":"blue","wallpaper":"B5","dim":14,"blur":0,"fit":"cover","image":null,"revision":0}),
|
||||
saved: json!({"theme":"blue","wallpaper":"B5","dim":14,"blur":0,"fit":"cover","image":null,"revision":0}),
|
||||
generation: 0,
|
||||
busy: false,
|
||||
ready: false,
|
||||
@@ -591,6 +632,8 @@ pub fn init(realtime: bool) {
|
||||
"archives"
|
||||
} else if search.contains("app=register") {
|
||||
"register"
|
||||
} else if search.contains("app=settings") {
|
||||
"settings"
|
||||
} else {
|
||||
"home"
|
||||
},
|
||||
@@ -623,6 +666,13 @@ pub fn init(realtime: bool) {
|
||||
}
|
||||
if let Some(view) = button.get_attribute("data-open") {
|
||||
show(&view, realtime);
|
||||
if button.id() == "theme-shortcut"
|
||||
&& let Some(region) =
|
||||
el("appearance-themes").and_then(|e| e.dyn_into::<HtmlElement>().ok())
|
||||
{
|
||||
region.scroll_into_view();
|
||||
let _ = region.focus();
|
||||
}
|
||||
if matches!(view.as_str(), "settings" | "display") {
|
||||
let s = clicked.clone();
|
||||
spawn_local(async move {
|
||||
@@ -631,6 +681,16 @@ pub fn init(realtime: bool) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(theme) = button.get_attribute("data-appearance-theme") {
|
||||
if clicked.borrow().ready
|
||||
&& matches!(theme.as_str(), "graphite" | "blue" | "white")
|
||||
&& clicked.borrow().prefs["theme"].as_str() != Some(theme.as_str())
|
||||
{
|
||||
clicked.borrow_mut().prefs["theme"] = json!(theme);
|
||||
queue_save(clicked.clone());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(wall) = button.get_attribute("data-wall") {
|
||||
if clicked.borrow().ready {
|
||||
let mut s = clicked.borrow_mut();
|
||||
@@ -671,7 +731,7 @@ pub fn init(realtime: bool) {
|
||||
"reset-wallpaper" => {
|
||||
if clicked.borrow().ready {
|
||||
let rev = clicked.borrow().prefs["revision"].clone();
|
||||
clicked.borrow_mut().prefs = json!({"theme":"graphite","wallpaper":"B4","dim":14,"blur":0,"fit":"cover","image":null,"revision":rev});
|
||||
clicked.borrow_mut().prefs = json!({"theme":"blue","wallpaper":"B5","dim":14,"blur":0,"fit":"cover","image":null,"revision":rev});
|
||||
queue_save(clicked.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user