-
-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2563 from Flow-Launcher/dev
Release 1.17.2
- Loading branch information
Showing
12 changed files
with
132 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Flow.Launcher.Infrastructure.Http; | ||
using Flow.Launcher.Infrastructure.Logger; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Text.Json; | ||
|
||
namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources | ||
{ | ||
public class DuckDuckGo : SuggestionSource | ||
{ | ||
public override async Task<List<string>> SuggestionsAsync(string query, CancellationToken token) | ||
{ | ||
// When the search query is empty, DuckDuckGo returns `[]`. When it's not empty, it returns data | ||
// in the following format: `["query", ["suggestion1", "suggestion2", ...]]`. | ||
if (string.IsNullOrEmpty(query)) | ||
{ | ||
return new List<string>(); | ||
} | ||
|
||
try | ||
{ | ||
const string api = "https://duckduckgo.com/ac/?type=list&q="; | ||
|
||
await using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeDataString(query), token: token).ConfigureAwait(false); | ||
|
||
using var json = await JsonDocument.ParseAsync(resultStream, cancellationToken: token); | ||
|
||
var results = json.RootElement.EnumerateArray().ElementAt(1); | ||
|
||
return results.EnumerateArray().Select(o => o.GetString()).ToList(); | ||
|
||
} | ||
catch (Exception e) when (e is HttpRequestException or {InnerException: TimeoutException}) | ||
{ | ||
Log.Exception("|DuckDuckGo.Suggestions|Can't get suggestion from DuckDuckGo", e); | ||
return null; | ||
} | ||
catch (JsonException e) | ||
{ | ||
Log.Exception("|DuckDuckGo.Suggestions|can't parse suggestions", e); | ||
return new List<string>(); | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "DuckDuckGo"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version: '1.17.1.{build}' | ||
version: '1.17.2.{build}' | ||
|
||
init: | ||
- ps: | | ||
|