diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 57b5948..3a51880 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,12 +70,14 @@ jobs: if: matrix.os != 'windows-latest' run: | cp target/${{ matrix.target }}/release/wx ${{ matrix.asset }} + mkdir -p npm/platforms/${{ matrix.npm_dir }}/bin cp target/${{ matrix.target }}/release/wx npm/platforms/${{ matrix.npm_dir }}/bin/wx - name: Copy binary (Windows) if: matrix.os == 'windows-latest' run: | copy target\${{ matrix.target }}\release\wx.exe ${{ matrix.asset }} + if not exist npm\platforms\${{ matrix.npm_dir }}\bin mkdir npm\platforms\${{ matrix.npm_dir }}\bin copy target\${{ matrix.target }}\release\wx.exe npm\platforms\${{ matrix.npm_dir }}\bin\wx.exe - uses: actions/upload-artifact@v4 diff --git a/Cargo.toml b/Cargo.toml index 3b70b45..643e447 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,8 @@ pbkdf2 = "0.12" # 解压 zstd = "0.13" -# IPC (Unix socket + Windows named pipe 统一) +# IPC Windows named pipe(Unix 直接用 tokio::net::UnixListener) +[target.'cfg(windows)'.dependencies] interprocess = { version = "2", features = ["tokio"] } # 错误处理 diff --git a/src/cli/transport.rs b/src/cli/transport.rs index e0c4d05..01590a3 100644 --- a/src/cli/transport.rs +++ b/src/cli/transport.rs @@ -91,6 +91,7 @@ fn start_daemon() -> Result<()> { #[cfg(windows)] { + use std::os::windows::process::CommandExt; let log_file = std::fs::OpenOptions::new() .create(true).append(true) .open(config::log_path()) diff --git a/src/daemon/server.rs b/src/daemon/server.rs index 35eabe1..baa3b31 100644 --- a/src/daemon/server.rs +++ b/src/daemon/server.rs @@ -105,13 +105,41 @@ async fn serve_windows( let names2 = Arc::clone(&names); tokio::spawn(async move { - if let Err(e) = handle_connection_generic(conn, db2, names2).await { + if let Err(e) = handle_connection_windows(conn, db2, names2).await { eprintln!("[server] 连接处理错误: {}", e); } }); } } +#[cfg(windows)] +async fn handle_connection_windows( + conn: interprocess::local_socket::tokio::Stream, + db: Arc, + names: Arc>, +) -> Result<()> { + let (reader, mut writer) = tokio::io::split(conn); + let mut lines = BufReader::new(reader).lines(); + + let line = match lines.next_line().await? { + Some(l) => l, + None => return Ok(()), + }; + + let req: Request = match serde_json::from_str(&line) { + Ok(r) => r, + Err(e) => { + let resp = Response::err(format!("JSON 解析错误: {}", e)); + writer.write_all(resp.to_json_line()?.as_bytes()).await?; + return Ok(()); + } + }; + + let resp = dispatch(req, &db, &names).await; + writer.write_all(resp.to_json_line()?.as_bytes()).await?; + Ok(()) +} + async fn dispatch( req: Request, db: &DbCache,