Embed yt-dlp into the binary so the standalone exe is self-contained (extract to cache on first run); drop now-redundant resource bundle; refresh Windows installers

This commit is contained in:
Jonathan Sykes
2026-06-14 11:44:29 +08:00
parent 63560a8e61
commit fed2aef969
5 changed files with 32 additions and 5 deletions

Binary file not shown.

View File

@@ -21,7 +21,31 @@ use tauri::Manager;
const SEARCH_LIMIT: u32 = 25;
/// Locate yt-dlp: prefer the bundled resource copy, then a dev ./bin, then PATH.
// yt-dlp.exe is baked straight into this binary at compile time, so the standalone
// `ytplayer.exe` is fully self-contained — no sibling file and nothing on PATH
// required. On first run we materialize it into the app cache dir and run from there.
// (Windows only; other platforms fall back to a resource/dev/PATH copy.)
#[cfg(windows)]
static YTDLP_EMBEDDED: &[u8] = include_bytes!("../../bin/yt-dlp.exe");
/// Write the embedded yt-dlp to the cache dir if it isn't already there (size-checked),
/// and return its path.
#[cfg(windows)]
fn embedded_ytdlp(app: &tauri::AppHandle) -> Option<PathBuf> {
let dir = app.path().app_cache_dir().ok()?;
std::fs::create_dir_all(&dir).ok()?;
let dest = dir.join("yt-dlp.exe");
let fresh = std::fs::metadata(&dest)
.map(|m| m.len() == YTDLP_EMBEDDED.len() as u64)
.unwrap_or(false);
if !fresh {
std::fs::write(&dest, YTDLP_EMBEDDED).ok()?;
}
Some(dest)
}
/// Locate yt-dlp: prefer a bundled resource copy, then a dev ./bin, then the
/// embedded self-contained copy (Windows), then finally PATH.
fn ytdlp_path(app: &tauri::AppHandle) -> PathBuf {
let name = if cfg!(windows) { "yt-dlp.exe" } else { "yt-dlp" };
if let Ok(res) = app.path().resource_dir() {
@@ -34,6 +58,12 @@ fn ytdlp_path(app: &tauri::AppHandle) -> PathBuf {
if dev.exists() {
return dev;
}
#[cfg(windows)]
{
if let Some(p) = embedded_ytdlp(app) {
return p;
}
}
PathBuf::from(name)
}

View File

@@ -35,9 +35,6 @@
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"resources": {
"../bin/yt-dlp.exe": "bin/yt-dlp.exe"
}
]
}
}