mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
refactor: 代码格式优化
This commit is contained in:
parent
cd41a175c7
commit
d853d820ea
2 changed files with 21 additions and 26 deletions
|
|
@ -97,7 +97,6 @@ static std::wstring ResourceFromPri(std::wstring_view packageFullName, std::wstr
|
|||
}
|
||||
|
||||
bool AppXReader::Initialize(HWND hWnd) noexcept {
|
||||
bool isSuspended = false;
|
||||
if (Win32Helper::GetWndClassName(hWnd) == L"ApplicationFrameWindow") {
|
||||
// UWP 应用被托管在 ApplicationFrameHost 进程中
|
||||
HWND childHwnd = NULL;
|
||||
|
|
@ -114,33 +113,27 @@ bool AppXReader::Initialize(HWND hWnd) noexcept {
|
|||
(LPARAM)&childHwnd
|
||||
);
|
||||
|
||||
if (childHwnd == NULL) {
|
||||
// 特殊情况下 UWP 应用无法通过子窗口找到
|
||||
// 比如被最小化(挂起)或尚未完成初始化
|
||||
isSuspended = true;
|
||||
} else {
|
||||
if (childHwnd) {
|
||||
hWnd = childHwnd;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 被最小化(挂起)或尚未完成初始化时 UWP 进程无法通过子窗口找到,
|
||||
// 回落到从窗口的 PropertyStore 中检索 AUMID。
|
||||
// 来自 https://github.com/valinet/sws/blob/bc8b04e451649964ee3d74255f9e9eda13ef24c3/SimpleWindowSwitcher/sws_IconPainter.c#L257
|
||||
com_ptr<IPropertyStore> propStore;
|
||||
HRESULT hr = SHGetPropertyStoreForWindow(hWnd, IID_PPV_ARGS(&propStore));
|
||||
if (FAILED(hr)) {
|
||||
Logger::Get().ComError("SHGetPropertyStoreForWindow 失败", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isSuspended) {
|
||||
// 窗口被挂起,此时 UWP 进程无法通过子窗口找到
|
||||
// 回落到从窗口的 PropertyStore 中检索 AUMID
|
||||
// 来自 https://github.com/valinet/sws/blob/bc8b04e451649964ee3d74255f9e9eda13ef24c3/SimpleWindowSwitcher/sws_IconPainter.c#L257
|
||||
com_ptr<IPropertyStore> propStore;
|
||||
HRESULT hr = SHGetPropertyStoreForWindow(hWnd, IID_PPV_ARGS(&propStore));
|
||||
if (FAILED(hr)) {
|
||||
Logger::Get().ComError("SHGetPropertyStoreForWindow 失败", hr);
|
||||
return false;
|
||||
}
|
||||
wil::unique_prop_variant prop;
|
||||
hr = propStore->GetValue(PKEY_AppUserModel_ID, &prop);
|
||||
if (FAILED(hr) || prop.vt != VT_LPWSTR || !prop.pwszVal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wil::unique_prop_variant prop;
|
||||
hr = propStore->GetValue(PKEY_AppUserModel_ID, &prop);
|
||||
if (FAILED(hr) || prop.vt != VT_LPWSTR || !prop.pwszVal) {
|
||||
return false;
|
||||
return Initialize(prop.pwszVal);
|
||||
}
|
||||
|
||||
return Initialize(prop.pwszVal);
|
||||
}
|
||||
|
||||
// 使用 GetApplicationUserModelId 获取 AUMID
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ namespace winrt::Magpie::implementation {
|
|||
static constexpr uint32_t FIRST_PROFILE_ITEM_IDX = 4;
|
||||
|
||||
RootPage::RootPage() {
|
||||
// 设置 Language 属性帮助 XAML 选择合适的字体,比如繁体中文使用 Microsoft JhengHei UI,日语使用 Yu Gothic UI
|
||||
// 设置 Language 属性帮助 XAML 选择合适的字体,比如繁体中文使用 Microsoft JhengHei UI,
|
||||
// 日语使用 Yu Gothic UI
|
||||
Language(LocalizationService::Get().Language());
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +53,8 @@ RootPage::~RootPage() {
|
|||
void RootPage::InitializeComponent() {
|
||||
RootPageT::InitializeComponent();
|
||||
|
||||
_appThemeChangedRevoker = App::Get().ThemeChanged(auto_revoke, [this](bool) { _UpdateTheme(true); });
|
||||
_appThemeChangedRevoker = App::Get().ThemeChanged(
|
||||
auto_revoke, [this](bool) { _UpdateTheme(true); });
|
||||
_UpdateTheme(false);
|
||||
|
||||
_dpiChangedRevoker = App::Get().MainWindow().DpiChanged(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue