| 21 | #include "uwp/xamlthreadpool.hpp" |
| 22 | |
| 23 | class Application final { |
| 24 | static void ConfigurationChanged(void *context); |
| 25 | static winrt::TranslucentTB::Xaml::App CreateXamlApp(); |
| 26 | |
| 27 | ConfigManager m_Config; |
| 28 | |
| 29 | DynamicLoader m_Loader; |
| 30 | |
| 31 | TaskbarAttributeWorker m_Worker; |
| 32 | StartupManager m_Startup; |
| 33 | |
| 34 | // seemingly, dynamic deps are not transitive so add a dyn dep to the CRT that WinUI uses. |
| 35 | DynamicDependency m_UwpCRTDep, m_WinUIDep; |
| 36 | winrt::TranslucentTB::Xaml::App m_XamlApp; |
| 37 | wuxh::WindowsXamlManager m_XamlManager; |
| 38 | MainAppWindow m_AppWindow; |
| 39 | Window m_WelcomePage; |
| 40 | |
| 41 | XamlThreadPool m_Xaml; |
| 42 | bool m_ShuttingDown; |
| 43 | |
| 44 | winrt::Windows::System::DispatcherQueue m_Dispatcher; |
| 45 | |
| 46 | void CreateWelcomePage(); |
| 47 | Application(HINSTANCE hInst, std::optional<std::filesystem::path> storageFolder, bool fileExists); |
| 48 | |
| 49 | public: |
| 50 | Application(HINSTANCE hInst, std::optional<std::filesystem::path> storageFolder) : Application(hInst, std::move(storageFolder), false) { } |
| 51 | |
| 52 | static void OpenDonationPage(); |
| 53 | static void OpenTipsPage(); |
| 54 | static void OpenDiscordServer(); |
| 55 | |
| 56 | constexpr ConfigManager &GetConfigManager() noexcept { return m_Config; } |
| 57 | constexpr StartupManager &GetStartupManager() noexcept { return m_Startup; } |
| 58 | constexpr TaskbarAttributeWorker &GetWorker() noexcept { return m_Worker; } |
| 59 | |
| 60 | int Run(); |
| 61 | winrt::fire_and_forget Shutdown(); |
| 62 | |
| 63 | template<typename T, typename Callback, typename... Args> |
| 64 | void CreateXamlWindow(xaml_startup_position pos, Callback &&callback, Args&&... args) |
| 65 | { |
| 66 | m_Xaml.CreateXamlWindow<T>(pos, std::forward<Callback>(callback), std::forward<Args>(args)...); |
| 67 | } |
| 68 | |
| 69 | winrt::fire_and_forget DispatchToMainThread(winrt::Windows::System::DispatcherQueueHandler callback, |
| 70 | winrt::Windows::System::DispatcherQueuePriority priority = winrt::Windows::System::DispatcherQueuePriority::Normal) |
| 71 | { |
| 72 | co_await wil::resume_foreground(m_Dispatcher, priority); |
| 73 | callback(); |
| 74 | } |
| 75 | |
| 76 | bool BringWelcomeToFront() noexcept; |
| 77 | }; |