Formatted code and rebuilt PluginLoader

This commit is contained in:
2024-02-27 11:07:27 +02:00
parent 14f280baef
commit ef7a2c0896
40 changed files with 525 additions and 524 deletions

View File

@@ -13,17 +13,19 @@ public enum MessageBoxButtons
{
YesNo,
YesNoCancel,
ContinueCancel,
ContinueCancel
}
internal interface IOutputModel
{
internal Task ShowMessageBox(string title, string message, MessageBoxType type);
internal Task<string> ShowInputBox(string title, string message);
internal Task ShowMessageBox(string message);
internal Task<int> ShowMessageBox(string title, string message, MessageBoxButtons buttons, bool isWarning);
internal Task ShowNotification(string title, string message, int timeout_seconds = 5);
}

View File

@@ -3,7 +3,7 @@ using System.Threading.Tasks;
namespace PluginManager.UX.Linux;
internal class KDE : IOutputModel
internal class KDE: IOutputModel
{
internal string KdeDialogApplication { get; } = "kdialog";
@@ -11,15 +11,15 @@ internal class KDE : IOutputModel
{
var process = new Process();
process.StartInfo.FileName = KdeDialogApplication;
string typeStr = type switch
var typeStr = type switch
{
MessageBoxType.Info => "msgbox",
MessageBoxType.Info => "msgbox",
MessageBoxType.Warning => "sorry",
MessageBoxType.Error => "error",
_ => "info"
MessageBoxType.Error => "error",
_ => "info"
};
process.StartInfo.Arguments = $"--title \"{title}\" --{typeStr} \"{message}\"";
process.Start();
await process.WaitForExitAsync();
@@ -28,48 +28,48 @@ internal class KDE : IOutputModel
public async Task<string> ShowInputBox(string title, string message)
{
var process = new Process();
process.StartInfo.FileName = KdeDialogApplication;
process.StartInfo.Arguments = $"--title \"{title}\" --inputbox \"{message}\"";
process.StartInfo.FileName = KdeDialogApplication;
process.StartInfo.Arguments = $"--title \"{title}\" --inputbox \"{message}\"";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardInput = true;
process.Start();
await process.WaitForExitAsync();
return await process.StandardOutput.ReadToEndAsync();
}
public async Task ShowMessageBox(string message)
{
var process = new Process();
process.StartInfo.FileName = KdeDialogApplication;
process.StartInfo.FileName = KdeDialogApplication;
process.StartInfo.Arguments = $"--msgbox \"{message}\"";
process.Start();
await process.WaitForExitAsync();
}
public async Task<int> ShowMessageBox(string title, string message, MessageBoxButtons buttons, bool isWarning)
{
var process = new Process();
process.StartInfo.FileName = KdeDialogApplication;
string buttonsStr = buttons switch
var buttonsStr = buttons switch
{
MessageBoxButtons.YesNo => "yesno",
MessageBoxButtons.YesNoCancel => "yesnocancel",
MessageBoxButtons.YesNo => "yesno",
MessageBoxButtons.YesNoCancel => "yesnocancel",
MessageBoxButtons.ContinueCancel => "continuecancel",
_ => "yesno"
_ => "yesno"
};
string typeStr = isWarning ? "warning" : "";
var typeStr = isWarning ? "warning" : "";
process.StartInfo.Arguments = $"--title \"{title}\" --{typeStr}{buttonsStr} \"{message}\"";
process.Start();
await process.WaitForExitAsync();
return process.ExitCode;
}
public async Task ShowNotification(string title, string message, int timeout_seconds = 5)
{
var process = new Process();
process.StartInfo.FileName = KdeDialogApplication;
process.StartInfo.FileName = KdeDialogApplication;
process.StartInfo.Arguments = $"--title \"{title}\" --passivepopup \"{message}\" {timeout_seconds}";
process.Start();
await process.WaitForExitAsync();

View File

@@ -1,45 +1,43 @@
using System.Threading.Tasks;
using Spectre.Console;
namespace PluginManager.UX.Other;
internal class Console : IOutputModel
internal class Console: IOutputModel
{
public Task ShowMessageBox(string title, string message, MessageBoxType type)
{
AnsiConsole.Markup(title);
AnsiConsole.Markup(message);
return Task.CompletedTask;
}
public Task<string> ShowInputBox(string title, string message)
{
AnsiConsole.MarkupLine(title);
string input = AnsiConsole.Ask<string>(message);
var input = AnsiConsole.Ask<string>(message);
return Task.FromResult(input);
}
public Task ShowMessageBox(string message)
{
AnsiConsole.MarkupLine(message);
return Task.CompletedTask;
}
public Task<int> ShowMessageBox(string title, string message,MessageBoxButtons buttons, bool isWarning)
public Task<int> ShowMessageBox(string title, string message, MessageBoxButtons buttons, bool isWarning)
{
AnsiConsole.MarkupLine(title);
AnsiConsole.MarkupLine(message);
return Task.FromResult(0);
}
public Task ShowNotification(string title, string message, int timeout_seconds = 5)
{
return Task.CompletedTask;

View File

@@ -2,10 +2,10 @@ using System.Threading.Tasks;
namespace PluginManager.UX;
public static class UxHandler
public static class UxHandler
{
private static IOutputModel? _model;
public static void Init()
{
_model = Config.AppSettings["UI"] switch
@@ -14,32 +14,32 @@ public static class UxHandler
"CONSOLE" => new Other.Console(),
_ => null
};
}
public static async Task ShowMessageBox(string title, string message, MessageBoxType type = MessageBoxType.Info)
{
await _model.ShowMessageBox(title, message, type);
}
public static async Task<string> ShowInputBox(string title, string message)
{
return await _model.ShowInputBox(title, message);
}
public static async Task ShowMessageBox(string message)
{
await _model.ShowMessageBox(message);
}
public static async Task<int> ShowMessageBox(string title, string message, MessageBoxButtons buttons, bool isWarning)
{
return await _model.ShowMessageBox(title, message, buttons, isWarning);
}
public static async Task ShowNotification(string title, string message, int timeout_seconds = 5)
{
await _model.ShowNotification(title, message, timeout_seconds);
}
}