Skip to content

Commit

Permalink
Implement basic WSL functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
htngr committed Jan 26, 2024
1 parent eb26ff5 commit 9d3ac78
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion codchi/src/ctrl/ipc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::ControllerServiceClient;
use super::RUNTIME;
use crate::consts::Dir;
use anyhow::bail;
use anyhow::{anyhow, Result};
use futures::Future;
use parity_tokio_ipc::Endpoint;
Expand All @@ -19,7 +20,7 @@ pub fn get_socket_path() -> Result<String> {
} else if cfg!(target_family = "windows") {
Ok(r"\\.\pipe\codchi.sock".to_string())
} else {
Err(anyhow!("Unsupported OS."))
bail!("Unsupported OS.")
}
}

Expand Down
25 changes: 24 additions & 1 deletion codchi/src/ctrl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,15 @@ mod utils {
#[cfg(target_family = "windows")]
pub fn daemonize() -> Result<bool> {
use crate::cli::*;
use crate::ctrl::ipc;
use crate::util::UtilExt;
use anyhow::bail;
use spinoff::*;
use std::env;
use std::os::windows::process::CommandExt;
use std::process::{exit, Command};
use std::process::Command;
use std::time::Duration;
use tokio::runtime::Runtime;
use windows::Win32::System::Threading::*;

let dir = Dir::Data.get_or_create()?;
Expand All @@ -190,6 +196,23 @@ mod utils {
.creation_flags(CREATE_NEW_PROCESS_GROUP.0 | CREATE_NO_WINDOW.0)
.spawn()?;

let mut spinner = Spinner::new_with_stream(
spinners::Dots,
"Starting controller in background...",
Color::Blue,
spinoff::Streams::Stderr,
);
Runtime::new()?
.block_on(async {
for _ in 0..15 {
if let Some(_) = ipc::connect_client_async().await? {
return Ok(());
}
tokio::time::sleep(Duration::from_millis(100)).await;
}
bail!("Failed to start controller within 2 second.");
})
.finally(|| spinner.clear())?;
// We're always the parent here
Ok(false)
}
Expand Down
2 changes: 1 addition & 1 deletion codchi/src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Driver for DriverImpl {

let names = wslapi::registry::distribution_names();
println!("{:#?}", names.collect::<OsString>());
todo!()
Ok(())
}

fn get_controller_fs(&self) -> anyhow::Result<std::path::PathBuf> {
Expand Down

0 comments on commit 9d3ac78

Please sign in to comment.