diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 0b68de9dcbe2bebbe9c85af5bffa0789e1f7d359..f59a8672f74a1f44f641cc11334a22599beba1ed 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -275,9 +275,37 @@ impl Platform for WindowsPlatform { .detach(); } - // todo(windows) fn restart(&self) { - unimplemented!() + let pid = std::process::id(); + let Some(app_path) = self.app_path().log_err() else { + return; + }; + let script = format!( + r#" + $pidToWaitFor = {} + $exePath = "{}" + + while ($true) {{ + $process = Get-Process -Id $pidToWaitFor -ErrorAction SilentlyContinue + if (-not $process) {{ + Start-Process -FilePath $exePath + break + }} + Start-Sleep -Seconds 0.1 + }} + "#, + pid, + app_path.display(), + ); + let restart_process = std::process::Command::new("powershell.exe") + .arg("-command") + .arg(script) + .spawn(); + + match restart_process { + Ok(_) => self.quit(), + Err(e) => log::error!("failed to spawn restart script: {:?}", e), + } } // todo(windows) @@ -621,9 +649,8 @@ impl Platform for WindowsPlatform { } } - // todo(windows) fn app_path(&self) -> Result { - Err(anyhow!("not yet implemented")) + Ok(std::env::current_exe()?) } fn local_timezone(&self) -> UtcOffset {