refactor: EffectsService 和 LocalizationService 移到 Magpie.Core

This commit is contained in:
Xu 2026-03-24 13:36:26 +08:00
commit 7682132dce
25 changed files with 101 additions and 108 deletions

View file

@ -59,7 +59,7 @@ winrt::fire_and_forget EffectsService::Initialize() {
CommonSharedConstants::EFFECTS_DIR, L"\\", effectNames[id], L".hlsl");
std::string source;
Win32Helper::ReadTextFile(fileName.c_str(), source);
EffectInfo2 effectInfo;
EffectInfo effectInfo;
std::string errorMsg = ShaderEffectParser::ParseForInfo(
StrHelper::UTF16ToUTF8(effectNames[id]), std::move(source), effectInfo);
if (!errorMsg.empty()) {
@ -80,12 +80,12 @@ void EffectsService::Uninitialize() {
_WaitForInitialize();
}
const std::vector<EffectInfo2>& EffectsService::GetEffects() noexcept {
const std::vector<EffectInfo>& EffectsService::GetEffects() noexcept {
_WaitForInitialize();
return _effects;
}
const EffectInfo2* EffectsService::GetEffect(std::wstring_view name) noexcept {
const EffectInfo* EffectsService::GetEffect(std::wstring_view name) noexcept {
_WaitForInitialize();
auto it = _effectsMap.find(name);

View file

@ -1,15 +1,13 @@
#include "pch.h"
#include "AppSettings.h"
#include "LocalizationService.h"
#include "CommonSharedConstants.h"
#include <bcp47mrm.h>
#include <winrt/Windows.System.UserProfile.h>
using namespace winrt;
namespace Magpie {
// 标签必须为小写
static std::array SUPPORTED_LANGUAGES{
static std::array SUPPORTED_LANGUAGES = {
L"de",
L"en-us",
L"es",
@ -32,7 +30,7 @@ static std::array SUPPORTED_LANGUAGES{
void LocalizationService::EarlyInitialize() {
// 非打包应用默认使用“Windows 显示语言”,这里自行切换至“首选语言”
std::wstring userLanguages;
for (const hstring& language : UserProfile::GlobalizationPreferences::Languages()) {
for (const winrt::hstring& language : winrt::UserProfile::GlobalizationPreferences::Languages()) {
userLanguages += language;
userLanguages += L'\0';
}
@ -62,22 +60,26 @@ void LocalizationService::EarlyInitialize() {
_Language(bestLanguage);
}
void LocalizationService::Initialize() {
AppSettings& settings = AppSettings::Get();
int language = settings.Language();
void LocalizationService::Initialize(int language) {
if (language >= 0) {
_Language(SUPPORTED_LANGUAGES[language]);
}
_resourceLoader = winrt::ResourceLoader::GetForViewIndependentUse(
CommonSharedConstants::APP_RESOURCE_MAP_ID);
}
std::span<const wchar_t*> LocalizationService::SupportedLanguages() noexcept {
std::span<const wchar_t*> LocalizationService::GetSupportedLanguages() noexcept {
return SUPPORTED_LANGUAGES;
}
winrt::hstring LocalizationService::GetLocalizedString(std::wstring_view resName) const noexcept {
return _resourceLoader.GetString(resName);
}
void LocalizationService::_Language(const wchar_t* tag) {
_language = tag;
ResourceContext::SetGlobalQualifierValue(L"Language", tag);
winrt::ResourceContext::SetGlobalQualifierValue(L"Language", tag);
}
}

View file

@ -66,6 +66,8 @@
<ClInclude Include="FrameProducer.h" />
<ClInclude Include="CursorHelper.h" />
<ClInclude Include="include\EffectInfo.h" />
<ClInclude Include="include\EffectsService.h" />
<ClInclude Include="include\LocalizationService.h" />
<ClInclude Include="include\ShaderEffectParser.h" />
<ClInclude Include="ShaderEffectCompilerService.h" />
<ClInclude Include="ShaderEffectDesc.h" />
@ -99,9 +101,11 @@
<ClCompile Include="DuplicateFrameChecker.cpp" />
<ClCompile Include="DescriptorHeap.cpp" />
<ClCompile Include="EffectsDrawer.cpp" />
<ClCompile Include="EffectsService.cpp" />
<ClCompile Include="ExclModeHelper.cpp" />
<ClCompile Include="FrameProducer.cpp" />
<ClCompile Include="CursorHelper.cpp" />
<ClCompile Include="LocalizationService.cpp" />
<ClCompile Include="ShaderEffectCompilerService.cpp" />
<ClCompile Include="ShaderEffectDrawer.cpp" />
<ClCompile Include="GraphicsCaptureFrameSource.cpp" />

View file

@ -94,7 +94,6 @@
<ClInclude Include="DuplicateFrameChecker.h">
<Filter>Capture</Filter>
</ClInclude>
<ClInclude Include="RectHelper.h" />
<ClInclude Include="DirtyRectsOptimizer.h">
<Filter>Capture</Filter>
</ClInclude>
@ -129,6 +128,15 @@
<Filter>Render</Filter>
</ClInclude>
<ClInclude Include="Renderer.h" />
<ClInclude Include="RectHelper.h">
<Filter>Helpers</Filter>
</ClInclude>
<ClInclude Include="include\EffectsService.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="include\LocalizationService.h">
<Filter>Include</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ScalingRuntime.cpp" />
@ -199,6 +207,12 @@
<Filter>Render</Filter>
</ClCompile>
<ClCompile Include="Renderer.cpp" />
<ClCompile Include="LocalizationService.cpp">
<Filter>Services</Filter>
</ClCompile>
<ClCompile Include="EffectsService.cpp">
<Filter>Services</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="shaders\MaskedCursorPS.hlsl">
@ -240,10 +254,12 @@
<FxCompile Include="shaders\CursorResizerPS.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
<FxCompile Include="shaders\TextureBlitPS.hlsl" />
<FxCompile Include="shaders\FullscreenVS.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
<FxCompile Include="shaders\TextureBlitPS.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View file

@ -19,21 +19,11 @@ static UINT WM_MAGPIE_SCALINGCHANGED;
// 窗口模式缩放时缩放窗口应遮挡源窗口和它的阴影,在四周留出 50 x DPI 缩放的空间
static constexpr int WINDOWED_MODE_MIN_SPACE_AROUND = 2 * 50;
static void InitMessage() noexcept {
[[maybe_unused]] static Ignore _ = []() {
WM_MAGPIE_SCALINGCHANGED =
RegisterWindowMessage(CommonSharedConstants::WM_MAGPIE_SCALINGCHANGED);
return Ignore();
}();
}
static bool IsTopmostWindow(HWND hWnd) noexcept {
return GetWindowExStyle(hWnd) & WS_EX_TOPMOST;
}
ScalingWindow::ScalingWindow() noexcept :
_resourceLoader(winrt::ResourceLoader::GetForViewIndependentUse(CommonSharedConstants::APP_RESOURCE_MAP_ID)) {}
ScalingWindow::ScalingWindow() noexcept {}
ScalingWindow::~ScalingWindow() noexcept {}
@ -93,8 +83,6 @@ ScalingError ScalingWindow::_StartImpl(HWND hwndSrc) noexcept {
return ScalingError::ScalingFailedGeneral;
}
InitMessage();
bool isSrcInvisibleOrMinimized = false;
if (ScalingError error = _srcTracker.Set(hwndSrc, _options, isSrcInvisibleOrMinimized);
error != ScalingError::NoError
@ -120,7 +108,10 @@ ScalingError ScalingWindow::_StartImpl(HWND hwndSrc) noexcept {
}
[[maybe_unused]] static Ignore _ = []() {
WNDCLASSEXW wcex{
WM_MAGPIE_SCALINGCHANGED =
RegisterWindowMessage(CommonSharedConstants::WM_MAGPIE_SCALINGCHANGED);
WNDCLASSEXW wcex = {
.cbSize = sizeof(wcex),
.lpfnWndProc = _WndProc,
.hInstance = wil::GetModuleInstanceHandle(),
@ -462,10 +453,6 @@ void ScalingWindow::CleanAfterSrcRepositioned() noexcept {
_isSrcRepositioning = false;
}
winrt::hstring ScalingWindow::GetLocalizedString(std::wstring_view resName) const {
return _resourceLoader.GetString(resName);
}
LRESULT ScalingWindow::_MessageHandler(UINT msg, WPARAM wParam, LPARAM lParam) noexcept {
switch (msg) {
case WM_CREATE:

View file

@ -66,8 +66,6 @@ public:
void CleanAfterSrcRepositioned() noexcept;
winrt::hstring GetLocalizedString(std::wstring_view resName) const;
void ShowToast(std::wstring_view msg) const noexcept {
_options.showToast(Handle(), msg);
}
@ -162,8 +160,6 @@ private:
class SrcTracker _srcTracker;
winrt::ResourceLoader _resourceLoader{ nullptr };
wil::unique_mutex_nothrow _exclModeMutex;
std::array<wil::unique_hwnd, 4> _hwndResizeHelpers{};

View file

@ -393,7 +393,7 @@ static bool ResolveHeaderSortName(
return false;
}
((EffectInfo2*)data)->sortName = sortName;
((EffectInfo*)data)->sortName = sortName;
return true;
}
@ -418,9 +418,9 @@ static bool ResolveHeaderCapability(
static constexpr std::array FLAG_INFOS = {
// 以下为必需
std::make_pair("FP16", EffectInfoFlags2::SupportFP16),
std::make_pair("FP16", EffectInfoFlags::SupportFP16),
// 以下为可选
std::make_pair("ADVANCEDCOLOR", EffectInfoFlags2::SupportAdvancedColor)
std::make_pair("ADVANCEDCOLOR", EffectInfoFlags::SupportAdvancedColor)
};
std::bitset<FLAG_INFOS.size()> processed;
@ -440,7 +440,7 @@ static bool ResolveHeaderCapability(
}
processed[idx] = true;
((EffectInfo2*)data)->flags |= it->second;
((EffectInfo*)data)->flags |= it->second;
} else {
Logger::Get().Warn(StrHelper::Concat("使用了未知 CAPABILITY 标志: ", token));
}
@ -454,7 +454,7 @@ static bool ResolveHeaderScaleFactor(
ParserState& state,
void* data
) noexcept {
if (!GetNextNumber(source, state, ((EffectInfo2*)data)->scaleFactor)) {
if (!GetNextNumber(source, state, ((EffectInfo*)data)->scaleFactor)) {
return false;
}
@ -468,7 +468,7 @@ static bool ResolveHeaderScaleFactor(
static bool ResolveHeader(
std::string_view source,
uint32_t startLineNumer,
EffectInfo2& effectInfo
EffectInfo& effectInfo
) noexcept {
static constexpr std::array COMMAND_INFOS = {
CommandInfo{ "VERSION", ResolveHeaderVersion, true },
@ -653,7 +653,7 @@ static bool ResolveParameter(
std::string ShaderEffectParser::ParseForInfo(
std::string&& name,
std::string&& source,
EffectInfo2& effectInfo
EffectInfo& effectInfo
) noexcept {
assert(!name.empty() && !source.empty());
@ -671,7 +671,7 @@ std::string ShaderEffectParser::ParseForInfo(
std::string_view sourceView(source);
if (!CheckMagic(sourceView, state)) {
Logger::Get().Error("检查 MagpieFX 头失败");
Logger::Get().Error(StrHelper::Concat("CheckMagic 失败\n\t错误消息: ", state.errorMsg));
return std::move(state.errorMsg);
}
@ -775,14 +775,14 @@ std::string ShaderEffectParser::ParseForInfo(
completeCurrentBlock(BlockType::Header, sourceView.size(), std::numeric_limits<size_t>::max());
if (!ResolveHeader(headerBlock.source, headerBlock.startLineNumer, effectInfo)) {
Logger::Get().Error(StrHelper::Concat("解析 Header 块失败: ", state.errorMsg));
Logger::Get().Error(StrHelper::Concat("ResolveHeader 失败\n\t错误消息: ", state.errorMsg));
return std::move(state.errorMsg);
}
effectInfo.params.resize(paramBlocks.size());
for (size_t i = 0; i < paramBlocks.size(); ++i) {
if (!ResolveParameter(paramBlocks[i].source, paramBlocks[i].startLineNumer, effectInfo.params[i])) {
Logger::Get().Error(fmt::format("解析 Parameter#{} 块失败", i + 1));
Logger::Get().Error(fmt::format("ResolveParameter#{} 失败\n\t错误消息: ", state.errorMsg));
return std::move(state.errorMsg);
}
}

View file

@ -12,20 +12,20 @@ struct EffectInfoParameter {
float step;
};
enum class EffectInfoFlags2 {
enum class EffectInfoFlags {
None,
SupportFP16 = 1,
SupportAdvancedColor = 1 << 1,
};
DEFINE_ENUM_FLAG_OPERATORS(EffectInfoFlags2)
DEFINE_ENUM_FLAG_OPERATORS(EffectInfoFlags)
struct EffectInfo2 {
struct EffectInfo {
std::string name;
std::string sortName;
std::vector<EffectInfoParameter> params;
// 0 表示可以自由缩放
uint32_t scaleFactor = 0;
EffectInfoFlags2 flags = EffectInfoFlags2::None;
EffectInfoFlags flags = EffectInfoFlags::None;
};
}

View file

@ -18,17 +18,17 @@ public:
void Uninitialize();
const std::vector<EffectInfo2>& GetEffects() noexcept;
const std::vector<EffectInfo>& GetEffects() noexcept;
// 由于 WinUI 使用 UTF-16这里也以 UTF-16 作为参数以减少编码转换
const EffectInfo2* GetEffect(std::wstring_view name) noexcept;
const EffectInfo* GetEffect(std::wstring_view name) noexcept;
private:
EffectsService() = default;
void _WaitForInitialize() noexcept;
std::vector<EffectInfo2> _effects;
std::vector<EffectInfo> _effects;
phmap::flat_hash_map<std::wstring, uint32_t> _effectsMap;
std::atomic<bool> _initialized = false;
bool _initializedCache = false;

View file

@ -15,21 +15,25 @@ public:
// 在初始化 AppSettings 前调用以使用系统默认语言,然后就可以从 AppSettings 里读取语言设置
void EarlyInitialize();
void Initialize();
// -1 表示使用系统设置
void Initialize(int language);
// 支持的所有语言的标签,均为小写
static std::span<const wchar_t* > SupportedLanguages() noexcept;
static std::span<const wchar_t*> GetSupportedLanguages() noexcept;
const wchar_t* Language() const noexcept {
const wchar_t* GetLanguage() const noexcept {
return _language;
}
winrt::hstring GetLocalizedString(std::wstring_view resName) const noexcept;
private:
LocalizationService() = default;
void _Language(const wchar_t* tag);
const wchar_t* _language = nullptr;
winrt::ResourceLoader _resourceLoader{ nullptr };
};
}

View file

@ -33,7 +33,7 @@ struct ShaderEffectParser {
static std::string ParseForInfo(
std::string&& name,
std::string&& source,
struct EffectInfo2& effectInfo
struct EffectInfo& effectInfo
) noexcept;
static bool ParseForDesc(

View file

@ -120,8 +120,6 @@ bool App::Initialize(const wchar_t* arguments) {
return false;
}
EffectsService::Get().Initialize();
_mainWindow = std::make_unique<class MainWindow>();
// 初始化 XAML 框架。退出时也不要关闭,如果正在播放动画会崩溃。文档中的清空消息队列的做法无用。
@ -154,6 +152,20 @@ bool App::Initialize(const wchar_t* arguments) {
return false;
}
// 尽可能早的初始化 LocalizationService
LocalizationService::Get().Initialize(settings.Language());
// 会在后台解析效果,应尽可能早的初始化
EffectsService::Get().Initialize();
ToastService::Get().Initialize();
if (!AdaptersService::Get().Initialize()) {
_Uninitialize();
return false;
}
ShortcutService::Get().Initialize();
ScalingService::Get().Initialize();
UpdateService::Get().Initialize();
ThemeHelper::Initialize();
// 延迟注册 DependencyProperty见 FixThreadPoolCrash
SettingsCard::RegisterDependencyProperties();
SettingsExpander::RegisterDependencyProperties();
@ -167,17 +179,6 @@ bool App::Initialize(const wchar_t* arguments) {
auto_revoke, std::bind_front(&App::_AppSettings_ThemeChanged, this));
_AppSettings_ThemeChanged(AppSettings::Get().Theme());
LocalizationService::Get().Initialize();
ToastService::Get().Initialize();
if (!AdaptersService::Get().Initialize()) {
_Uninitialize();
return false;
}
ShortcutService::Get().Initialize();
ScalingService::Get().Initialize();
UpdateService::Get().Initialize();
ThemeHelper::Initialize();
NotifyIconService& notifyIconService = NotifyIconService::Get();
notifyIconService.Initialize();
notifyIconService.IsShow(AppSettings::Get().IsShowNotifyIcon());

View file

@ -555,7 +555,7 @@ bool AppSettings::_Save(const _AppSettingsData& data) noexcept {
if (_language < 0) {
writer.String("");
} else {
const wchar_t* language = LocalizationService::SupportedLanguages()[_language];
const wchar_t* language = LocalizationService::GetSupportedLanguages()[_language];
writer.String(StrHelper::UTF16ToUTF8(language).c_str());
}
@ -688,7 +688,7 @@ void AppSettings::_LoadSettings(const rapidjson::GenericObject<true, rapidjson::
_language = -1;
} else {
StrHelper::ToLowerCase(language);
std::span<const wchar_t*> languages = LocalizationService::SupportedLanguages();
std::span<const wchar_t*> languages = LocalizationService::GetSupportedLanguages();
auto it = std::find(languages.begin(), languages.end(), language);
if (it == languages.end()) {
// 未知的语言设置,重置为使用系统设置

View file

@ -29,8 +29,7 @@ struct _AppSettingsData {
std::filesystem::path _configDir;
std::filesystem::path _configPath;
// LocalizationService::SupportedLanguages 索引
// -1 表示使用系统设置
// LocalizationService::SupportedLanguages 索引,-1 表示使用系统设置
int _language = -1;
// 保存窗口中心点和 DPI 无关的窗口尺寸

View file

@ -5,7 +5,7 @@
#include <parallel_hashmap/phmap.h>
namespace Magpie {
struct EffectInfo2;
struct EffectInfo;
}
namespace winrt::Magpie::implementation {
@ -134,7 +134,7 @@ private:
uint32_t _scalingModeIdx;
uint32_t _effectIdx;
const ::Magpie::EffectInfo2* _effectInfo = nullptr;
const ::Magpie::EffectInfo* _effectInfo = nullptr;
};
}

View file

@ -307,7 +307,7 @@ fire_and_forget HomeViewModel::IsTouchSupportEnabled(bool value) {
}
Uri HomeViewModel::TouchSupportLearnMoreUrl() const noexcept {
if (LocalizationService::Get().Language() == L"zh-hans"sv) {
if (LocalizationService::Get().GetLanguage() == L"zh-hans"sv) {
return Uri(L"https://github.com/Blinue/Magpie/blob/dev/docs/%E5%85%B3%E4%BA%8E%E8%A7%A6%E6%8E%A7%E6%94%AF%E6%8C%81.md");
} else {
return Uri(L"https://github.com/Blinue/Magpie/blob/dev/docs/About%20touch%20support.md");

View file

@ -149,7 +149,6 @@
<DependentUpon>EffectParametersViewModel.idl</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="EffectsService.h" />
<ClInclude Include="FileDialogHelper.h" />
<ClInclude Include="HomeViewModel.h">
<DependentUpon>HomeViewModel.idl</DependentUpon>
@ -186,7 +185,6 @@
<ClInclude Include="Shortcut.h" />
<ClInclude Include="IconHelper.h" />
<ClInclude Include="JsonHelper.h" />
<ClInclude Include="LocalizationService.h" />
<ClInclude Include="ScalingService.h" />
<ClInclude Include="NewProfileViewModel.h">
<DependentUpon>NewProfileViewModel.idl</DependentUpon>
@ -341,7 +339,6 @@
<DependentUpon>EffectParametersViewModel.idl</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="EffectsService.cpp" />
<ClCompile Include="FileDialogHelper.cpp" />
<ClCompile Include="HomeViewModel.cpp">
<DependentUpon>HomeViewModel.idl</DependentUpon>
@ -379,7 +376,6 @@
<ClCompile Include="Shortcut.cpp" />
<ClCompile Include="IconHelper.cpp" />
<ClCompile Include="JsonHelper.cpp" />
<ClCompile Include="LocalizationService.cpp" />
<ClCompile Include="ScalingService.cpp" />
<ClCompile Include="NewProfileViewModel.cpp">
<DependentUpon>NewProfileViewModel.idl</DependentUpon>

View file

@ -34,9 +34,6 @@
<ClCompile Include="AutoStartHelper.cpp">
<Filter>Helpers</Filter>
</ClCompile>
<ClCompile Include="EffectsService.cpp">
<Filter>Services</Filter>
</ClCompile>
<ClCompile Include="ScalingModesService.cpp">
<Filter>Services</Filter>
</ClCompile>
@ -49,9 +46,6 @@
<ClCompile Include="ContentDialogHelper.cpp">
<Filter>Helpers</Filter>
</ClCompile>
<ClCompile Include="LocalizationService.cpp">
<Filter>Services</Filter>
</ClCompile>
<ClCompile Include="FileDialogHelper.cpp">
<Filter>Helpers</Filter>
</ClCompile>
@ -119,9 +113,6 @@
<ClInclude Include="ScalingMode.h">
<Filter>Models</Filter>
</ClInclude>
<ClInclude Include="EffectsService.h">
<Filter>Services</Filter>
</ClInclude>
<ClInclude Include="ScalingModesService.h">
<Filter>Services</Filter>
</ClInclude>
@ -137,9 +128,6 @@
<ClInclude Include="ContentDialogHelper.h">
<Filter>Helpers</Filter>
</ClInclude>
<ClInclude Include="LocalizationService.h">
<Filter>Services</Filter>
</ClInclude>
<ClInclude Include="FileDialogHelper.h">
<Filter>Helpers</Filter>
</ClInclude>

View file

@ -36,7 +36,7 @@ static constexpr uint32_t FIRST_PROFILE_ITEM_IDX = 4;
RootPage::RootPage() {
// 设置 Language 属性帮助 XAML 选择合适的字体,比如繁体中文使用 Microsoft JhengHei UI
// 日语使用 Yu Gothic UI
Language(LocalizationService::Get().Language());
Language(LocalizationService::Get().GetLanguage());
}
RootPage::~RootPage() {

View file

@ -95,7 +95,7 @@ private:
uint32_t _scalingModeIdx = 0;
uint32_t _effectIdx = 0;
hstring _name;
const ::Magpie::EffectInfo2* _effectInfo = nullptr;
const ::Magpie::EffectInfo* _effectInfo = nullptr;
com_ptr<EffectParametersViewModel> _parametersViewModel;
};

View file

@ -215,7 +215,7 @@ void ScalingModeItem::AddEffect(const hstring& fullName) {
EffectItem& effect = _Data().effects.emplace_back();
effect.name = fullName;
const EffectInfo2* effectInfo = EffectsService::Get().GetEffect(fullName);
const EffectInfo* effectInfo = EffectsService::Get().GetEffect(fullName);
assert(effectInfo);
if (effectInfo->scaleFactor == 0) {
// 支持缩放的效果默认等比缩放到充满屏幕

View file

@ -75,7 +75,7 @@ void ScalingModesPage::_BuildEffectMenu() noexcept {
phmap::flat_hash_map<std::wstring, MenuFlyoutSubItem> folders;
folders.reserve(8);
for (const EffectInfo2& effectInfo : EffectsService::Get().GetEffects()) {
for (const EffectInfo& effectInfo : EffectsService::Get().GetEffects()) {
std::wstring effectName(StrHelper::UTF8ToUTF16(effectInfo.name));
MenuFlyoutItem item;
@ -135,13 +135,13 @@ void ScalingModesPage::_BuildEffectMenu() noexcept {
hstring name1 = unbox_value<hstring>(l.try_as<MenuFlyoutItem>().Tag());
hstring name2 = unbox_value<hstring>(r.try_as<MenuFlyoutItem>().Tag());
const EffectInfo2* effectInfo1 = EffectsService::Get().GetEffect(name1);
const EffectInfo2* effectInfo2 = EffectsService::Get().GetEffect(name2);
const EffectInfo* effectInfo1 = EffectsService::Get().GetEffect(name1);
const EffectInfo* EffectInfo = EffectsService::Get().GetEffect(name2);
const std::string& sortName1 =
effectInfo1->sortName.empty() ? effectInfo1->name : effectInfo1->sortName;
const std::string& sortName2 =
effectInfo2->sortName.empty() ? effectInfo2->name : effectInfo2->sortName;
EffectInfo->sortName.empty() ? EffectInfo->name : EffectInfo->sortName;
return sortName1 < sortName2;
});

View file

@ -13,6 +13,7 @@
#include "TouchHelper.h"
#include "Win32Helper.h"
#include "WindowHelper.h"
#include "LocalizationService.h"
using namespace winrt::Magpie::implementation;
using namespace winrt;
@ -195,10 +196,9 @@ static void ShowError(HWND hWnd, ScalingError error) noexcept {
return;
}
ResourceLoader resourceLoader =
ResourceLoader::GetForViewIndependentUse(CommonSharedConstants::APP_RESOURCE_MAP_ID);
hstring title = isFail ? resourceLoader.GetString(L"Message_ScalingFailed") : hstring{};
ToastService::Get().ShowMessageOnWindow(title, resourceLoader.GetString(key), hWnd);
LocalizationService& ls = LocalizationService::Get();
hstring title = isFail ? ls.GetLocalizedString(L"Message_ScalingFailed") : hstring{};
ToastService::Get().ShowMessageOnWindow(title, ls.GetLocalizedString(key), hWnd);
Logger::Get().Error(fmt::format("缩放失败\n\t错误码: {}", (int)error));
}

View file

@ -15,7 +15,7 @@ using namespace Magpie;
namespace winrt::Magpie::implementation {
IVector<IInspectable> SettingsViewModel::Languages() const {
std::span<const wchar_t*> tags = LocalizationService::Get().SupportedLanguages();
std::span<const wchar_t*> tags = LocalizationService::Get().GetSupportedLanguages();
std::vector<IInspectable> languages;
languages.reserve(tags.size() + 1);

View file

@ -147,7 +147,7 @@ fire_and_forget ToastPage::ShowMessageOnWindow(std::wstring title, std::wstring
// 创建新的 TeachingTip
MUXC::TeachingTip curTeachingTip = FindName(L"MessageTeachingTip").try_as<MUXC::TeachingTip>();
// 帮助 XAML 选择合适的字体,直接设置 TeachingTip 的 Language 属性无用
MessageTeachingTipContent().Language(LocalizationService::Get().Language());
MessageTeachingTipContent().Language(LocalizationService::Get().GetLanguage());
if (title.empty()) {
TitleTextBlock().Visibility(Visibility::Collapsed);