mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-25 06:24:56 +00:00
Closes https://github.com/zed-industries/zed/issues/33748 Release Notes: - Windows is now supported as a target platform for SSH remoting. --------- Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
48 lines
1.6 KiB
Rust
48 lines
1.6 KiB
Rust
use windows::Win32::System::Com::{
|
|
CLSCTX_LOCAL_SERVER, COINIT_APARTMENTTHREADED, CoCreateInstance, CoInitializeEx, IDispatch,
|
|
IServiceProvider,
|
|
};
|
|
use windows::Win32::System::Variant::VARIANT;
|
|
use windows::Win32::UI::Shell::{
|
|
CSIDL_DESKTOP, IShellBrowser, IShellDispatch2, IShellFolderViewDual, IShellWindows,
|
|
SID_STopLevelBrowser, SVGIO_BACKGROUND, SWC_DESKTOP, SWFO_NEEDDISPATCH, ShellWindows,
|
|
};
|
|
use windows::core::{BSTR, Interface};
|
|
|
|
pub fn shell_execute_from_explorer(
|
|
file: &str,
|
|
parameters: &str,
|
|
directory: &str,
|
|
) -> anyhow::Result<()> {
|
|
unsafe {
|
|
CoInitializeEx(None, COINIT_APARTMENTTHREADED).unwrap();
|
|
|
|
let mut _hwnd = Default::default();
|
|
let shell_dispatch: IShellDispatch2 =
|
|
CoCreateInstance::<_, IShellWindows>(&ShellWindows, None, CLSCTX_LOCAL_SERVER)?
|
|
.FindWindowSW(
|
|
&VARIANT::from(CSIDL_DESKTOP as i32),
|
|
&VARIANT::default(),
|
|
SWC_DESKTOP,
|
|
&mut _hwnd,
|
|
SWFO_NEEDDISPATCH,
|
|
)?
|
|
.cast::<IServiceProvider>()?
|
|
.QueryService::<IShellBrowser>(&SID_STopLevelBrowser)?
|
|
.QueryActiveShellView()?
|
|
.GetItemObject::<IDispatch>(SVGIO_BACKGROUND)?
|
|
.cast::<IShellFolderViewDual>()?
|
|
.Application()?
|
|
.cast()?;
|
|
|
|
shell_dispatch.ShellExecute(
|
|
&BSTR::from(file),
|
|
&VARIANT::from(parameters),
|
|
&VARIANT::from(directory),
|
|
&VARIANT::from(""),
|
|
&VARIANT::from(0i32),
|
|
)?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|