Download plugin have progress status
This commit is contained in:
@@ -31,8 +31,8 @@ internal class SocketResponse
|
||||
return new SocketResponse(data, true, true, false);
|
||||
}
|
||||
|
||||
internal static SocketResponse Fail()
|
||||
internal static SocketResponse Fail(bool closeConnection)
|
||||
{
|
||||
return new SocketResponse(new byte[0], true, false, false);
|
||||
return new SocketResponse(new byte[0], true, false, closeConnection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,17 @@ namespace DiscordBotCore.API.Sockets.Sockets;
|
||||
|
||||
internal class PluginDownloadProgressSocket : ISocket
|
||||
{
|
||||
private float value = 0.0f;
|
||||
public string Path => "/plugin/download/progress";
|
||||
public Task<SocketResponse> HandleRequest(byte[] request, int count)
|
||||
{
|
||||
value += 0.1f;
|
||||
string pluginName = Encoding.UTF8.GetString(request, 0, count);
|
||||
Application.CurrentApplication.Logger.Log($"Received plugin download progress for {pluginName}.");
|
||||
if (!Application.CurrentApplication.PluginManager.InstallingPluginInformation.IsInstalling)
|
||||
{
|
||||
return Task.FromResult(SocketResponse.Fail(true));
|
||||
}
|
||||
|
||||
float value = Application.CurrentApplication.PluginManager.InstallingPluginInformation.InstallationProgress;
|
||||
SocketResponse response = SocketResponse.From(Encoding.UTF8.GetBytes(value.ToString()));
|
||||
response.CloseConnectionAfterResponse = value > 1.0f;
|
||||
response.CloseConnectionAfterResponse = false;
|
||||
return Task.FromResult(response);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user