| 64 | |
| 65 | template<typename T, typename Callback, typename... Args> |
| 66 | winrt::fire_and_forget CreateXamlWindow(std::unique_lock<Util::thread_independent_mutex> lock, WindowClass &classRef, WindowClass& dragRegionClass, xaml_startup_position pos, Callback callback, Args... args) |
| 67 | { |
| 68 | // more than one window per thread is technically doable but impractical, |
| 69 | // because XAML Islands has a ton of bugs when hosting more than 1 window per thread |
| 70 | assert(m_CurrentWindow == nullptr); |
| 71 | |
| 72 | co_await wil::resume_foreground(m_Dispatcher); |
| 73 | |
| 74 | std::unique_ptr<XamlPageHost<T>> host; |
| 75 | try |
| 76 | { |
| 77 | host = std::make_unique<XamlPageHost<T>>(classRef, dragRegionClass, pos, m_Dispatcher, DeletedCallback, this, args...); |
| 78 | } |
| 79 | HresultErrorCatch(spdlog::level::critical, L"Failed to create XAML window"); |
| 80 | |
| 81 | m_Source = host->source().try_as<IDesktopWindowXamlSourceNative2>(); |
| 82 | |
| 83 | std::invoke(callback, host->content(), static_cast<BaseXamlPageHost *>(host.get())); |
| 84 | |
| 85 | m_CurrentWindow = std::move(host); |
| 86 | } |
| 87 | |
| 88 | wil::unique_handle Delete(); |
| 89 | |