using System.Text.Json;
|
using Moli.Desktop.Layout;
|
|
namespace Moli.Desktop.Plugins;
|
|
public sealed record PluginDefaultLayout
|
{
|
public double X { get; init; } = 100;
|
public double Y { get; init; } = 100;
|
public double Width { get; init; } = 320;
|
public double Height { get; init; } = 160;
|
public bool Locked { get; init; }
|
public bool ClickThrough { get; init; }
|
public double Opacity { get; init; } = 1;
|
public double Scale { get; init; } = 1;
|
public DisplayLayer DisplayLayer { get; init; } = DisplayLayer.Desktop;
|
}
|
|
public sealed record PluginManifest
|
{
|
public required string Id { get; init; }
|
public required string Name { get; init; }
|
public required string Version { get; init; }
|
public required PluginType Type { get; init; }
|
public required string Entry { get; init; }
|
public string Description { get; init; } = "";
|
public string Author { get; init; } = "Unknown";
|
public List<string> Permissions { get; init; } = [];
|
public PluginDefaultLayout DefaultLayout { get; init; } = new();
|
public JsonElement Config { get; init; }
|
}
|
|
public sealed record PluginDescriptor
|
{
|
public required PluginId Id { get; init; }
|
public required PluginManifest Manifest { get; init; }
|
public required PluginType Type { get; init; }
|
public required PluginState State { get; init; }
|
public required string PluginDirectory { get; init; }
|
public required Uri EntryUri { get; init; }
|
public bool IsRemoteEntry { get; init; }
|
public string? ErrorCode { get; init; }
|
public string? ErrorMessage { get; init; }
|
}
|
|
public sealed record PluginManifestValidationResult
|
{
|
public bool Succeeded { get; init; }
|
public Uri? EntryUri { get; init; }
|
public bool IsRemoteEntry { get; init; }
|
public string? ErrorCode { get; init; }
|
public string? Message { get; init; }
|
|
public static PluginManifestValidationResult Success(Uri entryUri, bool isRemoteEntry) => new()
|
{
|
Succeeded = true,
|
EntryUri = entryUri,
|
IsRemoteEntry = isRemoteEntry
|
};
|
|
public static PluginManifestValidationResult Failure(string errorCode, string message) => new()
|
{
|
Succeeded = false,
|
ErrorCode = errorCode,
|
Message = message
|
};
|
}
|
|
public sealed record PluginOperationResult
|
{
|
public bool Succeeded { get; init; }
|
public PluginDescriptor? Plugin { get; init; }
|
public string? ErrorCode { get; init; }
|
public string? Message { get; init; }
|
|
public static PluginOperationResult Success(PluginDescriptor plugin, string? message = null) => new()
|
{
|
Succeeded = true,
|
Plugin = plugin,
|
Message = message
|
};
|
|
public static PluginOperationResult Failure(string errorCode, string message) => new()
|
{
|
Succeeded = false,
|
ErrorCode = errorCode,
|
Message = message
|
};
|
}
|
|
public enum PluginLifecycleEvent
|
{
|
Enable,
|
LoadSucceeded,
|
StartSucceeded,
|
Pause,
|
Resume,
|
Disable,
|
LoadFailed,
|
RuntimeFailed,
|
Remove
|
}
|