Skip to content

Commit d5970ad

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into JsonRevise
2 parents 2a03bba + 890f114 commit d5970ad

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Flow.Launcher.Infrastructure;
22
using System;
3+
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
56
using System.Reflection;
@@ -11,17 +12,23 @@ internal class PluginAssemblyLoader : AssemblyLoadContext
1112
{
1213
private readonly AssemblyDependencyResolver dependencyResolver;
1314

14-
private readonly AssemblyDependencyResolver referencedPluginPackageDependencyResolver;
15-
1615
private readonly AssemblyName assemblyName;
1716

17+
private static readonly List<Assembly> loadedAssembly;
18+
19+
static PluginAssemblyLoader()
20+
{
21+
loadedAssembly = new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
22+
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) =>
23+
{
24+
loadedAssembly.Add(args.LoadedAssembly);
25+
};
26+
}
27+
1828
internal PluginAssemblyLoader(string assemblyFilePath)
1929
{
2030
dependencyResolver = new AssemblyDependencyResolver(assemblyFilePath);
2131
assemblyName = new AssemblyName(Path.GetFileNameWithoutExtension(assemblyFilePath));
22-
23-
referencedPluginPackageDependencyResolver =
24-
new AssemblyDependencyResolver(Path.Combine(Constant.ProgramDirectory, "Flow.Launcher.Plugin.dll"));
2532
}
2633

2734
internal Assembly LoadAssemblyAndDependencies()
@@ -33,10 +40,10 @@ protected override Assembly Load(AssemblyName assemblyName)
3340
{
3441
string assemblyPath = dependencyResolver.ResolveAssemblyToPath(assemblyName);
3542

36-
// When resolving dependencies, ignore assembly depenedencies that already exits with Flow.Launcher.Plugin
37-
// Otherwise will get unexpected behaviour with plugins, e.g. JsonIgnore attribute not honored in WebSearch or other plugins
38-
// that use Newtonsoft.Json
39-
if (assemblyPath == null || ExistsInReferencedPluginPackage(assemblyName))
43+
// When resolving dependencies, ignore assembly depenedencies that already exits with Flow.Launcher
44+
// Otherwise duplicate assembly will be loaded and some weird behavior will occur, such as WinRT.Runtime.dll
45+
// will fail due to loading multiple versions in process, each with their own static instance of registration state
46+
if (assemblyPath == null || ExistsInReferencedPackage(assemblyName))
4047
return null;
4148

4249
return LoadFromAssemblyPath(assemblyPath);
@@ -45,13 +52,14 @@ protected override Assembly Load(AssemblyName assemblyName)
4552
internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, params Type[] types)
4653
{
4754
var allTypes = assembly.ExportedTypes;
48-
4955
return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Intersect(types).Any());
5056
}
5157

52-
internal bool ExistsInReferencedPluginPackage(AssemblyName assemblyName)
58+
internal bool ExistsInReferencedPackage(AssemblyName assemblyName)
5359
{
54-
return referencedPluginPackageDependencyResolver.ResolveAssemblyToPath(assemblyName) != null;
60+
if (loadedAssembly.Any(a => a.FullName == assemblyName.FullName))
61+
return true;
62+
return false;
5563
}
5664
}
57-
}
65+
}

Flow.Launcher.Core/Updater.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
8787
UpdateManager.RestartApp(Constant.ApplicationFileName);
8888
}
8989
}
90-
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e is TaskCanceledException)
90+
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e.InnerException is TimeoutException)
9191
{
9292
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
9393
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),

Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ private async Task<IEnumerable<Result>> SuggestionsAsync(string keyword, string
125125
{
126126
var suggestions = await source.Suggestions(keyword, token).ConfigureAwait(false);
127127

128-
if (token.IsCancellationRequested)
129-
return null;
128+
token.ThrowIfCancellationRequested();
130129

131130
var resultsFromSuggestion = suggestions?.Select(o => new Result
132131
{

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
2525
const string api = "http://suggestion.baidu.com/su?json=1&wd=";
2626
result = await Http.GetAsync(api + Uri.EscapeUriString(query), token).ConfigureAwait(false);
2727
}
28-
catch (TaskCanceledException)
28+
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
2929
{
30+
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
3031
return null;
3132
}
32-
catch (HttpRequestException e)
33+
catch (OperationCanceledException)
3334
{
34-
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
3535
return null;
3636
}
3737

38+
3839
if (string.IsNullOrEmpty(result)) return new List<string>();
3940
Match match = _reg.Match(result);
4041
if (match.Success)
@@ -44,7 +45,7 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
4445
{
4546
json = JsonDocument.Parse(match.Groups[1].Value);
4647
}
47-
catch(JsonException e)
48+
catch (JsonException e)
4849
{
4950
Log.Exception("|Baidu.Suggestions|can't parse suggestions", e);
5051
return new List<string>();

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
4040

4141

4242
}
43-
catch (TaskCanceledException)
43+
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
4444
{
45-
return new List<string>();
45+
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
46+
return null;
4647
}
47-
catch (HttpRequestException e)
48+
catch (OperationCanceledException)
4849
{
49-
Log.Exception("|Bing.Suggestions|Can't get suggestion from Bing", e);
5050
return new List<string>();
5151
}
5252
catch (JsonException e)

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
2222

2323
using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeUriString(query)).ConfigureAwait(false);
2424

25-
using var json = await JsonDocument.ParseAsync(resultStream);
25+
using var json = await JsonDocument.ParseAsync(resultStream, cancellationToken: token);
2626

2727
if (json == null)
2828
return new List<string>();
@@ -32,13 +32,13 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
3232
return results.EnumerateArray().Select(o => o.GetString()).ToList();
3333

3434
}
35-
catch (TaskCanceledException)
35+
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
3636
{
37-
return new List<string>();
37+
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
38+
return null;
3839
}
39-
catch (HttpRequestException e)
40+
catch (OperationCanceledException)
4041
{
41-
Log.Exception("|Google.Suggestions|Can't get suggestion from google", e);
4242
return new List<string>();
4343
}
4444
catch (JsonException e)

Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Name": "Web Searches",
2626
"Description": "Provide the web search ability",
2727
"Author": "qianlifeng",
28-
"Version": "1.3.2",
28+
"Version": "1.3.3",
2929
"Language": "csharp",
3030
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
3131
"ExecuteFileName": "Flow.Launcher.Plugin.WebSearch.dll",

0 commit comments

Comments
 (0)