mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-01 10:39:50 +08:00
重构了多个类中的方法为异步方法,并增加了消息注册逻辑: - `ScriptRepoUpdater.cs`:增加了检查并创建 `ReposPath` 目录的逻辑。 - `RepoWebBridge.cs`:引用新命名空间,重构 `GetRepoJson` 和 `ImportUri` 方法为异步方法,增加了检查和更新本地仓库的逻辑。 - `JsListViewModel.cs` 和 `MapPathingViewModel.cs`:引用新命名空间,增加消息注册逻辑,修正方法中的引用。 - `PathingTask.cs`:修正了日志记录中 `FileName` 的引用。 - `TaskSettingsPage.xaml`:更新了文本内容,增加了关于装备「王树瑞佑」的说明。 - 新增 `RefreshDataMessage.cs` 文件,定义了 `RefreshDataMessage` 类。
72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.Policy;
|
|
using System.Threading.Tasks;
|
|
using BetterGenshinImpact.ViewModel.Message;
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
namespace BetterGenshinImpact.Core.Script.WebView;
|
|
|
|
/// <summary>
|
|
/// 给 WebView 提供的桥接类
|
|
/// 用于调用 C# 方法
|
|
/// </summary>
|
|
[ClassInterface(ClassInterfaceType.AutoDual)]
|
|
[ComVisible(true)]
|
|
public class RepoWebBridge
|
|
{
|
|
public async Task<string> GetRepoJson()
|
|
{
|
|
try
|
|
{
|
|
var needUpdate = false;
|
|
string? localRepoJsonPath = null;
|
|
if (Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
|
|
{
|
|
localRepoJsonPath = Directory.GetFiles(ScriptRepoUpdater.CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault();
|
|
if (localRepoJsonPath is null)
|
|
{
|
|
needUpdate = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
needUpdate = true;
|
|
}
|
|
|
|
if (needUpdate)
|
|
{
|
|
await ScriptRepoUpdater.Instance.UpdateCenterRepo();
|
|
localRepoJsonPath = Directory.GetFiles(ScriptRepoUpdater.CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault();
|
|
if (localRepoJsonPath is null)
|
|
{
|
|
throw new Exception("本地仓库缺少 repo.json");
|
|
}
|
|
}
|
|
|
|
var json = await File.ReadAllTextAsync(localRepoJsonPath);
|
|
return json;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
await MessageBox.ShowAsync(e.Message, "获取仓库信息失败!");
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public async void ImportUri(string url)
|
|
{
|
|
try
|
|
{
|
|
await ScriptRepoUpdater.Instance.ImportScriptFromUri(url, false);
|
|
WeakReferenceMessenger.Default.Send(new RefreshDataMessage("Refresh"));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
await MessageBox.ShowAsync(e.Message, "订阅脚本链接失败!");
|
|
}
|
|
}
|
|
}
|