Skip to content

Commit

Permalink
feat: display error message when parsing config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Daydreamer-riri committed Apr 25, 2024
1 parent 6ca2536 commit fd02007
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<None Update="Images\Suggestion.light.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Images\Warn.dark.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Images\Warn.light.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion Community.PowerToys.Run.Plugin.WebSearchShortcut/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ internal Main(WebSearchShortcutSettings settings, IWebSearchShortcutStorage webS
{ "Config", @"Images\Config.light.png" },
{ "Reload", @"Images\Reload.light.png" },
{ "Suggestion", @"Images\Suggestion.light.png" },
{ "Warn", @"Images\Warn.light.png" }
};

private bool Disposed { get; set; }
Expand Down Expand Up @@ -141,6 +142,21 @@ public List<Result> Query(Query query)
];
}


if (!string.IsNullOrEmpty(WebSearchShortcutStorage.LoadError))
{
return
[
new()
{
Title = "Config parse error (Please check the config file)",
SubTitle = $"Error: {WebSearchShortcutStorage.LoadError}",
IcoPath = IconPath["Warn"],
ToolTipData = new ToolTipData("Config error", $"{WebSearchShortcutStorage.LoadError}")
}
];
}

List<Result> results = [];

if (string.IsNullOrEmpty(args))
Expand Down Expand Up @@ -173,7 +189,7 @@ public List<Result> Query(Query query)

public List<Result> Query(Query query, bool delayedExecution)
{
if (query?.Search is null || !delayedExecution)
if (query?.Search is null || !delayedExecution || !string.IsNullOrEmpty(WebSearchShortcutStorage.LoadError))
{
return ResetSuggestionsCache();
}
Expand Down
7 changes: 7 additions & 0 deletions Community.PowerToys.Run.Plugin.WebSearchShortcut/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public interface IWebSearchShortcutStorage
/// </summary>
void Save();
string GetPath();

string? LoadError { get; }
}

/// <inheritdoc/>
Expand All @@ -58,6 +60,8 @@ public class WebSearchShortcutStorage : IWebSearchShortcutStorage
/// </summary>
public const string DefaultFileName = "WebSearchShortcutStorage.json";

public string? LoadError { get; private set; }

private static readonly JsonSerializerOptions _serializerOptions = new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Expand Down Expand Up @@ -136,9 +140,12 @@ public void Load()
item.Name = key;
}
DownLoadIcon();

LoadError = null;
}
catch (Exception ex)
{
LoadError = ex.Message;
Log.Exception("Load failed: " + path, ex, GetType());
}
}
Expand Down

0 comments on commit fd02007

Please sign in to comment.