mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-23 12:15:48 +02:00
Halt reloading after subprocess crash if it happens too often
This commit is contained in:
parent
b9af966849
commit
c303346bc3
@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using CefSharp;
|
||||
using CefSharp.Handler;
|
||||
using TweetImpl.CefSharp.Adapters;
|
||||
@ -7,11 +8,11 @@ namespace TweetImpl.CefSharp.Handlers {
|
||||
sealed class CefRequestHandler : RequestHandler {
|
||||
public RequestHandlerLogic<IRequest> Logic { get; }
|
||||
|
||||
private readonly bool autoReload;
|
||||
private readonly AutoReloader? autoReloader;
|
||||
|
||||
public CefRequestHandler(CefLifeSpanHandler lifeSpanHandler, bool autoReload) {
|
||||
this.Logic = new RequestHandlerLogic<IRequest>(CefRequestAdapter.Instance, lifeSpanHandler.Logic);
|
||||
this.autoReload = autoReload;
|
||||
this.autoReloader = autoReload ? new AutoReloader() : null;
|
||||
}
|
||||
|
||||
protected override bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect) {
|
||||
@ -23,9 +24,31 @@ protected override bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser br
|
||||
}
|
||||
|
||||
protected override void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status) {
|
||||
if (autoReload) {
|
||||
if (autoReloader?.RequestReload() == true) {
|
||||
browser.Reload();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class AutoReloader {
|
||||
private readonly Stopwatch lastReload = Stopwatch.StartNew();
|
||||
private int rapidReloadCount;
|
||||
|
||||
public bool RequestReload() {
|
||||
if (rapidReloadCount >= 2) {
|
||||
lastReload.Stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lastReload.ElapsedMilliseconds < 5000) {
|
||||
++rapidReloadCount;
|
||||
}
|
||||
else {
|
||||
rapidReloadCount = 0;
|
||||
}
|
||||
|
||||
lastReload.Restart();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user