Add sudo password verification success message prompt

This commit is contained in:
2dust
2025-07-26 20:55:55 +08:00
parent 191a7a6574
commit e8cdc29bb5
9 changed files with 44 additions and 18 deletions
+14 -10
View File
@@ -9,6 +9,7 @@ public class CoreAdminHandler
private static readonly Lazy<CoreAdminHandler> _instance = new(() => new());
public static CoreAdminHandler Instance => _instance.Value;
private Config _config;
private readonly string _sudoAccessText = "SUDO_ACCESS_VERIFIED";
private Action<bool, string>? _updateFunc;
private int _linuxSudoPid = -1;
@@ -50,27 +51,30 @@ public class CoreAdminHandler
}
};
proc.OutputDataReceived += (sender, e) =>
{
if (e.Data.IsNotEmpty())
{
UpdateFunc(false, e.Data + Environment.NewLine);
}
};
proc.ErrorDataReceived += (sender, e) =>
var sudoVerified = false;
DataReceivedEventHandler dataHandler = (sender, e) =>
{
if (e.Data.IsNotEmpty())
{
if (!sudoVerified && e.Data.Contains(_sudoAccessText))
{
sudoVerified = true;
UpdateFunc(false, ResUI.SudoPwdVerfiedSuccessTip + Environment.NewLine);
return;
}
UpdateFunc(false, e.Data + Environment.NewLine);
}
};
proc.OutputDataReceived += dataHandler;
proc.ErrorDataReceived += dataHandler;
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
await Task.Delay(10);
await proc.StandardInput.WriteLineAsync();
await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd);
await Task.Delay(10);
await proc.StandardInput.WriteLineAsync(AppHandler.Instance.LinuxSudoPwd);
@@ -115,7 +119,7 @@ public class CoreAdminHandler
}
else
{
sb.AppendLine($"sudo -S {cmdLine}");
sb.AppendLine($"sudo -S echo \"{_sudoAccessText}\" && sudo -S {cmdLine}");
}
await File.WriteAllTextAsync(shFilePath, sb.ToString());