Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Flow.Launcher/Storage/QueryHistory.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Flow.Launcher.Plugin;
using System.Text.Json.Serialization;

namespace Flow.Launcher.Storage
{
public class History
{
public List<HistoryItem> Items { get; set; } = new List<HistoryItem>();
[JsonInclude]
public List<HistoryItem> Items { get; private set; } = new List<HistoryItem>();

private int _maxHistory = 300;

Expand Down
12 changes: 2 additions & 10 deletions Flow.Launcher/Storage/TopMostRecord.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin;

Expand All @@ -9,14 +7,8 @@ namespace Flow.Launcher.Storage
// todo this class is not thread safe.... but used from multiple threads.
public class TopMostRecord
{
/// <summary>
/// You should not directly access this field
/// <para>
/// It is public due to System.Text.Json limitation in version 3.1
/// </para>
/// </summary>
/// TODO: Set it to private
public Dictionary<string, Record> records { get; set; } = new Dictionary<string, Record>();
[JsonInclude]
public Dictionary<string, Record> records { get; private set; } = new Dictionary<string, Record>();

internal bool IsTopMost(Result result)
{
Expand Down
11 changes: 2 additions & 9 deletions Flow.Launcher/Storage/UserSelectedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ namespace Flow.Launcher.Storage
{
public class UserSelectedRecord
{
/// <summary>
/// You should not directly access this field
/// <para>
/// It is public due to System.Text.Json limitation in version 3.1
/// </para>
/// </summary>
/// TODO: Set it to private
[JsonPropertyName("records")]
public Dictionary<string, int> records { get; set; }
[JsonInclude]
public Dictionary<string, int> records { get; private set; }

public UserSelectedRecord()
{
Expand Down
29 changes: 15 additions & 14 deletions Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ class Bing : SuggestionSource
{
public override async Task<List<string>> Suggestions(string query, CancellationToken token)
{
JsonElement json;

try
{
const string api = "https://api.bing.com/qsonhs.aspx?q=";

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

json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token)).RootElement.GetProperty("AS");
using var json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token));
var root = json.RootElement.GetProperty("AS");

if (root.GetProperty("FullResults").GetInt32() == 0)
return new List<string>();

return root.GetProperty("Results")
.EnumerateArray()
.SelectMany(r => r.GetProperty("Suggests")
.EnumerateArray()
.Select(s => s.GetProperty("Txt").GetString()))
.ToList();



}
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
Expand All @@ -41,18 +53,7 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
{
Log.Exception("|Bing.Suggestions|can't parse suggestions", e);
return new List<string>();
}

if (json.GetProperty("FullResults").GetInt32() == 0)
return new List<string>();

return json.GetProperty("Results")
.EnumerateArray()
.SelectMany(r => r.GetProperty("Suggests")
.EnumerateArray()
.Select(s => s.GetProperty("Txt").GetString()))
.ToList();

}
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ public class Google : SuggestionSource
{
public override async Task<List<string>> Suggestions(string query, CancellationToken token)
{
JsonDocument json;

try
{
const string api = "https://www.google.com/complete/search?output=chrome&q=";

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

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

if (json == null)
return new List<string>();

var results = json.RootElement.EnumerateArray().ElementAt(1);

return results.EnumerateArray().Select(o => o.GetString()).ToList();

}
catch (Exception e) when (e is HttpRequestException || e.InnerException is TimeoutException)
Expand All @@ -41,11 +46,6 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
Log.Exception("|Google.Suggestions|can't parse suggestions", e);
return new List<string>();
}

var results = json?.RootElement.EnumerateArray().ElementAt(1);

return results?.EnumerateArray().Select(o => o.GetString()).ToList() ?? new List<string>();

}

public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.WebSearch/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"Name": "Web Searches",
"Description": "Provide the web search ability",
"Author": "qianlifeng",
"Version": "1.3.3",
"Version": "1.3.4",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.WebSearch.dll",
Expand Down