use super::Win32Shell;
use std::ops::{Deref, DerefMut};
use std::sync::{Mutex, MutexGuard};
static DESKTOP: Mutex<()> = Mutex::new(());
#[derive(Debug)]
pub(super) struct DesktopShell {
shell: Win32Shell,
_desktop: MutexGuard<'static, ()>,
}
pub(super) fn shell() -> DesktopShell {
let desktop = DESKTOP.lock().unwrap_or_else(|error| error.into_inner());
let shell = Win32Shell::open().expect(
"opening the Win32 shell needs a usable window station; a failure here is the \
runner's answer to whether it has one",
);
DesktopShell {
shell,
_desktop: desktop,
}
}
impl Deref for DesktopShell {
type Target = Win32Shell;
fn deref(&self) -> &Self::Target {
&self.shell
}
}
impl DerefMut for DesktopShell {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.shell
}
}
#[test]
fn the_fixture_holds_the_desktop_gate() {
let _shell = shell();
assert!(matches!(
DESKTOP.try_lock(),
Err(std::sync::TryLockError::WouldBlock)
));
}