Skip to content

Commit

Permalink
Internet availability checks
Browse files Browse the repository at this point in the history
  • Loading branch information
konraddysput committed Sep 6, 2024
1 parent 59d3cfb commit 68b0554
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Runtime/BacktraceDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ internal void Update()
}
if (_breadcrumbs != null)
{
_breadcrumbs.Update();
_breadcrumbs.Update(Time.unscaledTime);
}
LastFrameTime = Time.unscaledTime;
if (!DatabaseSettings.AutoSendMode)
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Model/Breadcrumbs/BacktraceBreadcrumbs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ public double BreadcrumbId()
return LogManager.BreadcrumbId();
}

public void Update()
public void Update(float time)
{
EventHandler.Update();
EventHandler.Update(time);
}

public static bool CanStoreBreadcrumbs(UnityEngineLogLevel logLevel, BacktraceBreadcrumbType backtraceBreadcrumbsLevel)
Expand Down
11 changes: 10 additions & 1 deletion Runtime/Model/Breadcrumbs/BacktraceBreadcrumbsEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ internal sealed class BacktraceBreadcrumbsEventHandler
private BacktraceBreadcrumbType _registeredLevel;
private NetworkReachability _networkStatus = NetworkReachability.NotReachable;
private Thread _thread;
private float _lastUpdateTime = 0;

// time in seconds between internet availability checks
private float INTERNET_AVAILABILITY_CHECK_INTERVAL_SEC = 30;
public BacktraceBreadcrumbsEventHandler(BacktraceBreadcrumbs breadcrumbs)
{
_thread = Thread.CurrentThread;
Expand Down Expand Up @@ -151,8 +155,13 @@ private void LogNewNetworkStatus(NetworkReachability status)
Log(string.Format("Network:{0}", status), LogType.Log, BreadcrumbLevel.System);
}

internal void Update()
internal void Update(float time)
{
if (time - _lastUpdateTime < INTERNET_AVAILABILITY_CHECK_INTERVAL_SEC && _lastUpdateTime != 0)
{
return;
}
_lastUpdateTime = time;
if (_registeredLevel.HasFlag(BacktraceBreadcrumbType.System) && Application.internetReachability != _networkStatus)
{
LogNewNetworkStatus(Application.internetReachability);
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Model/Breadcrumbs/IBacktraceBreadcrumbs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface IBacktraceBreadcrumbs
string GetBreadcrumbLogPath();
double BreadcrumbId();
void UnregisterEvents();
void Update();
void Update(float time);
string Archive();
}
}

0 comments on commit 68b0554

Please sign in to comment.