using System.Text.Json.Nodes;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace XFEWorkflow.Desktop.Sdk;
/// Created on the UI dispatcher. Navigation retains the page; disabling, uninstalling and application exit dispose it.
public interface IWorkflowPage : IAsyncDisposable
{
FrameworkElement View { get; }
ValueTask InitializeAsync(IPluginPageContext context, CancellationToken cancellationToken);
}
public interface IPluginPageContext
{
string PluginId { get; }
string PluginDirectory { get; }
string DataDirectory { get; }
JsonObject Settings { get; }
IReadOnlyList CredentialReferences { get; }
string GetCredential(string reference);
Task SetCredentialAsync(string reference, string value, CancellationToken cancellationToken = default);
Task SaveSettingsAsync(JsonObject settings, CancellationToken cancellationToken = default);
void InitializeWebView(WebView2 webView);
FrameworkElement CreateVerticalSplitter(string key, double fallback, double minimum, double maximum,
Func getSize, Action setSize, Func available);
void Log(string message, bool error = false);
string Redact(string text);
PluginPageUser User => new("", "未登录");
Task GetUserAsync(CancellationToken cancellationToken = default) => Task.FromResult(User);
event Action? UserChanged { add { } remove { } }
async Task SaveSettingsWithCredentialAsync(JsonObject settings, string reference, string secret, CancellationToken cancellationToken = default)
{
await SetCredentialAsync(reference, secret, cancellationToken);
await SaveSettingsAsync(settings, cancellationToken);
}
}
/// Display-only account information. No session or credential is exposed to a page.
public sealed record PluginPageUser(string Id, string DisplayName, string AvatarDataUri = "");