feat: enhance ADB path resolution and update HTTP request handling for improved flexibility
This commit is contained in:
+60
-7
@@ -18,13 +18,64 @@ fn repo_root() -> PathBuf {
|
||||
.expect("项目根目录")
|
||||
}
|
||||
|
||||
fn python_command(root: &Path) -> PathBuf {
|
||||
let bundled = root.join("server").join(".venv").join("Scripts").join("python.exe");
|
||||
if bundled.is_file() {
|
||||
bundled
|
||||
} else {
|
||||
PathBuf::from("python")
|
||||
fn app_root() -> PathBuf {
|
||||
if cfg!(debug_assertions) {
|
||||
return repo_root();
|
||||
}
|
||||
std::env::current_exe()
|
||||
.ok()
|
||||
.and_then(|path| path.parent().map(Path::to_path_buf))
|
||||
.filter(|path| path.join("server").is_dir())
|
||||
.unwrap_or_else(repo_root)
|
||||
}
|
||||
|
||||
fn python_command(root: &Path) -> PathBuf {
|
||||
let candidates = [
|
||||
root.join("runtime").join("python").join("python.exe"),
|
||||
root.join("runtime").join("python").join("bin").join("python3"),
|
||||
root.join("server").join(".venv").join("Scripts").join("python.exe"),
|
||||
root.join("server").join(".venv").join("bin").join("python3"),
|
||||
];
|
||||
for candidate in candidates {
|
||||
if candidate.is_file() {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
PathBuf::from(if cfg!(windows) { "python" } else { "python3" })
|
||||
}
|
||||
|
||||
fn prepare_webview_runtime(root: &Path) {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if webview_runtime_installed() {
|
||||
return;
|
||||
}
|
||||
let installer = root
|
||||
.join("vendor")
|
||||
.join("webview2")
|
||||
.join("MicrosoftEdgeWebView2RuntimeInstallerX64.exe");
|
||||
if installer.is_file() {
|
||||
let _ = Command::new(installer).args(["/silent", "/install"]).status();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn webview_runtime_installed() -> bool {
|
||||
let keys = [
|
||||
r"HKLM\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}",
|
||||
r"HKLM\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}",
|
||||
r"HKCU\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}",
|
||||
];
|
||||
keys.iter().any(|key| {
|
||||
Command::new("reg")
|
||||
.args(["query", key, "/v", "pv"])
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.status()
|
||||
.map(|status| status.success())
|
||||
.unwrap_or(false)
|
||||
})
|
||||
}
|
||||
|
||||
fn free_port() -> Result<u16, String> {
|
||||
@@ -148,7 +199,7 @@ fn disable_browser_chrome(window: &tauri::WebviewWindow) {
|
||||
}
|
||||
|
||||
fn boot(handle: &AppHandle, window: &tauri::WebviewWindow) -> Result<(), String> {
|
||||
let root = repo_root();
|
||||
let root = app_root();
|
||||
let mut last_error = "后台启动超时".to_string();
|
||||
for _ in 0..3 {
|
||||
let port = free_port()?;
|
||||
@@ -179,6 +230,8 @@ fn boot(handle: &AppHandle, window: &tauri::WebviewWindow) -> Result<(), String>
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let root = app_root();
|
||||
prepare_webview_runtime(&root);
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
|
||||
Reference in New Issue
Block a user