ChaoXingAutoClass
【WinUI】基于 XFEstudio 的 XFEWinUIApplication 模板重建的 WinUI 3 课程工作台。二维码和账号密码登录、课程 GridView、章节、播放进度、学习笔记及日志均使用原生 WinUI 控件。网页播放器运行在独立后台进程中,界面不显示课程网站。
关注
0
Fork
0
Star
0
using ChaoXingAutoClass.Browser;
using Microsoft.Playwright;
using System.Text.Json;
var profile = args.ElementAtOrDefault(0) ?? throw new ArgumentException("Pass the dedicated browser profile path.");
var endpointFile = args.ElementAtOrDefault(1) ?? throw new ArgumentException("Pass the endpoint file path.");
await using var host = await HiddenBrowserHost.StartAsync(profile, CancellationToken.None);
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(endpointFile))!);
await File.WriteAllTextAsync(endpointFile, host.Endpoint);
Console.WriteLine(host.Endpoint);
if (args.Contains("--standalone")) await Task.Delay(Timeout.InfiniteTimeSpan);
else
while (await Console.In.ReadLineAsync() is { } line && line != "stop")
{
string? requestId = null;
try
{
using var request = JsonDocument.Parse(line);
requestId = request.RootElement.GetProperty("requestId").GetString();
var command = request.RootElement.GetProperty("command").GetString();
if (command == "create")
{
var page = await host.CreateHiddenPageAsync(requestId!);
Console.WriteLine(JsonSerializer.Serialize(new { requestId, targetId = page.TargetId, url = page.Url }));
}
else if (command == "close")
{
await host.CloseHiddenPageAsync(request.RootElement.GetProperty("targetId").GetString()!);
Console.WriteLine(JsonSerializer.Serialize(new { requestId }));
}
}
catch (Exception error) { Console.WriteLine(JsonSerializer.Serialize(new { requestId, error = error.Message })); }
}
using ChaoXingAutoClass.Browser;
using Microsoft.Playwright;
using System.Text.Json;
var profile = args.ElementAtOrDefault(0) ?? throw new ArgumentException("Pass the dedicated browser profile path.");
var endpointFile = args.ElementAtOrDefault(1) ?? throw new ArgumentException("Pass the endpoint file path.");
await using var host = await HiddenBrowserHost.StartAsync(profile, CancellationToken.None);
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(endpointFile))!);
await File.WriteAllTextAsync(endpointFile, host.Endpoint);
Console.WriteLine(host.Endpoint);
if (args.Contains("--standalone")) await Task.Delay(Timeout.InfiniteTimeSpan);
else
while (await Console.In.ReadLineAsync() is { } line && line != "stop")
{
string? requestId = null;
try
{
using var request = JsonDocument.Parse(line);
requestId = request.RootElement.GetProperty("requestId").GetString();
var command = request.RootElement.GetProperty("command").GetString();
if (command == "create")
{
var page = await host.CreateHiddenPageAsync(requestId!);
Console.WriteLine(JsonSerializer.Serialize(new { requestId, targetId = page.TargetId, url = page.Url }));
}
else if (command == "close")
{
await host.CloseHiddenPageAsync(request.RootElement.GetProperty("targetId").GetString()!);
Console.WriteLine(JsonSerializer.Serialize(new { requestId }));
}
}
catch (Exception error) { Console.WriteLine(JsonSerializer.Serialize(new { requestId, error = error.Message })); }
}