mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
PowerToys Run cache issue (#4472)
* Clean termination of powertoys process. * Fixed issue with run not responding to WM_CLOSE * Fixed serialization error in pinyin and image cache * Fixed merge conflict * Fixed nit wrt to master * Fixed undeterministic behaviour of Environment.Exit function * Update timing for terminate process
This commit is contained in:
committed by
GitHub
parent
aad2e8012b
commit
92fa8b7421
@@ -21,7 +21,7 @@ namespace Wox.Infrastructure
|
||||
{
|
||||
private readonly HanyuPinyinOutputFormat Format = new HanyuPinyinOutputFormat();
|
||||
private ConcurrentDictionary<string, string[][]> PinyinCache;
|
||||
private BinaryStorage<ConcurrentDictionary<string, string[][]>> _pinyinStorage;
|
||||
private BinaryStorage<Dictionary<string, string[][]>> _pinyinStorage;
|
||||
private Settings _settings;
|
||||
|
||||
public void Initialize([NotNull] Settings settings)
|
||||
@@ -36,8 +36,8 @@ namespace Wox.Infrastructure
|
||||
|
||||
Stopwatch.Normal("|Wox.Infrastructure.Alphabet.Initialize|Preload pinyin cache", () =>
|
||||
{
|
||||
_pinyinStorage = new BinaryStorage<ConcurrentDictionary<string, string[][]>>("Pinyin");
|
||||
PinyinCache = _pinyinStorage.TryLoad(new ConcurrentDictionary<string, string[][]>());
|
||||
_pinyinStorage = new BinaryStorage<Dictionary<string, string[][]>>("Pinyin");
|
||||
SetPinyinCacheAsDictionary(_pinyinStorage.TryLoad(new Dictionary<string, string[][]>()));
|
||||
|
||||
// force pinyin library static constructor initialize
|
||||
PinyinHelper.toHanyuPinyinStringArray('T', Format);
|
||||
@@ -79,7 +79,7 @@ namespace Wox.Infrastructure
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pinyinStorage.Save(PinyinCache);
|
||||
_pinyinStorage.Save(GetPinyinCacheAsDictionary());
|
||||
}
|
||||
|
||||
private static string[] EmptyStringArray = new string[0];
|
||||
@@ -185,5 +185,15 @@ namespace Wox.Infrastructure
|
||||
).ToArray();
|
||||
return combination;
|
||||
}
|
||||
|
||||
private Dictionary<string, string[][]> GetPinyinCacheAsDictionary()
|
||||
{
|
||||
return new Dictionary<string, string[][]>(PinyinCache);
|
||||
}
|
||||
|
||||
private void SetPinyinCacheAsDictionary(Dictionary<string, string[][]> usage)
|
||||
{
|
||||
PinyinCache = new ConcurrentDictionary<string, string[][]>(usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,16 @@ namespace Wox.Infrastructure.Image
|
||||
{
|
||||
return _data.Values.Distinct().Count();
|
||||
}
|
||||
|
||||
public Dictionary<string, int> GetUsageAsDictionary()
|
||||
{
|
||||
return new Dictionary<string, int>(Usage);
|
||||
}
|
||||
|
||||
public void SetUsageAsDictionary(Dictionary<string, int> usage)
|
||||
{
|
||||
Usage = new ConcurrentDictionary<string, int>(usage);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -13,7 +14,7 @@ namespace Wox.Infrastructure.Image
|
||||
public static class ImageLoader
|
||||
{
|
||||
private static readonly ImageCache ImageCache = new ImageCache();
|
||||
private static BinaryStorage<ConcurrentDictionary<string, int>> _storage;
|
||||
private static BinaryStorage<Dictionary<string, int>> _storage;
|
||||
private static readonly ConcurrentDictionary<string, string> GuidToKey = new ConcurrentDictionary<string, string>();
|
||||
private static IImageHashGenerator _hashGenerator;
|
||||
|
||||
@@ -32,9 +33,9 @@ namespace Wox.Infrastructure.Image
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
_storage = new BinaryStorage<ConcurrentDictionary<string, int>>("Image");
|
||||
_storage = new BinaryStorage<Dictionary<string, int>>("Image");
|
||||
_hashGenerator = new ImageHashGenerator();
|
||||
ImageCache.Usage = _storage.TryLoad(new ConcurrentDictionary<string, int>());
|
||||
ImageCache.SetUsageAsDictionary(_storage.TryLoad(new Dictionary<string, int>()));
|
||||
|
||||
foreach (var icon in new[] { Constant.DefaultIcon, Constant.ErrorIcon })
|
||||
{
|
||||
@@ -58,7 +59,7 @@ namespace Wox.Infrastructure.Image
|
||||
public static void Save()
|
||||
{
|
||||
ImageCache.Cleanup();
|
||||
_storage.Save(ImageCache.Usage);
|
||||
_storage.Save(ImageCache.GetUsageAsDictionary());
|
||||
}
|
||||
|
||||
private class ImageResult
|
||||
|
||||
Reference in New Issue
Block a user