Skip to content

Commit

Permalink
[PTRun]Add logs to check Web Browser detection (#18831)
Browse files Browse the repository at this point in the history
* [PTRun]Add logs to check Web Browser detection

* Use proper initial value

* Add punctuation to the end of the log message
  • Loading branch information
jaimecbernardo committed Jun 14, 2022
1 parent d7c2fe3 commit 74ba26e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/modules/launcher/Wox.Infrastructure/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static bool OpenCommandInShell(string path, string pattern, string argume
{
if (string.IsNullOrEmpty(pattern))
{
Log.Warn("Trying to run OpenCommandInShell with an empty pattern. The default browser definition might have issues.", typeof(Helper));
Log.Warn($"Trying to run OpenCommandInShell with an empty pattern. The default browser definition might have issues. Path: '${path ?? string.Empty}' ; Arguments: '${arguments ?? string.Empty}' ; Working Directory: '${workingDir ?? string.Empty}'", typeof(Helper));
}
else if (pattern.Contains("%1", StringComparison.Ordinal))
{
Expand Down
17 changes: 13 additions & 4 deletions src/modules/launcher/Wox.Plugin/Common/DefaultBrowserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Wox.Plugin.Common
public static class DefaultBrowserInfo
{
private static readonly object _updateLock = new object();
private static int _lastUpdateTickCount = -1;

/// <summary>Gets the path to the MS Edge browser executable.</summary>
public static string MSEdgePath =>
Expand All @@ -41,16 +40,20 @@ public static class DefaultBrowserInfo

public static bool IsDefaultBrowserSet { get => !string.IsNullOrEmpty(Path); }

public const int UpdateTimeout = 300;
public const long UpdateTimeout = 300;

private static long _lastUpdateTickCount = -UpdateTimeout;

private static bool haveIRanUpdateOnce;

/// <summary>
/// Updates only if at least more than 300ms has passed since the last update, to avoid multiple calls to <see cref="Update"/>.
/// (because of multiple plugins calling update at the same time.)
/// </summary>
public static void UpdateIfTimePassed()
{
int curTickCount = Environment.TickCount;
if (curTickCount - _lastUpdateTickCount > UpdateTimeout)
long curTickCount = Environment.TickCount64;
if (curTickCount - _lastUpdateTickCount >= UpdateTimeout)
{
_lastUpdateTickCount = curTickCount;
Update();
Expand All @@ -66,6 +69,12 @@ public static void Update()
{
lock (_updateLock)
{
if (!haveIRanUpdateOnce)
{
Log.Warn("I've tried updating the chosen Web Browser info at least once.", typeof(DefaultBrowserInfo));
haveIRanUpdateOnce = true;
}

try
{
string progId = GetRegistryValue(
Expand Down

0 comments on commit 74ba26e

Please sign in to comment.