Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions crates/fastled-cli/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,18 @@ fn spawn_hidden_viewer(binary: &Path, url: &str) -> Result<ViewerProcess> {
/// viewer/WebView2 process tree is torn down too.
///
/// Returns a process handle whose lifetime controls the viewer lifetime.
///
/// Fails loudly when `url` is not an http(s) URL. The viewer must always be
/// pointed at the embedded HTTP server (which serves the loading page and
/// reloads on build completion); pointing it at a directory or `fastled://`
/// path regresses to a dead "Not Found" page (issues #151/#160).
pub fn launch_tauri_viewer(url: &str) -> Result<ViewerProcess> {
if !url.starts_with("http://") && !url.starts_with("https://") {
anyhow::bail!(
"viewer must be launched with an http(s) URL pointing at the FastLED server, got: {url}"
);
}

let binary =
find_tauri_viewer().context("fastled binary not found; cannot launch Tauri viewer")?;

Expand Down Expand Up @@ -520,6 +531,24 @@ mod tests {
assert_eq!(args, vec!["--internal-viewer", "http://127.0.0.1:8089"]);
}

#[test]
fn test_launch_tauri_viewer_rejects_directory_path() {
// Regression gate for #151/#160: the viewer must never be pointed at
// a filesystem path; it must load the FastLED HTTP server URL.
match launch_tauri_viewer("examples/TwinkleFox/fastled_js") {
Ok(_) => panic!("directory path must be rejected"),
Err(err) => assert!(err.to_string().contains("http(s) URL"), "got: {err}"),
}
}

#[test]
fn test_launch_tauri_viewer_rejects_fastled_protocol() {
match launch_tauri_viewer("fastled://localhost/index.html") {
Ok(_) => panic!("fastled:// protocol must be rejected"),
Err(err) => assert!(err.to_string().contains("http(s) URL"), "got: {err}"),
}
}

#[test]
#[cfg(windows)]
fn test_viewer_uses_hidden_process_creation_flags() {
Expand Down
Loading