Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

windows: Implement `restart` action (#10234)

张小白c763c8c64b87
diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs
index 0b68de9dcbe..f59a8672f74 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<PathBuf> {
- Err(anyhow!("not yet implemented"))
+ Ok(std::env::current_exe()?)
}
fn local_timezone(&self) -> UtcOffset {