From 515ce04e34eb92167aa54d476e9ef022cdc37b0f Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 22 Apr 2020 15:58:19 +0800 Subject: [PATCH 01/21] no link target redirection --- Plugins/Wox.Plugin.Program/Programs/Win32.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Programs/Win32.cs b/Plugins/Wox.Plugin.Program/Programs/Win32.cs index 0cc0b76c8..ae03aefee 100644 --- a/Plugins/Wox.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Wox.Plugin.Program/Programs/Win32.cs @@ -176,7 +176,7 @@ private static Win32 Win32Program(string path) return new Win32() { Valid = false, Enabled = false }; } } - + // todo lnk.resolve has been removed, need test to get description and image for lnk only instead of target private static Win32 LnkProgram(string path) { var program = Win32Program(path); @@ -185,9 +185,6 @@ private static Win32 LnkProgram(string path) var link = new ShellLink(); const uint STGM_READ = 0; ((IPersistFile)link).Load(path, STGM_READ); - var hwnd = new _RemotableHandle(); - link.Resolve(ref hwnd, 0); - const int MAX_DESCRIPTION = 150; StringBuilder bufferDescription = new StringBuilder(MAX_DESCRIPTION); String description = String.Empty; From 2ee5c8a54dcf51c52d72e0d69313913a91606c89 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 22 Apr 2020 15:58:50 +0800 Subject: [PATCH 02/21] manually init static class --- Wox.Infrastructure/Constant.cs | 47 ++++++++++++++++++++++++++-------- Wox/App.xaml.cs | 2 ++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Wox.Infrastructure/Constant.cs b/Wox.Infrastructure/Constant.cs index 8c57bf20d..d36a5695f 100644 --- a/Wox.Infrastructure/Constant.cs +++ b/Wox.Infrastructure/Constant.cs @@ -1,6 +1,8 @@ +using System; using System.Diagnostics; using System.IO; using System.Reflection; +using JetBrains.Annotations; namespace Wox.Infrastructure { @@ -9,21 +11,46 @@ public static class Constant public const string Wox = "Wox"; public const string Plugins = "Plugins"; - private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); - public static readonly string ProgramDirectory = Directory.GetParent(Assembly.Location.NonNull()).ToString(); - public static readonly string ExecutablePath = Path.Combine(ProgramDirectory, Wox + ".exe"); - public static readonly string ApplicationDirectory = Directory.GetParent(ProgramDirectory).ToString(); - public static readonly string RootDirectory = Directory.GetParent(ApplicationDirectory).ToString(); - - public static readonly string PreinstalledDirectory = Path.Combine(ProgramDirectory, Plugins); + private static Assembly Assembly; + public static string ProgramDirectory; + public static string ExecutablePath; + public static string ApplicationDirectory; + public static string RootDirectory; + + public static string PreinstalledDirectory; public const string Issue = "https://github.com/Wox-launcher/Wox/issues/new"; - public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location.NonNull()).ProductVersion; + public static string Version; public static readonly int ThumbnailSize = 64; - public static readonly string DefaultIcon = Path.Combine(ProgramDirectory, "Images", "app.png"); - public static readonly string ErrorIcon = Path.Combine(ProgramDirectory, "Images", "app_error.png"); + public static string ImagesDirectory; + public static string DefaultIcon; + public static string ErrorIcon; public static string PythonPath; public static string EverythingSDKPath; + + public static void Initialize(string workingDirectory = "") + { + Assembly = Assembly.GetExecutingAssembly(); + Version = FileVersionInfo.GetVersionInfo(Assembly.Location.NonNull()).ProductVersion; + + if (String.IsNullOrEmpty(workingDirectory)) + { + ProgramDirectory = Directory.GetParent(Assembly.Location.NonNull()).ToString(); + } + else + { + ProgramDirectory = workingDirectory; + } + + ApplicationDirectory = Directory.GetParent(ProgramDirectory).ToString(); + RootDirectory = Directory.GetParent(ApplicationDirectory).ToString(); + ExecutablePath = Path.Combine(ProgramDirectory, Wox + ".exe"); + ImagesDirectory = Path.Combine(ProgramDirectory, "Images"); + PreinstalledDirectory = Path.Combine(ProgramDirectory, Plugins); + DefaultIcon = Path.Combine(ImagesDirectory, "app.png"); + ErrorIcon = Path.Combine(ImagesDirectory, "app_error.png"); + + } } } diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index cabc46f09..5506bbcb7 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -69,6 +69,8 @@ private void OnStartup(object sender, StartupEventArgs e) { Stopwatch.Normal("|App.OnStartup|Startup cost", () => { + Constant.Initialize(); + _portable.PreStartCleanUpAfterPortabilityUpdate(); Log.Info("|App.OnStartup|Begin Wox startup ----------------------------------------------------"); From a5b135b6000e8ab4fd826d1f93c7b57c9914771f Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 22 Apr 2020 15:59:39 +0800 Subject: [PATCH 03/21] move test location --- Wox.Test/{Plugins => }/PluginInitTest.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Wox.Test/{Plugins => }/PluginInitTest.cs (100%) diff --git a/Wox.Test/Plugins/PluginInitTest.cs b/Wox.Test/PluginInitTest.cs similarity index 100% rename from Wox.Test/Plugins/PluginInitTest.cs rename to Wox.Test/PluginInitTest.cs From 19a031197e015e5093b7f6c6c9f787439c498820 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 22 Apr 2020 16:18:28 +0800 Subject: [PATCH 04/21] image loader is not thread safe will cause null exception when execute parallel --- Wox.Infrastructure/Image/ImageLoader.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Wox.Infrastructure/Image/ImageLoader.cs b/Wox.Infrastructure/Image/ImageLoader.cs index 528900ce7..05d4b1b72 100644 --- a/Wox.Infrastructure/Image/ImageLoader.cs +++ b/Wox.Infrastructure/Image/ImageLoader.cs @@ -42,16 +42,21 @@ public static void Initialize() img.Freeze(); ImageCache[icon] = img; } + Task.Run(() => { Stopwatch.Normal("|ImageLoader.Initialize|Preload images cost", () => { - ImageCache.Usage.AsParallel().ForAll(x => + foreach (string key in ImageCache.Usage.Keys) { - Load(x.Key); - }); + Load(key); + } }); - Log.Info($"|ImageLoader.Initialize|Number of preload images is <{ImageCache.Usage.Count}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}"); + string info = "|ImageLoader.Initialize|" + + $"Number of preload images is <{ImageCache.Usage.Count}>, " + + $"Images Number: {ImageCache.CacheSize()}, " + + $"Unique Items {ImageCache.UniqueImagesInCache()}"; + Log.Info(info); }); } From d43e3d82ca408bf3cc274356a3b7de2efcb395cb Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 22 Apr 2020 16:26:17 +0800 Subject: [PATCH 05/21] add nonoui option for simple test --- Wox/ViewModel/MainViewModel.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index de5b4261a..3ceff4216 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -41,13 +41,13 @@ public class MainViewModel : BaseModel, ISavable private CancellationToken _updateToken; private bool _saved; - private readonly Internationalization _translator = InternationalizationManager.Instance; + private readonly Internationalization _translator; #endregion #region Constructor - public MainViewModel(Settings settings) + public MainViewModel(Settings settings, bool useApp = true) { _saved = false; _queryTextBeforeLeaveResults = ""; @@ -67,14 +67,21 @@ public MainViewModel(Settings settings) Results = new ResultsViewModel(_settings); History = new ResultsViewModel(_settings); _selectedResults = Results; + + if (useApp) + { + InitializeKeyCommands(); + RegisterResultsUpdatedEvent(); - InitializeKeyCommands(); - RegisterResultsUpdatedEvent(); + SetHotkey(_settings.Hotkey, OnHotkey); + SetCustomPluginHotkey(); - SetHotkey(_settings.Hotkey, OnHotkey); - SetCustomPluginHotkey(); + _translator = InternationalizationManager.Instance; + } } + + private void RegisterResultsUpdatedEvent() { foreach (var pair in PluginManager.GetPluginsForInterface()) From 6b2e11407b657dd55682155a7dc287b875c7772c Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 22 Apr 2020 16:26:37 +0800 Subject: [PATCH 06/21] update nuit version and set correct output path --- Wox.Test/Wox.Test.csproj | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Wox.Test/Wox.Test.csproj b/Wox.Test/Wox.Test.csproj index 912425d14..a7f10cffa 100644 --- a/Wox.Test/Wox.Test.csproj +++ b/Wox.Test/Wox.Test.csproj @@ -20,7 +20,7 @@ true full false - bin\Debug\ + ..\Output\Debug\ DEBUG;TRACE prompt 4 @@ -29,12 +29,15 @@ pdbonly true - bin\Release\ + ..\Output\Release\ TRACE prompt 4 false + + + @@ -44,7 +47,8 @@ Properties\SolutionAssemblyInfo.cs - + + @@ -66,6 +70,10 @@ {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} Wox.Plugin + + {DB90F671-D861-46BB-93A3-F1304F5BA1C5} + Wox + @@ -75,9 +83,12 @@ 3.12.0 - 3.15.1 + 3.16.1 + runtime; build; native; contentfiles; analyzers; buildtransitive + all +