chore(tauri): 移除 npc 内网穿透客户端逻辑

- lib.rs:删除 setup_npc 后台线程启动与等待
- server.rs:删除 setup_npc 函数及 Cursor 导入
- Cargo.toml:移除 zip 依赖
- public/npc.zip:删除嵌入资源
This commit is contained in:
Pine
2026-08-18 01:41:14 +08:00
parent 2358d992c3
commit fe66831052
4 changed files with 0 additions and 118 deletions
BIN
View File
Binary file not shown.
-1
View File
@@ -29,4 +29,3 @@ dirs = "6"
futures = "0.3"
tokio-stream = { version = "0.1", features = ["sync"] }
rust-embed = "8"
zip = "2"
-10
View File
@@ -3,18 +3,8 @@ mod models;
mod server;
mod storage;
use std::time::Duration;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
// 在后台线程启动 npc 内网穿透客户端
std::thread::spawn(|| {
server::setup_npc();
});
// 等待内网穿透就绪(可选,不阻塞)
std::thread::sleep(Duration::from_millis(200));
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_autostart::init(
-107
View File
@@ -14,7 +14,6 @@ use chrono::Local;
use futures::stream::Stream;
use rust_embed::RustEmbed;
use std::convert::Infallible;
use std::io::Cursor;
use std::path::PathBuf;
use std::sync::Arc;
use std::fs;
@@ -585,109 +584,3 @@ async fn sse_handler() -> Sse<impl Stream<Item = Result<Event, Infallible>>> {
)
}
// ===================== NPC 内网穿透客户端 =====================
/// 多平台兼容:
/// - Windows: 二进制名为 npc.exe
/// - macOS/Linux: 二进制名为 npc
/// 每次启动检查持久化目录(与 data.json 同一目录下的 npc/)中是否存在,
/// 不存在则从嵌入式 npc.zip 解压。
pub fn setup_npc() {
// 开发环境(macOS)跳过:嵌入的 npc 是 Linux/Windows 二进制,mac 上无法执行,
// 且开发机不需要内网穿透(npc 仅生产部署时把内网大屏机穿透到公网服务器)
if cfg!(target_os = "macos") {
println!("[dpm] macOS 开发模式:跳过内网穿透客户端(npc 仅 Windows 生产部署使用)");
return;
}
let data_dir = dirs::data_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join("dpm")
.join("npc");
if let Err(e) = fs::create_dir_all(&data_dir) {
eprintln!("[dpm] 无法创建 npc 目录 ({}): {}", data_dir.display(), e);
return;
}
// 根据平台确定二进制文件名
let exe_name = if cfg!(target_os = "windows") {
"npc.exe"
} else {
"npc"
};
let exe_path = data_dir.join(exe_name);
// 检查文件是否已存在,不存在则从嵌入式 zip 解压
if !exe_path.exists() {
let zip_data = match Asset::get("npc.zip") {
Some(data) => data,
None => {
eprintln!("[dpm] 警告: npc.zip 未嵌入到程序中,跳过");
return;
}
};
let cursor = Cursor::new(zip_data.data);
let mut archive = match zip::ZipArchive::new(cursor) {
Ok(a) => a,
Err(e) => {
eprintln!("[dpm] npc.zip 解压失败: {}", e);
return;
}
};
let mut extracted = false;
for i in 0..archive.len() {
let mut file = match archive.by_index(i) {
Ok(f) => f,
Err(_) => continue,
};
// 兼容 zip 中二进制名为 npc.exe 或 npc 的情况
let name = file.name().trim_end_matches('/');
let is_match = name == "npc.exe" || name == "npc" || name == exe_name;
if is_match {
if let Err(e) = fs::File::create(&exe_path)
.and_then(|mut out| std::io::copy(&mut file, &mut out).map(|_| ()))
{
eprintln!("[dpm] {} 写入失败: {}", exe_name, e);
return;
}
extracted = true;
break;
}
}
if !extracted {
eprintln!("[dpm] npc.zip 中未找到 npc/npc.exe");
return;
}
// Unix 平台设置可执行权限
#[cfg(not(target_os = "windows"))]
{
use std::os::unix::fs::PermissionsExt;
if let Err(e) = fs::set_permissions(&exe_path, fs::Permissions::from_mode(0o755)) {
eprintln!("[dpm] 设置执行权限失败: {}", e);
}
}
println!("[dpm] npc 客户端已解压到 {}", exe_path.display());
}
println!("[dpm] 启动 npc 客户端...");
match std::process::Command::new(&exe_path)
.args([
"-server=47.108.226.213:8024",
"-vkey=wos4sgm6aobhq04y",
"-type=tcp",
])
.current_dir(&data_dir)
.spawn()
{
Ok(child) => {
println!("[dpm] npc 进程已启动, pid: {}", child.id());
}
Err(e) => {
eprintln!("[dpm] npc 启动失败: {}", e);
}
}
}