Skip to content

Commit

Permalink
refactor: 删除 XamlHostingHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Oct 15, 2024
1 parent 378f81d commit 1994f02
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 72 deletions.
22 changes: 20 additions & 2 deletions src/Magpie.App/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ App::App() {
EffectsService::Get().StartInitialize();

// 初始化 XAML 框架
_xamlManagerWrapper.emplace();
_windowsXamlManager = Hosting::WindowsXamlManager::InitializeForCurrentThread();

const bool isWin11 = Win32Utils::GetOSVersion().IsWin11();
if (!isWin11) {
// Win10 中隐藏 DesktopWindowXamlSource 窗口
if (CoreWindow coreWindow = CoreWindow::GetForCurrentThread()) {
HWND hwndDWXS;
coreWindow.as<ICoreWindowInterop>()->get_WindowHandle(&hwndDWXS);
ShowWindow(hwndDWXS, SW_HIDE);
}
}

LocalizationService::Get().EarlyInitialize();
}
Expand All @@ -62,9 +72,17 @@ void App::Close() {
}
_isClosed = true;

_xamlManagerWrapper.reset();
_windowsXamlManager.Close();
_windowsXamlManager = nullptr;

Exit();

// 做最后的清理,见
// https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.hosting.windowsxamlmanager.close
MSG msg;
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
DispatchMessage(&msg);
}
}

void App::SaveSettings() {
Expand Down
4 changes: 2 additions & 2 deletions src/Magpie.App/App.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "App.g.h"
#include "XamlHostingHelper.h"
#include <winrt/Windows.UI.Xaml.Hosting.h>

namespace winrt::Magpie::App::implementation {

Expand Down Expand Up @@ -44,7 +44,7 @@ class App : public App_base<App, Markup::IXamlMetadataProvider> {
void Restart() const noexcept;

private:
std::optional<XamlHostingHelper::ManagerWrapper> _xamlManagerWrapper;
Hosting::WindowsXamlManager _windowsXamlManager{ nullptr };
weak_ref<Magpie::App::RootPage> _rootPage{ nullptr };
HWND _hwndMain = NULL;
bool _isClosed = false;
Expand Down
2 changes: 0 additions & 2 deletions src/Magpie.App/Magpie.App.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
<DependentUpon>WrapPanel.idl</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="XamlHostingHelper.h" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
Expand Down Expand Up @@ -420,7 +419,6 @@
<DependentUpon>WrapPanel.idl</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="XamlHostingHelper.cpp" />
</ItemGroup>
<ItemGroup>
<Midl Include="ToastPage.idl">
Expand Down
6 changes: 0 additions & 6 deletions src/Magpie.App/Magpie.App.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
<ClCompile Include="ToastService.cpp">
<Filter>Services</Filter>
</ClCompile>
<ClCompile Include="XamlHostingHelper.cpp">
<Filter>Helpers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
Expand Down Expand Up @@ -132,9 +129,6 @@
<ClInclude Include="ToastService.h">
<Filter>Services</Filter>
</ClInclude>
<ClInclude Include="XamlHostingHelper.h">
<Filter>Helpers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Pages">
Expand Down
2 changes: 1 addition & 1 deletion src/Magpie.App/ToastService.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "pch.h"
#include "ToastService.h"
#include "XamlHostingHelper.h"
#include "CommonSharedConstants.h"
#include "Utils.h"
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
#include <winrt/Windows.UI.Xaml.Hosting.h>

using namespace winrt;
using namespace Windows::UI::Xaml::Controls;
Expand Down
39 changes: 0 additions & 39 deletions src/Magpie.App/XamlHostingHelper.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions src/Magpie.App/XamlHostingHelper.h

This file was deleted.

0 comments on commit 1994f02

Please sign in to comment.