refactor: 减少头文件间的依赖

This commit is contained in:
Xu 2024-12-21 00:47:55 +08:00
commit ff850d28f4
24 changed files with 59 additions and 37 deletions

View file

@ -103,7 +103,7 @@ void AboutViewModel::IsCheckForPreviewUpdates(bool value) {
}
bool AboutViewModel::IsCheckForUpdatesButtonEnabled() const noexcept {
// 只有发布版本能检查更新
// 只有发布版本能检查更新
#ifdef MAGPIE_VERSION_TAG
return !IsCheckingForUpdates() && !IsDownloadingOrLater();
#else

View file

@ -37,6 +37,7 @@
#include "IsEqualStateTrigger.h"
#include "IsNullStateTrigger.h"
#include "TextBlockHelper.h"
#include "MainWindow.h"
using namespace ::Magpie;
using namespace winrt;
@ -117,6 +118,8 @@ bool App::Initialize(const wchar_t* arguments) {
return false;
}
_mainWindow = std::make_unique<class MainWindow>();
EffectsService::Get().Initialize();
// 初始化 XAML 框架。退出时也不要关闭,如果正在播放动画会崩溃。文档中的清空消息队列的做法无用。
@ -174,7 +177,7 @@ bool App::Initialize(const wchar_t* arguments) {
// 不显示托盘图标时忽略 -t 参数
if (!notifyIconService.IsShow() || arguments != L"-t"sv) {
if (!_mainWindow.Create()) {
if (!_mainWindow->Create()) {
Quit();
return false;
}
@ -191,7 +194,7 @@ int App::Run() {
} else if (msg.message == WM_MAGPIE_QUIT) [[unlikely]] {
Quit();
} else {
_mainWindow.HandleMessage(msg);
_mainWindow->HandleMessage(msg);
}
}
@ -205,14 +208,14 @@ int App::Run() {
void App::ShowMainWindow() noexcept {
if (_mainWindow) {
_mainWindow.Show();
_mainWindow->Show();
} else {
_mainWindow.Create();
_mainWindow->Create();
}
}
void App::Quit() {
_mainWindow.Destroy();
_mainWindow->Destroy();
PostQuitMessage(0);
}
@ -240,7 +243,7 @@ void App::Restart(bool asElevated, const wchar_t* arguments) noexcept {
const com_ptr<RootPage>& App::RootPage() const noexcept {
assert(_mainWindow);
return _mainWindow.Content();
return _mainWindow->Content();
}
void App::_Uninitialize() {

View file

@ -1,13 +1,17 @@
#pragma once
#include "App.g.h"
#include <winrt/Windows.UI.Xaml.Hosting.h>
#include "MainWindow.h"
#include "AppSettings.h"
#include "Event.h"
#include "RootPage.h"
namespace Magpie {
class MainWindow;
}
namespace winrt::Magpie::implementation {
struct RootPage;
class App : public App_base<App, Markup::IXamlMetadataProvider> {
public:
static App& Get();
@ -33,11 +37,11 @@ public:
const com_ptr<RootPage>& RootPage() const noexcept;
const ::Magpie::MainWindow& MainWindow() const noexcept {
return _mainWindow;
return *_mainWindow;
}
::Magpie::MainWindow& MainWindow() noexcept {
return _mainWindow;
return *_mainWindow;
}
bool IsLightTheme() const noexcept {
@ -65,7 +69,7 @@ private:
Hosting::WindowsXamlManager _windowsXamlManager{ nullptr };
::Magpie::MainWindow _mainWindow;
std::unique_ptr<::Magpie::MainWindow> _mainWindow;
CoreDispatcher _dispatcher{ nullptr };
@ -106,10 +110,3 @@ private:
};
}
namespace winrt::Magpie::factory_implementation {
class App : public AppT<App, implementation::App> {
};
}

View file

@ -41,6 +41,5 @@ namespace Magpie {
namespace Magpie {
[default_interface]
runtimeclass App : Windows.UI.Xaml.Application {
App();
}
}

View file

@ -15,8 +15,8 @@
#include <ShellScalingApi.h>
#include "resource.h"
#include "App.h"
#include "MainWindow.h"
using namespace ::Magpie;
using namespace winrt;
using namespace winrt::Magpie;

View file

@ -5,7 +5,6 @@
#include "Profile.h"
#include <parallel_hashmap/phmap.h>
#include <rapidjson/document.h>
#include "Win32Helper.h"
namespace Magpie {

View file

@ -8,6 +8,7 @@
#include "IconHelper.h"
#include "StrHelper.h"
#include "App.h"
#include "MainWindow.h"
using namespace ::Magpie;
using namespace winrt;

View file

@ -4,6 +4,7 @@
#include "CaptionButtonsControl.g.cpp"
#endif
#include "App.h"
#include "MainWindow.h"
namespace winrt::Magpie::implementation {

View file

@ -2,6 +2,7 @@
#include "FileDialogHelper.h"
#include "Logger.h"
#include "App.h"
#include "MainWindow.h"
using namespace ::Magpie;
using namespace winrt::Magpie::implementation;

View file

@ -12,6 +12,7 @@
#include "TouchHelper.h"
#include "LocalizationService.h"
#include "App.h"
#include "RootPage.h"
using namespace Magpie;

View file

@ -8,6 +8,8 @@
#include "EffectsService.h"
#include "AppSettings.h"
#include "App.h"
#include "CaptionButtonsControl.h"
#include "TitleBarControl.h"
using namespace winrt::Magpie::implementation;

View file

@ -17,6 +17,7 @@
#include "FileDialogHelper.h"
#include "CommonSharedConstants.h"
#include "App.h"
#include "MainWindow.h"
using namespace ::Magpie;
using namespace winrt;

View file

@ -15,6 +15,8 @@
#include "ContentDialogHelper.h"
#include "LocalizationService.h"
#include "App.h"
#include "TitleBarControl.h"
#include "MainWindow.h"
using namespace ::Magpie;
using namespace winrt;
@ -205,6 +207,10 @@ void RootPage::NavigateToAboutPage() {
nv.SelectedItem(nv.FooterMenuItems().GetAt(0));
}
TitleBarControl& RootPage::TitleBar() {
return *get_self<TitleBarControl>(RootPageT::TitleBar());
}
static Color Win32ColorToWinRTColor(COLORREF color) {
return { 255, GetRValue(color), GetGValue(color), GetBValue(color) };
}

View file

@ -2,7 +2,6 @@
#include "RootPage.g.h"
#include "Event.h"
#include "NewProfileViewModel.h"
#include "TitleBarControl.h"
namespace Magpie {
struct Profile;
@ -10,6 +9,8 @@ struct Profile;
namespace winrt::Magpie::implementation {
struct TitleBarControl;
struct RootPage : RootPageT<RootPage> {
RootPage();
~RootPage();
@ -40,9 +41,7 @@ struct RootPage : RootPageT<RootPage> {
void NavigateToAboutPage();
TitleBarControl& TitleBar() {
return *get_self<TitleBarControl>(RootPageT::TitleBar());
}
TitleBarControl& TitleBar();
private:
void _UpdateTheme(bool updateIcons);

View file

@ -15,6 +15,7 @@
#include "StrHelper.h"
#include "CommonSharedConstants.h"
#include "App.h"
#include "MainWindow.h"
using namespace Magpie;

View file

@ -11,6 +11,9 @@
#include "EffectHelper.h"
#include "CommonSharedConstants.h"
#include "App.h"
#include "ScalingModeEffectItem.h"
#include "Win32Helper.h"
#include "RootPage.h"
using namespace ::Magpie;

View file

@ -2,7 +2,6 @@
#include "ScalingModeItem.g.h"
#include "Event.h"
#include "ScalingModesService.h"
#include "ScalingModeEffectItem.h"
namespace Magpie {
struct ScalingMode;
@ -10,6 +9,8 @@ struct ScalingMode;
namespace winrt::Magpie::implementation {
struct ScalingModeEffectItem;
struct ScalingModeItem : ScalingModeItemT<ScalingModeItem>,
wil::notify_property_changed_base<ScalingModeItem> {
ScalingModeItem(uint32_t index, bool isInitialExpanded);

View file

@ -12,6 +12,7 @@
#include "CommonSharedConstants.h"
#include "App.h"
#include "KeyVisualState.h"
#include "MainWindow.h"
using namespace ::Magpie;
using namespace winrt;

View file

@ -6,6 +6,8 @@
#include "IconHelper.h"
#include "Win32Helper.h"
#include "App.h"
#include "CaptionButtonsControl.h"
#include "RootPage.h"
using namespace ::Magpie;
using namespace winrt;
@ -43,4 +45,8 @@ void TitleBarControl::IsWindowActive(bool value) {
CaptionButtons().IsWindowActive(value);
}
CaptionButtonsControl& TitleBarControl::CaptionButtons() noexcept {
return *get_self<CaptionButtonsControl>(TitleBarControlT::CaptionButtons());
}
}

View file

@ -1,8 +1,10 @@
#pragma once
#include "TitleBarControl.g.h"
#include "CaptionButtonsControl.h"
namespace winrt::Magpie::implementation {
struct CaptionButtonsControl;
struct TitleBarControl : TitleBarControlT<TitleBarControl>,
wil::notify_property_changed_base<TitleBarControl> {
TitleBarControl();
@ -15,13 +17,12 @@ struct TitleBarControl : TitleBarControlT<TitleBarControl>,
void IsWindowActive(bool value);
CaptionButtonsControl& CaptionButtons() {
return *get_self<CaptionButtonsControl>(TitleBarControlT::CaptionButtons());
}
CaptionButtonsControl& CaptionButtons() noexcept;
private:
Imaging::SoftwareBitmapSource _logo{ nullptr };
};
}
namespace winrt::Magpie::factory_implementation {

View file

@ -1,7 +1,6 @@
#pragma once
#include "ToastPage.g.h"
#include "Event.h"
#include "AppSettings.h"
namespace winrt::Magpie::implementation {

View file

@ -5,6 +5,7 @@
#include <winrt/Windows.UI.Xaml.Hosting.h>
#include "XamlHelper.h"
#include "App.h"
#include "MainWindow.h"
using namespace winrt::Magpie::implementation;
using namespace winrt;

View file

@ -33,11 +33,8 @@ static constexpr Version MAGPIE_VERSION(
static constexpr uint32_t MD5_HASH_LENGTH = 16;
void UpdateService::Initialize() noexcept {
#ifndef MAGPIE_VERSION_TAG
// 只有正式版本才能检查更新
return;
#endif
// 只有发布版本能检查更新
#ifdef MAGPIE_VERSION_TAG
AppSettings& settings = AppSettings::Get();
if (settings.IsAutoCheckForUpdates()) {
_StartTimer();
@ -55,6 +52,7 @@ void UpdateService::Initialize() noexcept {
App::Get().MainWindow().Destroyed([this]() {
_MainWindow_Closed();
});
#endif
}
fire_and_forget UpdateService::CheckForUpdatesAsync(bool isAutoUpdate) {

View file

@ -19,6 +19,7 @@
#include "Win32Helper.h"
#include "TouchHelper.h"
#include "CommonSharedConstants.h"
#include "Logger.h"
using namespace Magpie;
using namespace winrt::Magpie::implementation;