feat(receiver): 持久化接收机发现端点并支持位置备注信息
This commit is contained in:
@@ -3,7 +3,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
fn collect(root: &Path, folder: &Path, output: &mut String) {
|
||||
fn collect(root: &Path, folder: &Path, url_prefix: &str, output: &mut String) {
|
||||
let mut files: Vec<_> = fs::read_dir(folder)
|
||||
.expect("frontend assets")
|
||||
.map(|f| f.unwrap().path())
|
||||
@@ -15,7 +15,7 @@ fn collect(root: &Path, folder: &Path, output: &mut String) {
|
||||
}
|
||||
assert!(!path.is_symlink(), "frontend assets must not be symlinks");
|
||||
if path.is_dir() {
|
||||
collect(root, &path, output);
|
||||
collect(root, &path, url_prefix, output);
|
||||
continue;
|
||||
}
|
||||
let relative = path
|
||||
@@ -29,32 +29,93 @@ fn collect(root: &Path, folder: &Path, output: &mut String) {
|
||||
"wasm" => "application/wasm",
|
||||
"css" => "text/css; charset=utf-8",
|
||||
"png" => "image/png",
|
||||
"ico" => "image/x-icon",
|
||||
"svg" => "image/svg+xml",
|
||||
"json" => "application/json",
|
||||
"wav" => "audio/wav",
|
||||
"txt" => "text/plain; charset=utf-8",
|
||||
_ => continue,
|
||||
};
|
||||
output.push_str(&format!(
|
||||
"{:?} => Some((include_bytes!({:?}), {:?})),\n",
|
||||
format!("/{relative}"),
|
||||
format!("{url_prefix}/{relative}"),
|
||||
path.to_string_lossy(),
|
||||
mime
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn embed_windows_icon(workbench: &Path, output: &Path) {
|
||||
if env::var("CARGO_CFG_TARGET_ENV").as_deref() != Ok("msvc") {
|
||||
return;
|
||||
}
|
||||
|
||||
let arch = env::var("CARGO_CFG_TARGET_ARCH").expect("Windows target architecture");
|
||||
let sdk = find_msvc_tools::find_windows_sdk(&arch).expect("Windows SDK required for RID icon");
|
||||
let compiler = sdk
|
||||
.path()
|
||||
.map(|path| path.join("rc.exe"))
|
||||
.find(|path| path.is_file())
|
||||
.expect("Windows SDK resource compiler (rc.exe)");
|
||||
|
||||
fs::copy(
|
||||
workbench.join("assets/rid-app.ico"),
|
||||
output.join("rid-app.ico"),
|
||||
)
|
||||
.expect("copy Windows application icon");
|
||||
fs::write(output.join("rid-app.rc"), "1 ICON \"rid-app.ico\"\r\n")
|
||||
.expect("write application icon resource script");
|
||||
let status = std::process::Command::new(compiler)
|
||||
.current_dir(output)
|
||||
.args(["/nologo", "/fo", "rid-app.res", "rid-app.rc"])
|
||||
.status()
|
||||
.expect("run Windows resource compiler");
|
||||
assert!(
|
||||
status.success(),
|
||||
"Windows application icon compilation failed"
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-link-arg-bin=fpv-rid-registry-fullstack={}",
|
||||
output.join("rid-app.res").display()
|
||||
);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("dist/web-ui");
|
||||
let project = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
let root = project.join("dist/web-ui");
|
||||
let workbench = project.join("crates/web-ui/workbench");
|
||||
let output_directory = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
println!("cargo:rerun-if-changed={}", root.display());
|
||||
println!("cargo:rerun-if-changed={}", workbench.display());
|
||||
#[cfg(windows)]
|
||||
embed_windows_icon(&workbench, &output_directory);
|
||||
if env::var_os("CARGO_FEATURE_PORTABLE").is_some() {
|
||||
println!("cargo:rerun-if-env-changed=RID_MAP_DOWNLOADER");
|
||||
let downloader = PathBuf::from(
|
||||
env::var_os("RID_MAP_DOWNLOADER")
|
||||
.expect("Build the map downloader for the portable target"),
|
||||
);
|
||||
println!("cargo:rerun-if-changed={}", downloader.display());
|
||||
fs::copy(downloader, output_directory.join("rid-map-downloader.bin"))
|
||||
.expect("embed the map downloader");
|
||||
}
|
||||
assert!(
|
||||
root.join("index.html").is_file(),
|
||||
"Build Rust frontend first: cargo xtask web"
|
||||
);
|
||||
let mut output = r#"pub fn resource(path: &str) -> Option<(&'static [u8], &'static str)> { let path = if path == "/" || path == "/realtime" { "/index.html" } else { path }; match path {
|
||||
let mut output = r#"pub fn resource(path: &str) -> Option<(&'static [u8], &'static str)> { let path = match path { "/" | "/realtime" | "/workbench/module.html" => "/index.html", "/workbench" | "/workbench/" => "/workbench/login.html", _ => path }; match path {
|
||||
"#.to_owned();
|
||||
collect(&root, &root, &mut output);
|
||||
collect(&root, &root, "", &mut output);
|
||||
collect(&workbench, &workbench, "/workbench", &mut output);
|
||||
if env::var_os("CARGO_FEATURE_PORTABLE").is_some() {
|
||||
let license = project.join("scripts/map-downloader/LICENSE-upstream.txt");
|
||||
println!("cargo:rerun-if-changed={}", license.display());
|
||||
output.push_str(&format!(
|
||||
"\"/map-downloader-LICENSE.txt\" => Some((include_bytes!({:?}), \"text/plain; charset=utf-8\")),\n",
|
||||
license.to_string_lossy(),
|
||||
));
|
||||
}
|
||||
output.push_str("_ => None } }\n");
|
||||
fs::write(
|
||||
PathBuf::from(env::var("OUT_DIR").unwrap()).join("web_assets.rs"),
|
||||
output,
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(output_directory.join("web_assets.rs"), output).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user