Skip to content

Commit

Permalink
feat: add bucket when needed for package
Browse files Browse the repository at this point in the history
  • Loading branch information
Quriz committed Dec 18, 2023
1 parent d03d799 commit 022474c
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 112 deletions.
32 changes: 22 additions & 10 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public class Main : IPlugin, IPluginI18n, IDelayedExecutionPlugin, IContextMenu,

private static string RepositoryNewIssueUrl => "https://github.com/Quriz/PowerToysRunScoop/issues/new?labels=bug&title={0}&body={1}";

private Scoop _scoop;
private Action<string> onPluginError;

private Scoop _scoop;
private bool _initFailed;
private Exception _initException;

private PluginInitContext _context;
private static string _iconPath;
private bool _disposed;
Expand All @@ -52,7 +56,15 @@ public void Init(PluginInitContext context)

DefaultBrowserInfo.UpdateIfTimePassed();

_scoop = new();
try
{
_scoop = new Scoop();
}
catch (Exception e)
{
_initFailed = true;
_initException = e;
}

onPluginError = message =>
{
Expand All @@ -65,9 +77,9 @@ public void Init(PluginInitContext context)

public List<Result> Query(Query query, bool delayedExecution)
{
if (_scoop.HasApiKeyError)
if (_initFailed)
{
return ApiKeyErrorQueryResult();
return InitErrorQueryResult();
}

if (!delayedExecution || query is null || string.IsNullOrWhiteSpace(query.Search))
Expand All @@ -92,21 +104,21 @@ public List<Result> Query(Query query, bool delayedExecution)
return DefaultQueryResult();
}

private List<Result> ApiKeyErrorQueryResult()
private List<Result> InitErrorQueryResult()
{
return
[
new Result
{
Title = Properties.Resources.plugin_error_api_key,
SubTitle = Properties.Resources.plugin_error_api_key_sub,
Title = Properties.Resources.error_init,
SubTitle = Properties.Resources.error_init_sub,
QueryTextDisplay = " ", // Empty string doesn't work
IcoPath = _iconPath,
Action = _ =>
{
// Create a new issue describing the error
var title = HttpUtility.UrlEncode("Bug: Can't get API key");
var body = HttpUtility.UrlEncode($"Exception:\n{_scoop.ApiKeyErrorText}");
var title = HttpUtility.UrlEncode("Bug: Initialization Failed");
var body = HttpUtility.UrlEncode(_initException.ToString());
return OpenUrlInBrowser(string.Format(CultureInfo.CurrentCulture, RepositoryNewIssueUrl, title, body));
},
},
Expand Down Expand Up @@ -217,7 +229,7 @@ private bool OpenUrlInBrowser(string url)
return true;
}

onPluginError(string.Format(CultureInfo.CurrentCulture, Properties.Resources.plugin_error_homepage, DefaultBrowserInfo.Name ?? DefaultBrowserInfo.MSEdgeName));
onPluginError(string.Format(CultureInfo.CurrentCulture, Properties.Resources.error_homepage, DefaultBrowserInfo.Name ?? DefaultBrowserInfo.MSEdgeName));
return false;
}

Expand Down
39 changes: 24 additions & 15 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<data name="context_menu_update" xml:space="preserve">
<value>Update (Ctrl+U)</value>
</data>
<data name="plugin_error_homepage" xml:space="preserve">
<data name="error_homepage" xml:space="preserve">
<value>Failed to open {0}.</value>
</data>
<data name="context_menu_homepage" xml:space="preserve">
Expand All @@ -144,10 +144,13 @@
<data name="plugin_description_sub" xml:space="preserve">
<value>Search, install, update, and uninstall Scoop packages.</value>
</data>
<data name="plugin_error_api_key" xml:space="preserve">
<value>Failed to get API key for search.</value>
<data name="error_init" xml:space="preserve">
<value>Failed to initialize plugin.</value>
</data>
<data name="plugin_error_api_key_sub" xml:space="preserve">
<data name="error_init_sub" xml:space="preserve">
<value>If you believe this is a plugin error, press Enter to open an issue.</value>
</data>
<data name="message_add_bucket" xml:space="preserve">
<value>To install this package, you need to add the bucket '{0}'. Do you want to continue?</value>
</data>
</root>
Loading

0 comments on commit 022474c

Please sign in to comment.