mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Fix ResourceMerger
1. Fix duplication for loading resource. 2. Fix null reference when plugin is not loaded. 3. speedup.
This commit is contained in:
@@ -1,20 +1,42 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Wox.Core.i18n;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.UI
|
||||
{
|
||||
public class ResourceMerger
|
||||
public static class ResourceMerger
|
||||
{
|
||||
internal static void ApplyResources()
|
||||
private static void RemoveResource(string resourceDirectoryName)
|
||||
{
|
||||
Application.Current.Resources.MergedDictionaries.Clear();
|
||||
ApplyPluginLanguages();
|
||||
ApplyThemeAndLanguageResources();
|
||||
var mergedDictionaries = Application.Current.Resources.MergedDictionaries;
|
||||
foreach (var resource in mergedDictionaries)
|
||||
{
|
||||
int directoryPosition = resource.Source.Segments.Length - 2;
|
||||
string currentDirectoryName = resource.Source.Segments[directoryPosition];
|
||||
if (currentDirectoryName == resourceDirectoryName)
|
||||
{
|
||||
mergedDictionaries.Remove(resource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ApplyThemeAndLanguageResources()
|
||||
public static void ApplyThemeResource()
|
||||
{
|
||||
RemoveResource(Theme.Theme.DirectoryName);
|
||||
ApplyUIResources();
|
||||
}
|
||||
|
||||
public static void ApplyLanguageResources()
|
||||
{
|
||||
RemoveResource(Internationalization.DirectoryName);
|
||||
ApplyUIResources();
|
||||
}
|
||||
|
||||
private static void ApplyUIResources()
|
||||
{
|
||||
var UIResources = AssemblyHelper.LoadInterfacesFromAppDomain<IUIResource>();
|
||||
foreach (var uiResource in UIResources)
|
||||
@@ -25,6 +47,7 @@ namespace Wox.Core.UI
|
||||
|
||||
internal static void ApplyPluginLanguages()
|
||||
{
|
||||
RemoveResource(PluginManager.DirectoryName);
|
||||
var pluginI18ns = AssemblyHelper.LoadInterfacesFromAppDomain<IPluginI18n>();
|
||||
foreach (var pluginI18n in pluginI18ns)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user