forked from mikemorain/Wox.Plugin.GoogleSearch
-
Notifications
You must be signed in to change notification settings - Fork 4
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 #13 from Yusyuriv/several-fixes
Implement a few small improvements
- Loading branch information
Showing
4 changed files
with
29 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
using System.Web; | ||
|
||
namespace Wox.Plugin.GoogleSearch | ||
{ | ||
public class GoogleSearchResult | ||
{ | ||
public string Name { get; set; } | ||
public string Url { get; set; } | ||
public string DecodedUrl => HttpUtility.UrlDecode(Url); | ||
} | ||
} | ||
} |
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,59 +1,52 @@ | ||
using Flow.Launcher.Plugin; | ||
using Flow.Launcher.Plugin.SharedCommands; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Wox.Plugin.GoogleSearch | ||
{ | ||
public class Main: IPlugin | ||
public class Main: IAsyncPlugin | ||
{ | ||
private string _pluginDirectory; | ||
|
||
private GoogleSearch _gs; | ||
|
||
private PluginInitContext context; | ||
private PluginInitContext _context; | ||
|
||
public List<Result> Query(Query query) | ||
{ | ||
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token) { | ||
await Task.Delay(300, token); | ||
var results = new List<Result>(); | ||
if (string.IsNullOrEmpty(query.Search)) return results; | ||
var searchResults = _gs.Search(query.Search, 8); | ||
var searchResults = await _gs.Search(query.Search, 8, token); | ||
foreach (var s in searchResults) | ||
{ | ||
var r = new Result | ||
{ | ||
Title = s.Name, | ||
SubTitle = s.Url, | ||
IcoPath = $"{_pluginDirectory}\\images\\icon.png", | ||
SubTitle = s.DecodedUrl, | ||
IcoPath = @"images\icon.png", | ||
Action = c => | ||
{ | ||
try | ||
{ | ||
context.API.OpenUrl(s.Url); | ||
_context.API.OpenUrl(s.Url); | ||
return true; | ||
} | ||
catch (Exception) | ||
{ | ||
return false; | ||
} | ||
}, | ||
ContextData = s | ||
}; | ||
results.Add(r); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
public void Init(PluginInitContext context) | ||
public async Task InitAsync(PluginInitContext context) | ||
Check warning on line 46 in Main.cs GitHub Actions / build
|
||
{ | ||
this.context = context; | ||
_pluginDirectory = context.CurrentPluginMetadata.PluginDirectory; | ||
_context = context; | ||
_gs = new GoogleSearch(); | ||
|
||
} | ||
} | ||
} | ||
} |
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