基于WebView2实现的Win11桌面框架,利用插件自定义
Moli
2026-05-03 9806138b910904d2f982ebf9471b295fb6939715
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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 DisplayPriority DisplayPriority { get; init; } = DisplayPriority.IconLayer;
}
 
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
}