feat: add parameter help icons with editable help.csv

This commit is contained in:
xin
2026-06-18 15:43:31 +08:00
parent c1a76a5875
commit c017129c9f
13 changed files with 243 additions and 229 deletions

2
src-tauri/Cargo.lock generated
View File

@ -3180,7 +3180,7 @@ dependencies = [
[[package]]
name = "spectral-insight-mission-plan"
version = "0.0.2"
version = "0.0.4"
dependencies = [
"byteorder",
"chrono",

View File

@ -1,6 +1,6 @@
[package]
name = "spectral-insight-mission-plan"
version = "0.0.4"
version = "0.0.5"
description = "Spectral Insight Mission Plan"
authors = ["you"]
edition = "2021"

View File

@ -0,0 +1,54 @@
use serde::Serialize;
use tauri::command;
use std::path::PathBuf;
#[derive(Debug, Serialize)]
pub struct HelpEntry {
pub key: String,
pub label: String,
pub description: String,
}
fn defaults_dir() -> PathBuf {
std::env::current_exe()
.unwrap_or_else(|_| PathBuf::from("."))
.parent()
.unwrap_or_else(|| std::path::Path::new("."))
.to_path_buf()
}
const DEFAULT_CSV: &str = include_str!("../../../help.csv");
#[command]
pub fn load_help_csv() -> Vec<HelpEntry> {
let path = defaults_dir().join("help.csv");
// Always write embedded default so file stays in sync with the binary
if let Some(parent) = path.parent() {
let _ = std::fs::create_dir_all(parent);
}
let _ = std::fs::write(&path, DEFAULT_CSV);
match std::fs::read_to_string(&path) {
Ok(c) => parse_csv(&c),
Err(_) => parse_csv(DEFAULT_CSV),
}
}
fn parse_csv(content: &str) -> Vec<HelpEntry> {
let mut entries = Vec::new();
for (i, line) in content.lines().enumerate() {
if i == 0 { continue; }
let trimmed = line.trim();
if trimmed.is_empty() { continue; }
let parts: Vec<&str> = trimmed.splitn(3, ',').collect();
if parts.len() == 3 {
entries.push(HelpEntry {
key: parts[0].trim().to_string(),
label: parts[1].trim().to_string(),
description: parts[2].trim().to_string(),
});
}
}
entries
}

View File

@ -4,3 +4,4 @@ pub mod validation_commands;
pub mod path_commands;
pub mod devtools_commands;
pub mod defaults_commands;
pub mod help_commands;

View File

@ -47,6 +47,7 @@ pub fn run() {
commands::defaults_commands::load_default_background,
commands::defaults_commands::save_planner_defaults,
commands::defaults_commands::load_planner_defaults,
commands::help_commands::load_help_csv,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");

View File

@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "Spectral Insight Mission Plan",
"version": "0.0.4",
"version": "0.0.5",
"identifier": "com.spectral-insight.mission-plan",
"build": {
"beforeDevCommand": "npm run dev",
@ -39,7 +39,8 @@
],
"resources": [
"../update.md",
"../说明书.md"
"../说明书.md",
"../help.csv"
],
"windows": {
"nsis": {