mirror of https://github.com/jackwener/wx-cli.git
fix: isolate profile daemon pipe
parent
4028473ec4
commit
f78d96c898
|
|
@ -257,7 +257,8 @@ fn ping_unix() -> Result<bool> {
|
|||
fn ping_windows() -> Result<bool> {
|
||||
use interprocess::local_socket::{prelude::*, GenericNamespaced, Stream};
|
||||
|
||||
let name = "wx-cli-daemon".to_ns_name::<GenericNamespaced>()?;
|
||||
let pipe_name = config::local_socket_name();
|
||||
let name = pipe_name.as_str().to_ns_name::<GenericNamespaced>()?;
|
||||
let stream = Stream::connect(name)?;
|
||||
let mut reader = BufReader::new(stream);
|
||||
|
||||
|
|
@ -468,7 +469,9 @@ fn send_unix(req: Request) -> Result<Response> {
|
|||
fn send_windows(req: Request) -> Result<Response> {
|
||||
use interprocess::local_socket::{prelude::*, GenericNamespaced, Stream};
|
||||
|
||||
let name = "wx-cli-daemon"
|
||||
let pipe_name = config::local_socket_name();
|
||||
let name = pipe_name
|
||||
.as_str()
|
||||
.to_ns_name::<GenericNamespaced>()
|
||||
.context("构造 pipe name 失败")?;
|
||||
let stream = Stream::connect(name).context("连接 daemon named pipe 失败")?;
|
||||
|
|
|
|||
|
|
@ -249,6 +249,14 @@ pub fn log_path() -> PathBuf {
|
|||
cli_dir().join("daemon.log")
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn local_socket_name() -> String {
|
||||
match active_profile() {
|
||||
Some(profile) => format!("wx-cli-daemon-{}", profile),
|
||||
None => "wx-cli-daemon".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cache_dir() -> PathBuf {
|
||||
cli_dir().join("cache")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,13 +84,13 @@ async fn serve_windows(
|
|||
) -> Result<()> {
|
||||
use interprocess::local_socket::{tokio::prelude::*, GenericNamespaced, ListenerOptions};
|
||||
|
||||
// interprocess 的 GenericNamespaced 在 Windows 上会自动拼接 `\\.\pipe\` 前缀,
|
||||
// 这里必须传相对名;client 端用 `\\.\pipe\wx-cli-daemon` 直接打开可以对上
|
||||
let name = "wx-cli-daemon".to_ns_name::<GenericNamespaced>()?;
|
||||
// interprocess 的 GenericNamespaced 在 Windows 上会自动拼接 `\\.\pipe\` 前缀。
|
||||
let pipe_name = crate::config::local_socket_name();
|
||||
let name = pipe_name.as_str().to_ns_name::<GenericNamespaced>()?;
|
||||
let opts = ListenerOptions::new().name(name);
|
||||
let listener = opts.create_tokio()?;
|
||||
|
||||
eprintln!("[server] 监听 \\\\.\\pipe\\wx-cli-daemon");
|
||||
eprintln!("[server] 监听 \\\\.\\pipe\\{}", pipe_name);
|
||||
|
||||
loop {
|
||||
let conn = listener.accept().await?;
|
||||
|
|
|
|||
Loading…
Reference in New Issue