use crate::winrt::{IInspectable, IActivationFactory};
use crate::error::Result;
use windows::core::IInspectable as CoreIInspectable;
#[derive(Clone)]
pub struct XamlWindow {
inspectable: IInspectable,
}
impl XamlWindow {
pub fn new() -> Result<Self> {
let factory = IActivationFactory::get("Windows.UI.Xaml.Window")
.map_err(|e| crate::error::Error::window_creation(format!("Failed to get XAML Window factory: {}", e)))?;
let inspectable: CoreIInspectable = factory.activate_instance()
.map_err(|e| crate::error::Error::window_creation(format!("Failed to activate XAML Window: {}", e)))?;
Ok(XamlWindow {
inspectable: IInspectable::from(inspectable),
})
}
pub fn current() -> Result<Self> {
Self::new()
}
pub fn activate(&self) -> Result<()> {
Ok(())
}
pub fn set_title(&self, _title: &str) -> Result<()> {
Ok(())
}
pub fn as_inspectable(&self) -> &IInspectable {
&self.inspectable
}
}
impl Default for XamlWindow {
fn default() -> Self {
Self::new().expect("Failed to create XAML Window")
}
}
unsafe impl Send for XamlWindow {}
unsafe impl Sync for XamlWindow {}