Added UI support for LINUX KDE Plasma

This commit is contained in:
2023-12-27 18:03:26 +02:00
parent c8480b3c83
commit af90ae5fba
11 changed files with 259 additions and 26 deletions

View File

@@ -0,0 +1,29 @@
using System.Threading.Tasks;
namespace PluginManager.UX;
public enum MessageBoxType
{
Info,
Warning,
Error
}
public enum MessageBoxButtons
{
YesNo,
YesNoCancel,
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

@@ -0,0 +1,75 @@
using System.Diagnostics;
using System.Threading.Tasks;
namespace PluginManager.UX.Linux;
internal class KDE : IOutputModel
{
public async Task ShowMessageBox(string title, string message, MessageBoxType type)
{
var process = new Process();
process.StartInfo.FileName = "kdialog";
string typeStr = type switch
{
MessageBoxType.Info => "msgbox",
MessageBoxType.Warning => "sorry",
MessageBoxType.Error => "error",
_ => "info"
};
process.StartInfo.Arguments = $"--title \"{title}\" --{typeStr} \"{message}\"";
process.Start();
await process.WaitForExitAsync();
}
public async Task<string> ShowInputBox(string title, string message)
{
var process = new Process();
process.StartInfo.FileName = "kdialog";
process.StartInfo.Arguments = $"--title \"{title}\" --inputbox \"{message}\"";
process.StartInfo.RedirectStandardOutput = true;
process.Start();
await process.WaitForExitAsync();
return await process.StandardOutput.ReadToEndAsync();
}
public async Task ShowMessageBox(string message)
{
var process = new Process();
process.StartInfo.FileName = "kdialog";
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 = "kdialog";
string buttonsStr = buttons switch
{
MessageBoxButtons.YesNo => "yesno",
MessageBoxButtons.YesNoCancel => "yesnocancel",
MessageBoxButtons.ContinueCancel => "continuecancel",
_ => "yesno"
};
string 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 = "kdialog";
process.StartInfo.Arguments = $"--title \"{title}\" --passivepopup \"{message}\" {timeout_seconds}";
process.Start();
await process.WaitForExitAsync();
}
}

View File

@@ -0,0 +1,51 @@
using System.Threading.Tasks;
using Spectre.Console;
namespace PluginManager.UX.Other;
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.Markup(title);
AnsiConsole.Markup(message);
string input = AnsiConsole.Ask<string>("Please enter the value:");
return Task.FromResult(input);
}
public Task ShowMessageBox(string message)
{
AnsiConsole.Markup(message);
return Task.CompletedTask;
}
public Task<int> ShowMessageBox(string title, string message,MessageBoxButtons buttons, bool isWarning)
{
AnsiConsole.Markup(title);
AnsiConsole.Markup(message);
return Task.FromResult(0);
}
public Task ShowNotification(string title, string message, int timeout_seconds = 5)
{
AnsiConsole.Markup(title);
AnsiConsole.Markup(message);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,42 @@
using System.Threading.Tasks;
namespace PluginManager.UX;
public static class UxHandler
{
private static IOutputModel _model;
public static void Init()
{
if (Config.AppSettings["UI"] == "KDE")
_model = new Linux.KDE();
else
_model = new Other.Console();
}
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);
}
}