mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-26 23:25:00 +03:00
Optimization and Improvement
Changed callback from synchronous Action<bool, string> to asynchronous Func<bool, string, Task>
This commit is contained in:
@@ -10,11 +10,11 @@ public class CoreAdminManager
|
||||
private static readonly Lazy<CoreAdminManager> _instance = new(() => new());
|
||||
public static CoreAdminManager Instance => _instance.Value;
|
||||
private Config _config;
|
||||
private Action<bool, string>? _updateFunc;
|
||||
private Func<bool, string, Task>? _updateFunc;
|
||||
private int _linuxSudoPid = -1;
|
||||
private const string _tag = "CoreAdminHandler";
|
||||
|
||||
public async Task Init(Config config, Action<bool, string> updateFunc)
|
||||
public async Task Init(Config config, Func<bool, string, Task> updateFunc)
|
||||
{
|
||||
if (_config != null)
|
||||
{
|
||||
@@ -26,9 +26,9 @@ public class CoreAdminManager
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void UpdateFunc(bool notify, string msg)
|
||||
private async Task UpdateFunc(bool notify, string msg)
|
||||
{
|
||||
_updateFunc?.Invoke(notify, msg);
|
||||
await _updateFunc?.Invoke(notify, msg);
|
||||
}
|
||||
|
||||
public async Task<Process?> RunProcessAsLinuxSudo(string fileName, CoreInfo coreInfo, string configPath)
|
||||
@@ -60,7 +60,7 @@ public class CoreAdminManager
|
||||
{
|
||||
if (e.Data.IsNotEmpty())
|
||||
{
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
_ = UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class CoreAdminManager
|
||||
.WithStandardInputPipe(PipeSource.FromString(AppManager.Instance.LinuxSudoPwd))
|
||||
.ExecuteBufferedAsync();
|
||||
|
||||
UpdateFunc(false, result.StandardOutput.ToString());
|
||||
await UpdateFunc(false, result.StandardOutput.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user