From 7056be0870ecab828ca6b41416d33dc2bd1b15f3 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sun, 22 May 2016 05:30:38 +0100 Subject: [PATCH] Databinding for plugin tab + faster image load --- Wox.Core/Plugin/PluginManager.cs | 6 +- Wox.Core/UserSettings/PluginSettings.cs | 1 + Wox.Infrastructure/Image/ImageCache.cs | 3 + Wox.Infrastructure/Image/ImageLoader.cs | 8 +- .../Image/ImagePathConverter.cs | 25 --- Wox.Infrastructure/Wox.Infrastructure.csproj | 1 - Wox.Plugin/FodyWeavers.xml | 4 + Wox.Plugin/PluginMetadata.cs | 16 +- Wox.Plugin/PluginPair.cs | 6 +- Wox.Plugin/Wox.Plugin.csproj | 17 +- Wox.Plugin/packages.config | 2 + Wox.sln | 3 + Wox/App.xaml.cs | 2 +- Wox/FodyWeavers.xml | 4 + Wox/ResultListBox.xaml | 5 +- Wox/SettingWindow.xaml | 140 ++++++++------- Wox/SettingWindow.xaml.cs | 167 +++--------------- Wox/ViewModel/PluginViewModel.cs | 34 ++++ Wox/ViewModel/ResultViewModel.cs | 18 +- Wox/ViewModel/SettingWindowViewModel.cs | 83 ++++++++- Wox/Wox.csproj | 13 ++ Wox/packages.config | 2 + 22 files changed, 286 insertions(+), 274 deletions(-) delete mode 100644 Wox.Infrastructure/Image/ImagePathConverter.cs create mode 100644 Wox.Plugin/FodyWeavers.xml create mode 100644 Wox/FodyWeavers.xml create mode 100644 Wox/ViewModel/PluginViewModel.cs diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 3dc8156eda..a50c4b663e 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -87,7 +87,7 @@ namespace Wox.Core.Plugin API = API }); }); - pair.InitTime = milliseconds; + pair.Metadata.InitTime = milliseconds; InternationalizationManager.Instance.UpdatePluginMetadataTranslations(pair); }); @@ -167,8 +167,8 @@ namespace Wox.Core.Plugin results = pair.Plugin.Query(query) ?? results; UpdatePluginMetadata(results, metadata, query); }); - pair.QueryCount += 1; - pair.AvgQueryTime = pair.QueryCount == 1 ? milliseconds : (pair.AvgQueryTime + milliseconds) / 2; + metadata.QueryCount += 1; + metadata.AvgQueryTime = metadata.QueryCount == 1 ? milliseconds : (metadata.AvgQueryTime + milliseconds) / 2; } catch (Exception e) { diff --git a/Wox.Core/UserSettings/PluginSettings.cs b/Wox.Core/UserSettings/PluginSettings.cs index 267361c50e..bc19879129 100644 --- a/Wox.Core/UserSettings/PluginSettings.cs +++ b/Wox.Core/UserSettings/PluginSettings.cs @@ -22,6 +22,7 @@ namespace Wox.Core.UserSettings metadata.ActionKeywords = settings.ActionKeywords; metadata.ActionKeyword = settings.ActionKeywords[0]; } + metadata.Disabled = settings.Disabled; } else { diff --git a/Wox.Infrastructure/Image/ImageCache.cs b/Wox.Infrastructure/Image/ImageCache.cs index 1bf5fc795b..c5888a82ce 100644 --- a/Wox.Infrastructure/Image/ImageCache.cs +++ b/Wox.Infrastructure/Image/ImageCache.cs @@ -20,7 +20,10 @@ namespace Wox.Infrastructure.Image { TopUsedImages[path] = 1; } + } + public void Cleanup() + { if (TopUsedImages.Count > MaxCached) { var images = TopUsedImages.OrderByDescending(o => o.Value) diff --git a/Wox.Infrastructure/Image/ImageLoader.cs b/Wox.Infrastructure/Image/ImageLoader.cs index 95b4a48305..5db66024a7 100644 --- a/Wox.Infrastructure/Image/ImageLoader.cs +++ b/Wox.Infrastructure/Image/ImageLoader.cs @@ -43,6 +43,7 @@ namespace Wox.Infrastructure.Image public static void Save() { + _cache.Cleanup(); _storage.Save(); } @@ -115,11 +116,6 @@ namespace Wox.Infrastructure.Image var img = Load(i.Key); if (img != null) { - // todo happlebao magic - // the image created on other threads can be accessed from main ui thread, - // this line made it possible - // should be changed the Dispatcher.InvokeAsync in the future - img.Freeze(); ImageSources[i.Key] = img; } }); @@ -185,9 +181,9 @@ namespace Wox.Infrastructure.Image path = ErrorIcon; } } - ImageSources[path] = image; _cache.Add(path); + image.Freeze(); } return image; } diff --git a/Wox.Infrastructure/Image/ImagePathConverter.cs b/Wox.Infrastructure/Image/ImagePathConverter.cs deleted file mode 100644 index 0fd99c3719..0000000000 --- a/Wox.Infrastructure/Image/ImagePathConverter.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Globalization; -using System.Windows; -using System.Windows.Data; - -namespace Wox.Infrastructure.Image -{ - public class ImagePathConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null || value == DependencyProperty.UnsetValue) - { - return null; - } - var image = ImageLoader.Load(value.ToString()); - return image; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - return null; - } - } -} \ No newline at end of file diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index bb1a42bc6b..018d34a73b 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -78,7 +78,6 @@ - diff --git a/Wox.Plugin/FodyWeavers.xml b/Wox.Plugin/FodyWeavers.xml new file mode 100644 index 0000000000..bb0f322ee9 --- /dev/null +++ b/Wox.Plugin/FodyWeavers.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Wox.Plugin/PluginMetadata.cs b/Wox.Plugin/PluginMetadata.cs index bdf51d4030..6a8341cf00 100644 --- a/Wox.Plugin/PluginMetadata.cs +++ b/Wox.Plugin/PluginMetadata.cs @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; using System.IO; - +using Newtonsoft.Json; +using PropertyChanged; namespace Wox.Plugin { + [ImplementPropertyChanged] + [JsonObject(MemberSerialization.OptOut)] public class PluginMetadata { private string _pluginDirectory; @@ -13,9 +16,8 @@ namespace Wox.Plugin public string Version { get; set; } public string Language { get; set; } public string Description { get; set; } - public string Website { get; set; } - + public bool Disabled { get; set; } public string ExecuteFilePath { get; private set;} public string ExecuteFileName { get; set; } @@ -31,7 +33,6 @@ namespace Wox.Plugin } } - [Obsolete("Use ActionKeywords instead, because Wox now support multiple action keywords. This will be remove in v1.3.0")] public string ActionKeyword { get; set; } public List ActionKeywords { get; set; } @@ -45,5 +46,12 @@ namespace Wox.Plugin [Obsolete("Use IcoPath")] public string FullIcoPath => IcoPath; + + [JsonIgnore] + public long InitTime { get; set; } + [JsonIgnore] + public long AvgQueryTime { get; set; } + [JsonIgnore] + public int QueryCount { get; set; } } } diff --git a/Wox.Plugin/PluginPair.cs b/Wox.Plugin/PluginPair.cs index 7c64e9b0fe..f008889641 100644 --- a/Wox.Plugin/PluginPair.cs +++ b/Wox.Plugin/PluginPair.cs @@ -5,11 +5,7 @@ public IPlugin Plugin { get; internal set; } public PluginMetadata Metadata { get; internal set; } - internal long InitTime { get; set; } - - internal long AvgQueryTime { get; set; } - - internal int QueryCount { get; set; } + public override string ToString() { diff --git a/Wox.Plugin/Wox.Plugin.csproj b/Wox.Plugin/Wox.Plugin.csproj index 1332d30443..2aec1a0258 100644 --- a/Wox.Plugin/Wox.Plugin.csproj +++ b/Wox.Plugin/Wox.Plugin.csproj @@ -12,6 +12,8 @@ v4.5.2 512 + + true @@ -44,6 +46,10 @@ + + ..\packages\PropertyChanged.Fody.1.51.0\lib\dotnet\PropertyChanged.dll + False + @@ -75,8 +81,17 @@ - + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +