Fixed issue with http server and duplicate new download dialog
parent
2906470ea4
commit
219dee0c75
|
@ -7,6 +7,7 @@ using XDM.Core.Lib.Common;
|
|||
using XDM.Core.Lib.Util;
|
||||
using HttpServer;
|
||||
using System.Threading;
|
||||
using TraceLog;
|
||||
|
||||
namespace BrowserMonitoring
|
||||
{
|
||||
|
@ -52,7 +53,7 @@ namespace BrowserMonitoring
|
|||
switch (context.RequestPath)
|
||||
{
|
||||
case "/download":
|
||||
Console.WriteLine(Encoding.UTF8.GetString(context.RequestBody!));
|
||||
Log.Debug(Encoding.UTF8.GetString(context.RequestBody!));
|
||||
var message = Message.ParseMessage(Encoding.UTF8.GetString(context.RequestBody!));
|
||||
if (!(Helpers.IsBlockedHost(message.Url) || Helpers.IsCompressedJSorCSS(message.Url)))
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace HttpServer
|
|||
var arr = statusLine.Split(' ');
|
||||
if (arr.Length > 2)
|
||||
{
|
||||
return arr[0];
|
||||
return arr[1];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -42,7 +42,8 @@ namespace HttpServer
|
|||
|
||||
internal static long ParseContentLength(Dictionary<string, List<string>> headers)
|
||||
{
|
||||
return Int64.Parse(headers.GetValueOrDefault("Content-Length")?[0] ?? "-1");
|
||||
var value = headers.GetValueOrDefault("Content-Length")?[0];
|
||||
return Int64.Parse(value ?? "-1");
|
||||
}
|
||||
|
||||
private static bool ShouldKeepAlive(Dictionary<string, List<string>> headers)
|
||||
|
@ -73,7 +74,7 @@ namespace HttpServer
|
|||
}
|
||||
ParseHeader(line, out string headerName, out string headerValue);
|
||||
var values = headers.GetValueOrDefault(headerName, new List<string>());
|
||||
values.Add(headerName);
|
||||
values.Add(headerValue);
|
||||
headers[headerName] = values;
|
||||
}
|
||||
var contentLength = ParseContentLength(headers);
|
||||
|
@ -91,7 +92,7 @@ namespace HttpServer
|
|||
{
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
while ((read = stream.Read(buffer, 0, (int)Math.Min(buffer.Length, limit))) != 0)
|
||||
while (limit > 0 && (read = stream.Read(buffer, 0, (int)Math.Min(buffer.Length, limit))) != 0)
|
||||
{
|
||||
destination.Write(buffer, 0, read);
|
||||
limit -= read;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using XDM.Core.Lib.Common;
|
||||
using XDM.Core.Lib.Common;
|
||||
using XDM.Core.Lib.Common.Segmented;
|
||||
using XDM.Core.Lib.Util;
|
||||
|
||||
|
@ -10,8 +9,10 @@ namespace XDM.Common.UI
|
|||
public class NewDownloadDialogHelper
|
||||
{
|
||||
public static void CreateAndShowDialog(IApp app, IAppUI appUi,
|
||||
INewDownloadDialogSkeleton window, Message message = null)
|
||||
INewDownloadDialogSkeleton window, Message? message = null,
|
||||
Action? destroyCallback = null)
|
||||
{
|
||||
window.DestroyEvent += (_, _) => destroyCallback?.Invoke();
|
||||
window.SetFolderValues(CommonUtils.GetFolderValues());
|
||||
window.SeletedFolderIndex = Config.Instance.FolderSelectionMode == FolderSelectionMode.Auto ? 0 : 2;
|
||||
|
||||
|
|
|
@ -117,11 +117,16 @@ namespace XDM.WinForm.UI
|
|||
#if !NET35
|
||||
linkLabel1.Margin = new Padding(5);
|
||||
#endif
|
||||
|
||||
this.FormClosed += (a, b) =>
|
||||
{
|
||||
this.DestroyEvent?.Invoke(this, EventArgs.Empty);
|
||||
};
|
||||
}
|
||||
|
||||
public void DisposeWindow()
|
||||
{
|
||||
this.Dispose();
|
||||
this.Close();
|
||||
}
|
||||
|
||||
//private string? SelectFile()
|
||||
|
|
|
@ -221,9 +221,16 @@ namespace XDMApp
|
|||
|
||||
public void ShowNewDownloadDialog(Message message)
|
||||
{
|
||||
var url = message.Url;
|
||||
if (NewDownloadPromptTracker.IsPromptAlreadyOpen(url))
|
||||
{
|
||||
return;
|
||||
}
|
||||
RunOnUiThread(() =>
|
||||
{
|
||||
NewDownloadDialogHelper.CreateAndShowDialog(this.App, this, this.CreateNewDownloadDialog(false), message);
|
||||
NewDownloadPromptTracker.PromptOpen(url);
|
||||
NewDownloadDialogHelper.CreateAndShowDialog(this.App, this, this.CreateNewDownloadDialog(false), message,
|
||||
() => NewDownloadPromptTracker.PromptClosed(url));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace XDMApp
|
||||
{
|
||||
public static class NewDownloadPromptTracker
|
||||
{
|
||||
private static readonly HashSet<string> newDownloadPrompts = new();
|
||||
|
||||
public static bool IsPromptAlreadyOpen(string url)
|
||||
{
|
||||
lock (newDownloadPrompts)
|
||||
{
|
||||
return newDownloadPrompts.Contains(url);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PromptOpen(string url)
|
||||
{
|
||||
lock (newDownloadPrompts)
|
||||
{
|
||||
newDownloadPrompts.Add(url);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PromptClosed(string url)
|
||||
{
|
||||
lock (newDownloadPrompts)
|
||||
{
|
||||
newDownloadPrompts.Remove(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ namespace XDMApp
|
|||
private NativeMessagingHostHandler nativeMessaging;
|
||||
private bool isClipboardMonitorActive = false;
|
||||
private string lastClipboardText;
|
||||
private Timer AwakePingTimer;
|
||||
private Timer awakePingTimer;
|
||||
private System.Threading.Timer UpdateCheckTimer;
|
||||
|
||||
public IList<UpdateInfo>? Updates { get; private set; }
|
||||
|
@ -66,11 +66,11 @@ namespace XDMApp
|
|||
Config.DataDir = configPath;
|
||||
Config.LoadConfig();
|
||||
|
||||
AwakePingTimer = new Timer(60000)
|
||||
awakePingTimer = new Timer(60000)
|
||||
{
|
||||
AutoReset = true
|
||||
};
|
||||
AwakePingTimer.Elapsed += (a, b) => Helpers.SendKeepAlivePing();
|
||||
awakePingTimer.Elapsed += (a, b) => Helpers.SendKeepAlivePing();
|
||||
|
||||
//UpdateCheckTimer = new System.Threading.Timer(
|
||||
// callback: a => CheckForUpdate(),
|
||||
|
@ -207,10 +207,10 @@ namespace XDMApp
|
|||
ProxyInfo? proxyInfo,
|
||||
int maxSpeedLimit)
|
||||
{
|
||||
if (!AwakePingTimer.Enabled)
|
||||
if (!awakePingTimer.Enabled)
|
||||
{
|
||||
Log.Debug("Starting keep awaik timer");
|
||||
AwakePingTimer.Start();
|
||||
awakePingTimer.Start();
|
||||
}
|
||||
var id = download.Id;
|
||||
var startType = DownloadStartType.Waiting;
|
||||
|
@ -501,10 +501,10 @@ namespace XDMApp
|
|||
public void ResumeDownload(Dictionary<string, BaseDownloadEntry> list,
|
||||
bool nonInteractive = false)
|
||||
{
|
||||
if (!AwakePingTimer.Enabled)
|
||||
if (!awakePingTimer.Enabled)
|
||||
{
|
||||
Log.Debug("Starting keep awake timer");
|
||||
AwakePingTimer.Start();
|
||||
awakePingTimer.Start();
|
||||
}
|
||||
|
||||
AppUI.RunOnUiThread((Action)(() =>
|
||||
|
@ -906,10 +906,10 @@ namespace XDMApp
|
|||
{
|
||||
Helpers.ShutDownPC();
|
||||
}
|
||||
if (AwakePingTimer.Enabled)
|
||||
if (awakePingTimer.Enabled)
|
||||
{
|
||||
Log.Debug("Stopping keep awake timer");
|
||||
AwakePingTimer.Stop();
|
||||
awakePingTimer.Stop();
|
||||
}
|
||||
if (Config.Instance.RunCommandAfterCompletion)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue