Compare commits
20
Commits
feed-window
...
0.52.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53564c3951 | ||
|
|
06ac010962 | ||
|
|
b04a4f9427 | ||
|
|
192d4624d0 | ||
|
|
e90100e6f0 | ||
|
|
c038563c4d | ||
|
|
4d6d337631 | ||
|
|
6d05fd2270 | ||
|
|
34761ef23e | ||
|
|
22663c6383 | ||
|
|
81ab66acfa | ||
|
|
7ab80da472 | ||
|
|
91939cfbea | ||
|
|
910b005461 | ||
|
|
38a5ddc842 | ||
|
|
f5dc391d84 | ||
|
|
e6d1867b26 | ||
|
|
4cd5ab25c5 | ||
|
|
150328a8e6 | ||
|
|
4547c5cd74 |
No files matched your search
@@ -74,7 +74,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: huiyadanli/bettergi-scripts-web
|
||||
repository: zaodonganqi/bettergi-script-web
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<Version>0.51.1-alpha.2</Version>
|
||||
<Version>0.52.0</Version>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
@@ -42,9 +42,9 @@
|
||||
<PackageReference Include="BehaviourTree" Version="1.0.73" />
|
||||
|
||||
<PackageReference Include="BetterGI.VCRuntime" Version="14.44.35208" />
|
||||
<PackageReference Include="BetterGI.Assets.Map" Version="1.0.12" />
|
||||
<PackageReference Include="BetterGI.Assets.Map" Version="1.0.13" />
|
||||
<PackageReference Include="BetterGI.Assets.Model" Version="1.0.12" />
|
||||
<PackageReference Include="BetterGI.Assets.Other" Version="1.0.9" />
|
||||
<PackageReference Include="BetterGI.Assets.Other" Version="1.0.10" />
|
||||
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="DeviceId" Version="6.9.0" />
|
||||
@@ -52,6 +52,7 @@
|
||||
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.9.0" />
|
||||
<PackageReference Include="Emoji.Wpf" Version="0.3.4" />
|
||||
<PackageReference Include="LibGit2Sharp" Version="0.31.0" />
|
||||
<PackageReference Include="MailKit" Version="4.14.0" />
|
||||
<PackageReference Include="Meziantou.Framework.Win32.CredentialManager" Version="1.7.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4" />
|
||||
@@ -63,6 +64,7 @@
|
||||
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.21.0" />
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2592.51" />
|
||||
<PackageReference Include="MimeKit" Version="4.14.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
|
||||
<PackageReference Include="OpenCvSharp4.WpfExtensions" Version="4.11.0.20250507" />
|
||||
|
||||
@@ -73,4 +73,11 @@ public partial class CommonConfig : ObservableObject
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private List<string> _onceHadRunDeviceIdList = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前看过的兑换码推送版本
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _redeemCodeFeedsUpdateVersion = "20251013";
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using BetterGenshinImpact.Core.Script.Utils;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using OpenCvSharp;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Script.Dependence;
|
||||
|
||||
public class Http
|
||||
{
|
||||
private readonly ILogger<Http> _logger = App.GetLogger<Http>();
|
||||
|
||||
private void CheckHttpPermission(string url)
|
||||
{
|
||||
var currentProject = TaskContext.Instance().CurrentScriptProject;
|
||||
if (!currentProject?.AllowJsHTTP ?? false)
|
||||
{
|
||||
throw new UnauthorizedAccessException("当前JS脚本不允许使用HTTP请求,请在调度器通用设置中启用“JS HTTP权限”");
|
||||
}
|
||||
var allowedUrls = currentProject?.Project?.Manifest.HttpAllowedUrls ?? [];
|
||||
if (allowedUrls.Length == 0)
|
||||
{
|
||||
throw new UnauthorizedAccessException("当前JS脚本没有配置允许请求的URL,请在脚本的manifest.json中配置http_allowed_urls");
|
||||
}
|
||||
if (allowedUrls.Any(allowedUrl =>
|
||||
{
|
||||
// fuzzy match
|
||||
var pattern = "^" + System.Text.RegularExpressions.Regex.Escape(allowedUrl).Replace("\\*", ".*") + "$";
|
||||
_logger.LogDebug($"[HTTP] 检查URL {url} 是否符合: {pattern}");
|
||||
var regex = new System.Text.RegularExpressions.Regex(pattern);
|
||||
return regex.IsMatch(url);
|
||||
}))
|
||||
{
|
||||
return;
|
||||
}
|
||||
throw new UnauthorizedAccessException($"当前JS脚本不允许请求此URL: {url},请在脚本的manifest.json中配置http_allowed_urls,当前允许的URL列表: [{string.Join(", ", allowedUrls)}]");
|
||||
}
|
||||
|
||||
public class HttpReponse
|
||||
{
|
||||
public int status_code { get; set; }
|
||||
public Dictionary<string, string> headers { get; set; } = new();
|
||||
public string body { get; set; } = "";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 执行HTTP请求
|
||||
/// </summary>
|
||||
/// <param name="method">HTTP方法</param>
|
||||
/// <param name="url">请求URL</param>
|
||||
/// <param name="body">请求体</param>
|
||||
/// <param name="headersJson">请求头,JSON格式</param>
|
||||
/// <returns></returns>
|
||||
public async Task<HttpReponse> Request(string method, string url, string? body = null, string? headersJson = null)
|
||||
{
|
||||
_logger.LogDebug($"[HTTP] 发送HTTP请求: {method} {url} Body: {(body != null ? body : "null")} Headers: {(headersJson != null ? headersJson : "null")}");
|
||||
CheckHttpPermission(url);
|
||||
|
||||
var dictHeaders = new Dictionary<string, string>();
|
||||
if (!string.IsNullOrWhiteSpace(headersJson))
|
||||
{
|
||||
try
|
||||
{
|
||||
var headers = JsonSerializer.Deserialize<Dictionary<string, string>>(headersJson);
|
||||
if (headers != null)
|
||||
{
|
||||
dictHeaders = headers;
|
||||
}
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
throw new ArgumentException("Headers JSON格式错误");
|
||||
}
|
||||
}
|
||||
|
||||
// header全部小写
|
||||
dictHeaders = dictHeaders.ToDictionary(kvp => kvp.Key.ToLowerInvariant(), kvp => kvp.Value);
|
||||
|
||||
// 提前取出来Content-Type,防止被覆盖
|
||||
string contentType = "application/json";
|
||||
if (dictHeaders.TryGetValue("content-type", out var ct))
|
||||
{
|
||||
contentType = ct;
|
||||
dictHeaders.Remove("content-type");
|
||||
}
|
||||
|
||||
// 使用HttpClient发送请求
|
||||
using var httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Clear();
|
||||
foreach (var header in dictHeaders)
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
|
||||
}
|
||||
|
||||
var content = body == null ? null : new StringContent(body, Encoding.UTF8, contentType);
|
||||
var response = await httpClient.SendAsync(new HttpRequestMessage(new HttpMethod(method), url) { Content = content });
|
||||
|
||||
var responseCode = (int)response.StatusCode;
|
||||
var responseHeaders = response.Headers.ToDictionary(h => h.Key, h => h.Value.First()); // 只取第一个值
|
||||
var responseBody = await response.Content.ReadAsStringAsync();
|
||||
return new HttpReponse
|
||||
{
|
||||
status_code = responseCode,
|
||||
headers = responseHeaders,
|
||||
body = responseBody,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ public class EngineExtend
|
||||
engine.AddHostObject("genshin", new Dependence.Genshin());
|
||||
engine.AddHostObject("log", new Log());
|
||||
engine.AddHostObject("file", new LimitedFile(workDir)); // 限制文件访问
|
||||
engine.AddHostObject("http", new Http()); // 限制文件访问
|
||||
engine.AddHostObject("notification", new Notification());
|
||||
|
||||
// 任务调度器
|
||||
|
||||
@@ -106,6 +106,22 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
[ObservableProperty]
|
||||
private bool? _allowJsNotification = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _allowJsHTTPHash = "";
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许JS脚本发送HTTP请求,通过验证Hash来控制
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool AllowJsHTTP
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetHttpAllowedUrlsHash() == AllowJsHTTPHash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ScriptGroupProject()
|
||||
{
|
||||
}
|
||||
@@ -163,6 +179,19 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
Project = new ScriptProject(FolderName);
|
||||
}
|
||||
|
||||
public string GetHttpAllowedUrlsHash()
|
||||
{
|
||||
if (Project == null)
|
||||
{
|
||||
BuildScriptProjectRelation();
|
||||
}
|
||||
if (Project == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return string.Join("|", Project.Manifest.HttpAllowedUrls);
|
||||
}
|
||||
|
||||
public async Task Run()
|
||||
{
|
||||
//执行记录
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Manifest
|
||||
public string[] Scripts { get; set; } = [];
|
||||
public string[] Library { get; set; } = [];
|
||||
public string[] SavedFiles { get; set; } = [];
|
||||
public string[] HttpAllowedUrls { get; set; } = [];
|
||||
|
||||
public static Manifest FromJson(string json)
|
||||
{
|
||||
|
||||
@@ -176,7 +176,8 @@ public class AutoDomainTask : ISoloTask
|
||||
{
|
||||
combatScenes = new CombatScenes().InitializeTeam(CaptureToRectArea());
|
||||
}
|
||||
RetryTeamInit(combatScenes);// 队伍没初始化成功则重试
|
||||
|
||||
RetryTeamInit(combatScenes); // 队伍没初始化成功则重试
|
||||
|
||||
// 0. 切换到第一个角色
|
||||
var combatCommands = FindCombatScriptAndSwitchAvatar(combatScenes);
|
||||
@@ -274,12 +275,12 @@ public class AutoDomainTask : ISoloTask
|
||||
if ("芬德尼尔之顶".Equals(_taskParam.DomainName))
|
||||
{
|
||||
menuFound = await NewRetry.WaitForElementAppear(
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => Simulation.SendInput.SimulateAction(GIActions.MoveBackward, KeyType.KeyDown),
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
);
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => Simulation.SendInput.SimulateAction(GIActions.MoveBackward, KeyType.KeyDown),
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
);
|
||||
Simulation.SendInput.SimulateAction(GIActions.MoveBackward, KeyType.KeyUp);
|
||||
}
|
||||
else if ("无妄引咎密宫".Equals(_taskParam.DomainName))
|
||||
@@ -296,14 +297,13 @@ public class AutoDomainTask : ISoloTask
|
||||
500
|
||||
);
|
||||
Simulation.SendInput.SimulateAction(GIActions.MoveLeft, KeyType.KeyUp);
|
||||
|
||||
}
|
||||
else if ("太山府".Equals(_taskParam.DomainName))
|
||||
{
|
||||
menuFound = await NewRetry.WaitForElementAppear(
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => { },
|
||||
_ct,
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
);
|
||||
@@ -311,11 +311,11 @@ public class AutoDomainTask : ISoloTask
|
||||
else
|
||||
{
|
||||
menuFound = await NewRetry.WaitForElementAppear(
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyDown),
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
AutoPickAssets.Instance.PickRo,
|
||||
() => Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyDown),
|
||||
_ct,
|
||||
20,
|
||||
500
|
||||
);
|
||||
Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyUp);
|
||||
}
|
||||
@@ -336,7 +336,6 @@ public class AutoDomainTask : ISoloTask
|
||||
{
|
||||
throw new Exception("请检查是否已进入秘境页面");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -467,6 +466,7 @@ public class AutoDomainTask : ISoloTask
|
||||
ra2.Dispose();
|
||||
Logger.LogInformation("自动秘境:点击 {Text}", "单人挑战");
|
||||
}
|
||||
|
||||
using var confirmRectArea2 = ra.Find(RecognitionObject.Ocr(ra.Width * 0.263, ra.Height * 0.32,
|
||||
ra.Width - ra.Width * 0.263 * 2, ra.Height - ra.Height * 0.32 - ra.Height * 0.353));
|
||||
if (confirmRectArea2.IsExist() && confirmRectArea2.Text.Contains("是否仍要挑战该秘境"))
|
||||
@@ -483,10 +483,7 @@ public class AutoDomainTask : ISoloTask
|
||||
// 等待队伍选择界面出现
|
||||
var teamUiFound = await NewRetry.WaitForElementAppear(
|
||||
ElementAssets.Instance.PartyBtnChooseView,
|
||||
() =>
|
||||
{
|
||||
Logger.LogInformation("自动秘境:进入 {Text}", "队伍选择界面");
|
||||
},
|
||||
() => { Logger.LogInformation("自动秘境:进入 {Text}", "队伍选择界面"); },
|
||||
_ct,
|
||||
10,
|
||||
1000
|
||||
@@ -520,6 +517,7 @@ public class AutoDomainTask : ISoloTask
|
||||
{
|
||||
Logger.LogWarning("开始挑战按钮未出现或未能点击。");
|
||||
}
|
||||
|
||||
// 载入
|
||||
await Delay(1000, _ct);
|
||||
}
|
||||
@@ -556,6 +554,7 @@ public class AutoDomainTask : ISoloTask
|
||||
done.Dispose();
|
||||
Logger.LogInformation("自动秘境:点击 {Text}", done.Text);
|
||||
}
|
||||
|
||||
// 检查左下角区域是否还存在目标文字,消失则继续,存在则结束
|
||||
using var leftBottom = CaptureToRectArea();
|
||||
var leftBottomOcr = leftBottom.Find(AutoFightAssets.Instance.AbnormalIconRa);
|
||||
@@ -1120,13 +1119,13 @@ public class AutoDomainTask : ISoloTask
|
||||
bool resinUsed = false;
|
||||
if (resinStatus.CondensedResinCount > 0)
|
||||
{
|
||||
resinUsed = PressUseResin(ra3, "浓缩树脂");
|
||||
(resinUsed, _) = PressUseResin(ra3, "浓缩树脂");
|
||||
resinStatus.CondensedResinCount -= 1;
|
||||
}
|
||||
else if (resinStatus.OriginalResinCount >= 20)
|
||||
{
|
||||
resinUsed = PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= 20;
|
||||
(resinUsed, var num) = PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= num;
|
||||
}
|
||||
|
||||
if (!resinUsed)
|
||||
@@ -1150,11 +1149,15 @@ public class AutoDomainTask : ISoloTask
|
||||
var failCount = 0;
|
||||
foreach (var record in _resinPriorityListWhenSpecifyUse)
|
||||
{
|
||||
if (record.RemainCount > 0 && PressUseResin(textListInPrompt2, record.Name))
|
||||
if (record.RemainCount > 0)
|
||||
{
|
||||
record.RemainCount -= 1;
|
||||
Logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
var (success, _) = PressUseResin(textListInPrompt2, record.Name);
|
||||
if (success)
|
||||
{
|
||||
record.RemainCount -= 1;
|
||||
Logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1230,6 +1233,7 @@ public class AutoDomainTask : ISoloTask
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1249,13 +1253,13 @@ public class AutoDomainTask : ISoloTask
|
||||
Bv.ClickBlackConfirmButton(CaptureToRectArea());
|
||||
}
|
||||
|
||||
private bool PressUseResin(ImageRegion ra, string resinName)
|
||||
public static (bool, int) PressUseResin(ImageRegion ra, string resinName)
|
||||
{
|
||||
var regionList = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.25, ra.Height * 0.2, ra.Width * 0.5, ra.Height * 0.6));
|
||||
return PressUseResin(regionList, resinName);
|
||||
}
|
||||
|
||||
private bool PressUseResin(List<Region> regionList, string resinName)
|
||||
public static (bool, int) PressUseResin(List<Region> regionList, string resinName)
|
||||
{
|
||||
var resinKey = regionList.FirstOrDefault(t => t.Text.Contains(resinName));
|
||||
if (resinKey != null)
|
||||
@@ -1272,10 +1276,11 @@ public class AutoDomainTask : ISoloTask
|
||||
// 点击使用
|
||||
useKey.Click();
|
||||
// 解决水龙王按下左键后没松开,然后后续点击按下就没反应了。使用双击
|
||||
Sleep(60, _ct);
|
||||
Sleep(60);
|
||||
useKey.Click();
|
||||
Logger.LogInformation("自动秘境:使用 {ResinName}", resinName);
|
||||
return true;
|
||||
var num = GetResinNum(resinKey, resinName);
|
||||
Logger.LogInformation("自动秘境:使用 {ResinName}, 数量:{Num}", resinName, num);
|
||||
return (true, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1288,13 +1293,41 @@ public class AutoDomainTask : ISoloTask
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return (false, 0);
|
||||
}
|
||||
|
||||
private static int GetResinNum(Region region, string resinName)
|
||||
{
|
||||
if (resinName == "原粹树脂")
|
||||
{
|
||||
if (region.Text.Contains("20"))
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
else if (region.Text.Contains("40"))
|
||||
{
|
||||
return 40;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("自动秘境:未识别到原粹树脂消耗体力数量,默认按20计算");
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
else if (resinName == "浓缩树脂" || resinName == "脆弱树脂" || resinName == "须臾树脂")
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("未知的树脂名称");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个区域在垂直方向上是否有重叠
|
||||
/// </summary>
|
||||
private bool IsHeightOverlap(Region region1, Region region2)
|
||||
private static bool IsHeightOverlap(Region region1, Region region2)
|
||||
{
|
||||
int region1Top = region1.Y;
|
||||
int region1Bottom = region1.Y + region1.Height;
|
||||
@@ -1305,7 +1338,7 @@ public class AutoDomainTask : ISoloTask
|
||||
return (region1Top <= region2Bottom && region1Bottom >= region2Top);
|
||||
}
|
||||
|
||||
private async Task ArtifactSalvage()
|
||||
private async Task ArtifactSalvage()
|
||||
{
|
||||
if (!_taskParam.AutoArtifactSalvage)
|
||||
{
|
||||
@@ -1319,4 +1352,4 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
await new AutoArtifactSalvageTask(new AutoArtifactSalvageTaskParam(star, javaScript: null, artifactSetFilter: null, maxNumToCheck: null, recognitionFailurePolicy: null)).Start(_ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,7 +380,7 @@ public class CombatScenes : IDisposable
|
||||
/// 推荐使用
|
||||
/// 失败后自动刷新编号框位置
|
||||
/// </summary>
|
||||
/// <param name="imageRegion"></param>
|
||||
/// <param name="imageRegion"></param>l
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public int GetActiveAvatarIndex(ImageRegion imageRegion, AvatarActiveCheckContext context)
|
||||
@@ -391,6 +391,7 @@ public class CombatScenes : IDisposable
|
||||
if (index > 0)
|
||||
{
|
||||
LastActiveAvatarIndex = index;
|
||||
return index;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -412,7 +413,7 @@ public class CombatScenes : IDisposable
|
||||
}
|
||||
|
||||
|
||||
return LastActiveAvatarIndex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -637,9 +637,9 @@ public class PathExecutor
|
||||
{
|
||||
tpTask = new TpTask(ct);
|
||||
}
|
||||
|
||||
|
||||
// 最小5分钟间隔
|
||||
if ((DateTime.UtcNow - _lastGetExpeditionRewardsTime).TotalMinutes < 5)
|
||||
if ( _combatScenes?.CurrentMultiGameStatus?.IsInMultiGame == true && (DateTime.UtcNow - _lastGetExpeditionRewardsTime).TotalMinutes < 5)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -652,7 +652,6 @@ public class PathExecutor
|
||||
if (!RunnerContext.Instance.isAutoFetchDispatch && adventurersGuildCountry != "无")
|
||||
{
|
||||
var ra1 = CaptureToRectArea();
|
||||
|
||||
var textRect = new Rect(60, 20, 160, 260);
|
||||
var textMat = new Mat(ra1.SrcMat, textRect);
|
||||
string text = OcrFactory.Paddle.Ocr(textMat);
|
||||
|
||||
@@ -26,6 +26,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoDomain;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using static Vanara.PInvoke.User32;
|
||||
using BetterGenshinImpact.GameTask.AutoFight;
|
||||
@@ -426,13 +427,13 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
bool resinUsed = false;
|
||||
if (resinStatus.CondensedResinCount > 0)
|
||||
{
|
||||
resinUsed = PressUseResin(ra3, "浓缩树脂");
|
||||
(resinUsed, _) = AutoDomainTask.PressUseResin(ra3, "浓缩树脂");
|
||||
resinStatus.CondensedResinCount -= 1;
|
||||
}
|
||||
else if (resinStatus.OriginalResinCount >= 20)
|
||||
{
|
||||
resinUsed = PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= 20;
|
||||
(resinUsed, var num) = AutoDomainTask.PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= num;
|
||||
}
|
||||
|
||||
if (!resinUsed)
|
||||
@@ -456,11 +457,15 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
var failCount = 0;
|
||||
foreach (var record in _resinPriorityListWhenSpecifyUse)
|
||||
{
|
||||
if (record.RemainCount > 0 && PressUseResin(textListInPrompt2, record.Name))
|
||||
if (record.RemainCount > 0)
|
||||
{
|
||||
record.RemainCount -= 1;
|
||||
_logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
var (success, _) = AutoDomainTask.PressUseResin(textListInPrompt2, record.Name);
|
||||
if (success)
|
||||
{
|
||||
record.RemainCount -= 1;
|
||||
Logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -552,62 +557,6 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
await ExitDomain(new BvPage(_ct));
|
||||
}
|
||||
|
||||
private bool PressUseResin(ImageRegion ra, string resinName)
|
||||
{
|
||||
var regionList = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.25, ra.Height * 0.2, ra.Width * 0.5, ra.Height * 0.6));
|
||||
return PressUseResin(regionList, resinName);
|
||||
}
|
||||
|
||||
private bool PressUseResin(List<Region> regionList, string resinName)
|
||||
{
|
||||
var resinKey = regionList.FirstOrDefault(t => t.Text.Contains(resinName));
|
||||
if (resinKey != null)
|
||||
{
|
||||
// 找到树脂名称对应的按键,关键词为使用,是同一行的(高度相交)
|
||||
var useList = regionList.Where(t => t.Text.Contains("使用")).ToList();
|
||||
if (useList.Count != 0)
|
||||
{
|
||||
// 找到使用按键
|
||||
var useKey = useList.FirstOrDefault(t => t.X > TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect.Width / 2
|
||||
&& IsHeightOverlap(t, resinKey));
|
||||
if (useKey != null)
|
||||
{
|
||||
// 点击使用
|
||||
useKey.Click();
|
||||
// 解决水龙王按下左键后没松开,然后后续点击按下就没反应了。使用双击
|
||||
Sleep(60, _ct);
|
||||
useKey.Click();
|
||||
_logger.LogInformation("自动秘境:使用 {ResinName}", resinName);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("自动秘境:未找到 {ResinName} 的使用按键", resinName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("自动秘境:未找到 {ResinName} 的使用按键", resinName);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断两个区域在垂直方向上是否有重叠
|
||||
/// </summary>
|
||||
private bool IsHeightOverlap(Region region1, Region region2)
|
||||
{
|
||||
int region1Top = region1.Y;
|
||||
int region1Bottom = region1.Y + region1.Height;
|
||||
int region2Top = region2.Y;
|
||||
int region2Bottom = region2.Y + region2.Height;
|
||||
|
||||
// 检查区域是否在垂直方向上重叠
|
||||
return (region1Top <= region2Bottom && region1Bottom >= region2Top);
|
||||
}
|
||||
|
||||
private async Task ArtifactSalvage()
|
||||
{
|
||||
if (!_taskParam.AutoArtifactSalvage)
|
||||
|
||||
@@ -13202,6 +13202,25 @@
|
||||
"name": "传送锚点",
|
||||
"area": "银月之庭"
|
||||
},
|
||||
{
|
||||
"id": "1750",
|
||||
"gadgetId": "70600003",
|
||||
"gadgetType": "TransPointSecond",
|
||||
"type": "Teleport",
|
||||
"position": [
|
||||
3278.798828125,
|
||||
0,
|
||||
10179.552734375
|
||||
],
|
||||
"tranPosition": [
|
||||
3268.82958984375,
|
||||
0,
|
||||
10170.6865234375
|
||||
],
|
||||
"country": "挪德卡莱",
|
||||
"name": "传送锚点",
|
||||
"area": "月矩力试验设计局"
|
||||
},
|
||||
{
|
||||
"id": "1751",
|
||||
"gadgetId": "70600003",
|
||||
|
||||
@@ -25,6 +25,7 @@ public class MapLazyAssets : Singleton<MapLazyAssets>
|
||||
{ "须弥", [2877, -374] },
|
||||
{ "枫丹", [4515, 3631] },
|
||||
{ "纳塔", [8973.5, -1879.1] },
|
||||
{ "挪德卡莱", [9542.25, 1661.84] },
|
||||
};
|
||||
|
||||
public readonly Dictionary<string, GiTpPosition> DomainPositionMap = new();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.UseRedeemCode;
|
||||
|
||||
public class GamePreviewLiveDateCalculator
|
||||
{
|
||||
private static readonly DateTime StartDate = new DateTime(2025, 10, 10);
|
||||
private const int IntervalDays = 42;
|
||||
private const double ValidDays = 3.5;
|
||||
|
||||
/// <summary>
|
||||
/// 计算当前日期是否是前瞻日期
|
||||
/// </summary>
|
||||
/// <returns>如果是前瞻日期,返回 true;否则返回 false。</returns>
|
||||
public static bool IsPreviewDate(DateTime date)
|
||||
{
|
||||
TimeSpan difference = date - StartDate;
|
||||
return difference.Days >= 0 && difference.Days % IntervalDays == 0;
|
||||
}
|
||||
|
||||
public static void TestIsPreviewDate()
|
||||
{
|
||||
IsPreviewDate(new DateTime(2025, 11, 21));
|
||||
}
|
||||
|
||||
public bool TestTodayIsPreviewDate()
|
||||
{
|
||||
return IsPreviewDate(DateTime.Today);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算当前时间是否在从前瞻日期开始的2.5天范围内。
|
||||
/// </summary>
|
||||
/// <returns>如果在范围内,返回 true;否则返回 false。</returns>
|
||||
public static bool IsWithinPreviewRange(DateTime now)
|
||||
{
|
||||
TimeSpan difference = now.Date - StartDate;
|
||||
int daysSinceStart = difference.Days;
|
||||
|
||||
if (daysSinceStart < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int intervalCount = daysSinceStart / IntervalDays;
|
||||
DateTime lastPreviewDate = StartDate.AddDays(intervalCount * IntervalDays);
|
||||
TimeSpan timeSinceLastPreview = now - lastPreviewDate;
|
||||
|
||||
return timeSinceLastPreview.TotalDays >= 0 && timeSinceLastPreview.TotalDays <= ValidDays;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,12 @@ namespace BetterGenshinImpact.GameTask.UseRedeemCode;
|
||||
public class RedeemCodeManager
|
||||
{
|
||||
public static HashSet<string> CancelClipboardHash { get; } = [];
|
||||
|
||||
public static void AddNotDetectClipboardText(string clipboardText)
|
||||
{
|
||||
var md5Hash = MD5Helper.ComputeMD5(clipboardText);
|
||||
CancelClipboardHash.Add(md5Hash);
|
||||
}
|
||||
|
||||
public static async Task ImportFromClipboard(string clipboardText)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Service.Notification.Model;
|
||||
using BetterGenshinImpact.Service.Notifier.Exception;
|
||||
using BetterGenshinImpact.Service.Notifier.Interface;
|
||||
using MailKit.Security;
|
||||
using MimeKit;
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
namespace BetterGenshinImpact.Service.Notifier
|
||||
@@ -38,10 +38,6 @@ namespace BetterGenshinImpact.Service.Notifier
|
||||
_fromEmail = fromEmail;
|
||||
_fromName = fromName;
|
||||
ToEmail = toEmail;
|
||||
|
||||
// 忽略SSL证书验证错误
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
delegate { return true; };
|
||||
}
|
||||
|
||||
// 收件人邮箱
|
||||
@@ -55,81 +51,105 @@ namespace BetterGenshinImpact.Service.Notifier
|
||||
throw new NotifierException("收件人邮箱地址为空");
|
||||
}
|
||||
|
||||
// 创建一个新的SmtpClient实例(不复用)
|
||||
using (var smtpClient = new SmtpClient())
|
||||
// 创建邮件消息
|
||||
var message = new MimeMessage();
|
||||
message.From.Add(new MailboxAddress(_fromName, _fromEmail));
|
||||
message.To.Add(new MailboxAddress("", ToEmail));
|
||||
message.Subject = FormatEmailSubject(content);
|
||||
|
||||
var bodyBuilder = new BodyBuilder
|
||||
{
|
||||
try
|
||||
HtmlBody = FormatEmailBody(content)
|
||||
};
|
||||
|
||||
// 添加图片附件(如果存在)
|
||||
if (content.Screenshot != null)
|
||||
{
|
||||
using var memoryStream = new MemoryStream();
|
||||
// 将图片保存到内存流
|
||||
await content.Screenshot.SaveAsJpegAsync(memoryStream);
|
||||
memoryStream.Position = 0; // 重置流位置
|
||||
|
||||
// 添加附件
|
||||
var attachment = await bodyBuilder.Attachments.AddAsync("screenshot.jpg", memoryStream, ContentType.Parse("image/jpeg"));
|
||||
attachment.ContentId = "screenshot";
|
||||
}
|
||||
|
||||
message.Body = bodyBuilder.ToMessageBody();
|
||||
|
||||
// 使用 MailKit 发送邮件
|
||||
using var smtpClient = new MailKit.Net.Smtp.SmtpClient();
|
||||
try
|
||||
{
|
||||
// 根据服务器和端口选择合适的连接方式
|
||||
var secureSocketOptions = GetSecureSocketOptions();
|
||||
|
||||
await smtpClient.ConnectAsync(_smtpServer, _smtpPort, secureSocketOptions);
|
||||
|
||||
// 如果服务器需要认证,则进行登录
|
||||
if (!string.IsNullOrEmpty(_smtpUsername))
|
||||
{
|
||||
// 配置SMTP客户端
|
||||
smtpClient.Host = _smtpServer;
|
||||
smtpClient.Port = _smtpPort;
|
||||
smtpClient.EnableSsl = true;
|
||||
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
smtpClient.UseDefaultCredentials = false;
|
||||
smtpClient.Credentials = new NetworkCredential(_smtpUsername, _smtpPassword);
|
||||
smtpClient.Timeout = 30000; // 30秒超时
|
||||
|
||||
// 创建邮件
|
||||
using (var mailMessage = new MailMessage())
|
||||
{
|
||||
mailMessage.From = new MailAddress(_fromEmail, _fromName);
|
||||
mailMessage.To.Add(ToEmail);
|
||||
mailMessage.Subject = FormatEmailSubject(content);
|
||||
mailMessage.Body = FormatEmailBody(content);
|
||||
mailMessage.IsBodyHtml = true;
|
||||
mailMessage.BodyEncoding = Encoding.UTF8;
|
||||
mailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
|
||||
// 添加图片附件(如果存在)
|
||||
if (content.Screenshot != null)
|
||||
{
|
||||
var tempPath = Path.GetTempFileName() + ".jpg";
|
||||
try
|
||||
{
|
||||
// 保存图片到临时文件
|
||||
await content.Screenshot.SaveAsJpegAsync(tempPath);
|
||||
|
||||
// 从文件添加附件
|
||||
var attachment = new Attachment(tempPath);
|
||||
mailMessage.Attachments.Add(attachment);
|
||||
|
||||
// 发送邮件
|
||||
await smtpClient.SendMailAsync(mailMessage);
|
||||
|
||||
// 清理附件和临时文件
|
||||
attachment.Dispose();
|
||||
if (File.Exists(tempPath)) File.Delete(tempPath);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
// 尝试清理临时文件
|
||||
try
|
||||
{
|
||||
if (File.Exists(tempPath)) File.Delete(tempPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
/* 忽略清理错误 */
|
||||
}
|
||||
|
||||
throw new NotifierException($"发送邮件失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没有图片时直接发送
|
||||
await smtpClient.SendMailAsync(mailMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
var errorMessage = $"发送邮件失败: {ex.Message}";
|
||||
throw new NotifierException(errorMessage);
|
||||
await smtpClient.AuthenticateAsync(_smtpUsername, _smtpPassword);
|
||||
}
|
||||
|
||||
await smtpClient.SendAsync(message);
|
||||
await smtpClient.DisconnectAsync(true);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
var errorMessage = $"发送邮件失败: {ex.Message}";
|
||||
throw new NotifierException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据服务器地址和端口号选择合适的 SecureSocketOptions
|
||||
/// </summary>
|
||||
private SecureSocketOptions GetSecureSocketOptions()
|
||||
{
|
||||
// 对于已知的特殊服务器配置
|
||||
if (IsKnownServerWithSpecialRequirements(_smtpServer, _smtpPort, out var secureSocketOption))
|
||||
{
|
||||
return secureSocketOption;
|
||||
}
|
||||
|
||||
// 通用规则
|
||||
return _smtpPort switch
|
||||
{
|
||||
465 => SecureSocketOptions.SslOnConnect,
|
||||
587 => SecureSocketOptions.StartTls, // 大多数服务商使用 STARTTLS
|
||||
25 => SecureSocketOptions.None,
|
||||
_ => SecureSocketOptions.Auto // 其他端口让 MailKit 自动协商
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否是已知有特殊要求的服务器
|
||||
/// </summary>
|
||||
private bool IsKnownServerWithSpecialRequirements(string server, int port, out SecureSocketOptions option)
|
||||
{
|
||||
option = SecureSocketOptions.Auto;
|
||||
|
||||
// 网易邮箱系列 - 587 端口使用 SSL
|
||||
if ((server.Contains("163.com") ||
|
||||
server.Contains("126.com") ||
|
||||
server.Contains("yeah.net")) && port == 587)
|
||||
{
|
||||
option = SecureSocketOptions.SslOnConnect;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 可以继续添加其他已知的特殊配置
|
||||
// 例如:
|
||||
// if (server.Contains("some-special-server.com") && port == 587)
|
||||
// {
|
||||
// option = SecureSocketOptions.SslOnConnect;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string FormatEmailSubject(BaseNotificationData content)
|
||||
{
|
||||
// 可以根据实际需求自定义邮件主题格式
|
||||
@@ -159,9 +179,13 @@ namespace BetterGenshinImpact.Service.Notifier
|
||||
}
|
||||
|
||||
// 添加提示信息
|
||||
builder.AppendLine("<p><em>如有截图,请查看附件。</em></p>");
|
||||
if (content.Screenshot != null)
|
||||
{
|
||||
builder.AppendLine("<p><em>截图已作为附件添加到邮件中。</em></p>");
|
||||
}
|
||||
|
||||
builder.AppendLine("</body></html>");
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -486,6 +486,7 @@ public partial class ScriptService : IScriptService
|
||||
target.JsScriptSettingsObject = source.JsScriptSettingsObject;
|
||||
target.GroupInfo = source.GroupInfo;
|
||||
target.AllowJsNotification = source.AllowJsNotification;
|
||||
target.AllowJsHTTPHash = source.AllowJsHTTPHash;
|
||||
target.SkipFlag = source.SkipFlag;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,15 @@ public sealed class BooleanToVisibilityRevertConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return (value is bool v && v) ? Visibility.Collapsed : Visibility.Visible;
|
||||
if (value is string str)
|
||||
{
|
||||
return string.IsNullOrEmpty(str) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
else if (value is bool b)
|
||||
{
|
||||
return b ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
|
||||
@@ -8,6 +8,11 @@ namespace BetterGenshinImpact.View.Converters
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
|
||||
return value != null;
|
||||
}
|
||||
|
||||
|
||||
@@ -178,13 +178,22 @@
|
||||
</ui:NavigationView.ContentOverlay>
|
||||
</ui:NavigationView>
|
||||
|
||||
<ui:TitleBar Title="{Binding Title, Mode=OneWay}" Grid.Row="0">
|
||||
<ui:TitleBar Title="{Binding Title, Mode=OneWay}" Grid.Row="0" Grid.Column="0">
|
||||
<ui:TitleBar.Icon>
|
||||
<ui:ImageIcon Source="pack://application:,,,/Resources/Images/logo.png" />
|
||||
</ui:TitleBar.Icon>
|
||||
<ui:TitleBar.TrailingContent>
|
||||
<StackPanel VerticalAlignment="Top" Orientation="Horizontal">
|
||||
<ui:Button Width="46"
|
||||
<ui:Button Width="40"
|
||||
Height="32"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
Command="{Binding OpenFeedCommand}"
|
||||
CornerRadius="0"
|
||||
Icon="{ui:SymbolIcon Gift16}"
|
||||
Foreground="{Binding RedeemCodeButtonForeground}"
|
||||
ToolTip="获取兑换码信息" />
|
||||
<ui:Button Width="40"
|
||||
Height="32"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
@@ -192,7 +201,7 @@
|
||||
CornerRadius="0"
|
||||
Icon="{ui:SymbolIcon Blur24}"
|
||||
ToolTip="切换深浅主题或背景样式" />
|
||||
<ui:Button Width="46"
|
||||
<ui:Button Width="32"
|
||||
Height="32"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
@@ -204,7 +213,7 @@
|
||||
</ui:TitleBar.TrailingContent>
|
||||
</ui:TitleBar>
|
||||
|
||||
<tray:NotifyIcon Grid.Row="0"
|
||||
<tray:NotifyIcon Grid.Row="0" Grid.Column="0"
|
||||
FocusOnLeftClick="False"
|
||||
Icon="pack://application:,,,/Resources/Images/logo.ico"
|
||||
LeftDoubleClick="OnNotifyIconLeftDoubleClick"
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:editable="clr-namespace:BetterGenshinImpact.ViewModel.Windows.Editable"
|
||||
xmlns:sys="clr-namespace:System;assembly=System.Runtime"
|
||||
Width="200"
|
||||
Height="300"
|
||||
MinWidth="350"
|
||||
MinHeight="300"
|
||||
d:DesignHeight="200"
|
||||
d:DesignWidth="300"
|
||||
d:DesignWidth="350"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<ObjectDataProvider x:Key="StatusDescriptionsProvider"
|
||||
@@ -50,6 +50,47 @@
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}">
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Margin="0,10,0,5" Text="JS HTTP权限"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}"/>
|
||||
<TextBlock Margin="0,0,0,5"
|
||||
Text="允许脚本发送HTTP请求,可能会带来安全风险,请谨慎开启。"
|
||||
Foreground="Orange"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}"/>
|
||||
<TextBlock Margin="0,0,0,5"
|
||||
Text="注意:脚本更新http_allowed_urls后,需手动重新启用权限。"
|
||||
Foreground="Orange"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}"/>
|
||||
<ItemsControl Margin="0,0,0,0" ItemsSource="{Binding JsHTTPInfoText}"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}"
|
||||
Foreground="{Binding Color}"
|
||||
FontSize="11"
|
||||
TextWrapping="NoWrap"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ItemsControl Margin="0,0,0,10" ItemsSource="{Binding JsHTTPInfo}"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBox Text="{Binding Text}"
|
||||
IsReadOnly="True"
|
||||
Foreground="{Binding Color}"
|
||||
FontSize="11"
|
||||
FontFamily="Consolas"
|
||||
TextWrapping="NoWrap"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ComboBox DisplayMemberPath="Value"
|
||||
ItemsSource="{Binding JsNotificationOptions}"
|
||||
SelectedValue="{Binding AllowJsHTTP, Mode=TwoWay}"
|
||||
SelectedValuePath="Key"
|
||||
Visibility="{Binding IsJsScript, Converter={StaticResource BoolToVisConverter}}">
|
||||
</ComboBox>
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,266 @@
|
||||
<ui:FluentWindow x:Class="BetterGenshinImpact.View.Windows.FeedWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Width="400"
|
||||
Height="700"
|
||||
MinWidth="400"
|
||||
MinHeight="250"
|
||||
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
|
||||
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ExtendsContentIntoTitleBar="True"
|
||||
FontFamily="{DynamicResource TextThemeFontFamily}"
|
||||
WindowBackdropType="Mica"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
WindowStyle="SingleBorderWindow"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<ui:TitleBar Name="MyTitleBar" Grid.Row="0" Title="兑换码">
|
||||
<ui:TitleBar.Icon>
|
||||
<ui:ImageIcon Source="pack://application:,,,/Resources/Images/logo.png" />
|
||||
</ui:TitleBar.Icon>
|
||||
</ui:TitleBar>
|
||||
|
||||
<!-- 主要内容区域 -->
|
||||
<Grid Grid.Row="1" Margin="20,10,20,10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题和描述 -->
|
||||
<StackPanel Grid.Row="0" Margin="0,0,0,15">
|
||||
<ui:TextBlock FontSize="24"
|
||||
FontWeight="SemiBold"
|
||||
Text="最新兑换码动态"
|
||||
Margin="0,0,0,5" />
|
||||
<ui:TextBlock FontSize="14"
|
||||
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
|
||||
Text="查看最新的国服原神的兑换码,一键自动兑换"
|
||||
TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- 加载状态 -->
|
||||
<StackPanel Grid.Row="1"
|
||||
VerticalAlignment="Top"
|
||||
Height="16"
|
||||
Orientation="Horizontal"
|
||||
Margin="0,0,0,10"
|
||||
Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<ui:ProgressRing Width="16" Height="16" IsIndeterminate="True" Margin="0,0,8,0" />
|
||||
<ui:TextBlock Text="正在加载兑换码..." Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Feed 列表 -->
|
||||
<ScrollViewer Grid.Row="2"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Disabled">
|
||||
<ItemsControl ItemsSource="{Binding FeedItems}" Padding="0,0,16,0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ui:Card Margin="0,0,0,12"
|
||||
Padding="16">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题 -->
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
FontSize="16"
|
||||
FontWeight="SemiBold"
|
||||
Text="{Binding Title}"
|
||||
TextWrapping="Wrap"
|
||||
Margin="0,0,0,8" />
|
||||
|
||||
<!-- 时间与有效期:同一行更紧凑(Valid 为空或 null 时隐藏) -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,0,0,6">
|
||||
<ui:TextBlock FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="{Binding Time}" />
|
||||
<ui:TextBlock FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text=" | "
|
||||
Margin="8,0,8,0">
|
||||
<ui:TextBlock.Style>
|
||||
<Style TargetType="{x:Type ui:TextBlock}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ui:TextBlock.Style>
|
||||
</ui:TextBlock>
|
||||
<ui:TextBlock FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="有效期至">
|
||||
<ui:TextBlock.Style>
|
||||
<Style TargetType="{x:Type ui:TextBlock}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ui:TextBlock.Style>
|
||||
</ui:TextBlock>
|
||||
<ui:TextBlock FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="{Binding Valid}"
|
||||
Margin="4,0,0,0">
|
||||
<ui:TextBlock.Style>
|
||||
<Style TargetType="{x:Type ui:TextBlock}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ui:TextBlock.Style>
|
||||
</ui:TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 内容:卡片式展示,增强层次与可读性 -->
|
||||
<StackPanel Grid.Row="2"
|
||||
Visibility="{Binding Content, Converter={StaticResource BooleanToVisibilityRevertConverter}}"
|
||||
Margin="0,0,0,12">
|
||||
<!--<ui:TextBlock Text="内容"
|
||||
FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Margin="0,0,0,6"/>-->
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
|
||||
CornerRadius="{DynamicResource ControlCornerRadius}"
|
||||
BorderThickness="1"
|
||||
Padding="12">
|
||||
<ui:TextBlock FontSize="14"
|
||||
Text="{Binding Content}"
|
||||
TextWrapping="Wrap"
|
||||
LineHeight="20" />
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 兑换码列表:胶囊标签,WrapPanel自动换行 -->
|
||||
<StackPanel Grid.Row="3" Margin="0,0,0,8">
|
||||
<!--<ui:TextBlock Text="兑换码"
|
||||
FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Margin="0,0,0,6"/>-->
|
||||
<ItemsControl ItemsSource="{Binding Codes}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
BorderBrush="{DynamicResource ControlElevationBorderBrush}"
|
||||
CornerRadius="4"
|
||||
BorderThickness="1"
|
||||
Padding="8,4"
|
||||
Margin="0,0,8,8">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<ui:SymbolIcon Symbol="TicketDiagonal24" Margin="0,0,6,0" />
|
||||
<ui:TextBlock FontSize="14"
|
||||
LineHeight="16"
|
||||
FontFamily="Consolas"
|
||||
Text="{Binding}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 标签 -->
|
||||
<StackPanel Grid.Row="4"
|
||||
Orientation="Horizontal"
|
||||
Visibility="{Binding HasTag, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Border CornerRadius="10"
|
||||
Background="{DynamicResource CardBackground}"
|
||||
BorderBrush="{DynamicResource CardBorderBrush}">
|
||||
<ui:TextBlock FontSize="11"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="White"
|
||||
Text="{Binding Tag}" />
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 按钮组 -->
|
||||
<StackPanel Grid.Row="5"
|
||||
Orientation="Horizontal"
|
||||
Margin="0,0,0,8">
|
||||
<ui:Button Content="复制"
|
||||
Appearance="Secondary"
|
||||
FontSize="12"
|
||||
Padding="12,6"
|
||||
Margin="0,0,8,0"
|
||||
Command="{Binding DataContext.CopyItemCodesCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding}" />
|
||||
<ui:Button Content="一键兑换"
|
||||
Appearance="Primary"
|
||||
FontSize="12"
|
||||
Padding="12,6"
|
||||
Command="{Binding DataContext.AutoRedeemItemCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding}" />
|
||||
</StackPanel>
|
||||
|
||||
|
||||
</Grid>
|
||||
</ui:Card>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<Grid Grid.Row="2" Margin="40,10,20,20">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Right">
|
||||
<ui:Button Name="BtnGetLiveCodes"
|
||||
Margin="0,0,10,0"
|
||||
Appearance="Secondary"
|
||||
Content="实时获取前瞻兑换码"
|
||||
Command="{Binding GetLiveRedeemCodesCommand}"
|
||||
Visibility="{Binding IsDisplayBtnGetLiveCodes, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
/>
|
||||
<ui:Button Name="BtnClose"
|
||||
Content="关闭"
|
||||
Click="BtnCloseClick" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Window.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
</Window.Resources>
|
||||
</ui:FluentWindow>
|
||||
@@ -0,0 +1,41 @@
|
||||
using BetterGenshinImpact.Helpers.Ui;
|
||||
using BetterGenshinImpact.ViewModel.Windows;
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace BetterGenshinImpact.View.Windows;
|
||||
|
||||
public partial class FeedWindow
|
||||
{
|
||||
public FeedWindowViewModel ViewModel { get; }
|
||||
|
||||
public FeedWindow(FeedWindowViewModel viewModel)
|
||||
{
|
||||
DataContext = ViewModel = viewModel;
|
||||
InitializeComponent();
|
||||
|
||||
this.Loaded += FeedWindow_Loaded;
|
||||
this.SourceInitialized += FeedWindow_SourceInitialized;
|
||||
}
|
||||
|
||||
public FeedWindow() : this(new FeedWindowViewModel())
|
||||
{
|
||||
}
|
||||
|
||||
private void FeedWindow_SourceInitialized(object? sender, EventArgs e)
|
||||
{
|
||||
// 应用与主窗口相同的背景主题
|
||||
WindowHelper.TryApplySystemBackdrop(this);
|
||||
}
|
||||
|
||||
private void FeedWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 窗口加载完成后拉取远程兑换码数据
|
||||
_ = ViewModel.LoadRemoteDataAsync();
|
||||
}
|
||||
|
||||
private void BtnCloseClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Globalization;
|
||||
using System.Windows.Navigation;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
@@ -24,6 +26,20 @@ namespace BetterGenshinImpact.View.Windows;
|
||||
[ObservableObject]
|
||||
public partial class ScriptRepoWindow
|
||||
{
|
||||
// 转换器类
|
||||
public class InverseBooleanConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is bool b ? !b : value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is bool b ? !b : value;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新渠道类
|
||||
public class RepoChannel
|
||||
{
|
||||
@@ -114,8 +130,6 @@ public partial class ScriptRepoWindow
|
||||
{
|
||||
new("CNB", "https://cnb.cool/bettergi/bettergi-scripts-list"),
|
||||
new("GitCode", "https://gitcode.com/huiyadanli/bettergi-scripts-list"),
|
||||
// 暂时无法使用
|
||||
// new("Gitee", "https://gitee.com/babalae/bettergi-scripts-list"),
|
||||
new("GitHub", "https://github.com/babalae/bettergi-scripts-list"),
|
||||
new("自定义", "https://example.com/custom-repo")
|
||||
};
|
||||
@@ -137,10 +151,33 @@ public partial class ScriptRepoWindow
|
||||
private void OnConfigSelectedRepoUrlChanged()
|
||||
{
|
||||
// 如果配置中的URL与当前选中渠道不一致,更新选中渠道
|
||||
if (string.IsNullOrEmpty(SelectedRepoChannel?.Url) || SelectedRepoChannel.Url != Config.SelectedRepoUrl)
|
||||
if (string.IsNullOrEmpty(Config.SelectedRepoUrl))
|
||||
{
|
||||
SelectedRepoChannel = _repoChannels.FirstOrDefault(c => c.Url == Config.SelectedRepoUrl) ??
|
||||
_repoChannels.FirstOrDefault(c => c.Name == "自定义") ?? _repoChannels[0];
|
||||
SelectedRepoChannel = _repoChannels[0];
|
||||
Config.SelectedRepoUrl = SelectedRepoChannel.Url;
|
||||
return;
|
||||
}
|
||||
|
||||
// 尝试找到匹配的预定义渠道
|
||||
var matchedChannel = _repoChannels.FirstOrDefault(c =>
|
||||
c.Name != "自定义" && c.Url == Config.SelectedRepoUrl);
|
||||
|
||||
if (matchedChannel != null)
|
||||
{
|
||||
SelectedRepoChannel = matchedChannel;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没有匹配的预定义渠道,选择自定义渠道
|
||||
var customChannel = _repoChannels.FirstOrDefault(c => c.Name == "自定义");
|
||||
if (customChannel != null)
|
||||
{
|
||||
SelectedRepoChannel = customChannel;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedRepoChannel = _repoChannels[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +194,7 @@ public partial class ScriptRepoWindow
|
||||
// 更新配置中的选中仓库URL
|
||||
if (SelectedRepoChannel.Name != "自定义")
|
||||
{
|
||||
// 如果不是自定义渠道,直接使用选中渠道的URL
|
||||
// 如果不是自定义渠道,使用选中渠道的URL
|
||||
Config.SelectedRepoUrl = SelectedRepoChannel.Url;
|
||||
}
|
||||
}
|
||||
@@ -170,11 +207,41 @@ public partial class ScriptRepoWindow
|
||||
Toast.Warning("请选择一个脚本仓库更新渠道。");
|
||||
return;
|
||||
}
|
||||
|
||||
// 确定要使用的URL
|
||||
string repoUrl;
|
||||
if (SelectedRepoChannel.Name == "自定义")
|
||||
{
|
||||
// 使用配置中的自定义URL
|
||||
repoUrl = Config.SelectedRepoUrl;
|
||||
|
||||
// 验证自定义URL
|
||||
if (string.IsNullOrWhiteSpace(repoUrl))
|
||||
{
|
||||
Toast.Warning("请输入自定义仓库URL。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (repoUrl == "https://example.com/custom-repo")
|
||||
{
|
||||
Toast.Warning("请修改默认的自定义URL为有效的仓库地址。");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用预定义渠道的URL
|
||||
repoUrl = SelectedRepoChannel.Url;
|
||||
}
|
||||
|
||||
if (!Uri.TryCreate(repoUrl, UriKind.Absolute, out _))
|
||||
{
|
||||
Toast.Warning("请输入有效的URL地址。");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 使用选定渠道的URL进行更新
|
||||
string repoUrl = SelectedRepoChannel.Url;
|
||||
|
||||
// 显示更新中提示
|
||||
Toast.Information("正在更新脚本仓库,请耐心等待...");
|
||||
|
||||
@@ -182,7 +249,8 @@ public partial class ScriptRepoWindow
|
||||
IsUpdating = true;
|
||||
UpdateProgressValue = 0;
|
||||
UpdateProgressText = "准备更新,请耐心等待...";
|
||||
// 执行更新 (repoPath, updated)
|
||||
|
||||
// 执行更新
|
||||
var (_, updated) = await ScriptRepoUpdater.Instance.UpdateCenterRepoByGit(repoUrl,
|
||||
(path, steps, totalSteps) =>
|
||||
{
|
||||
@@ -192,7 +260,6 @@ public partial class ScriptRepoWindow
|
||||
UpdateProgressText = $"{path}";
|
||||
});
|
||||
|
||||
|
||||
// 更新结果提示
|
||||
if (updated)
|
||||
{
|
||||
@@ -205,7 +272,7 @@ public partial class ScriptRepoWindow
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await MessageBox.ErrorAsync($"更新失败,可尝试重置仓库后重新更新。失败原因:: {ex.Message}");
|
||||
await MessageBox.ErrorAsync($"更新失败,可尝试重置仓库后重新更新。失败原因:{ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.Core.Script;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
@@ -8,6 +8,7 @@ using BetterGenshinImpact.Helpers.Ui;
|
||||
using BetterGenshinImpact.Model;
|
||||
using BetterGenshinImpact.Service.Interface;
|
||||
using BetterGenshinImpact.View;
|
||||
using BetterGenshinImpact.View.Pages;
|
||||
using BetterGenshinImpact.View.Windows;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -28,6 +29,8 @@ using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using BetterGenshinImpact.Helpers.Http;
|
||||
using BetterGenshinImpact.ViewModel.Windows;
|
||||
using Wpf.Ui;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
@@ -37,6 +40,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
private readonly ILogger<MainWindowViewModel> _logger;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly INavigationService _navigationService;
|
||||
public string Title => $"BetterGI · 更好的原神 · {Global.Version}{(RuntimeHelper.IsDebug ? " · Dev" : string.Empty)}";
|
||||
|
||||
[ObservableProperty] private bool _isVisible = true;
|
||||
@@ -46,6 +50,10 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
[ObservableProperty] private WindowBackdropType _currentBackdropType = WindowBackdropType.Auto;
|
||||
|
||||
[ObservableProperty] private bool _isWin11Later = OsVersionHelper.IsWindows11_OrGreater;
|
||||
|
||||
[ObservableProperty] private Brush _redeemCodeButtonForeground = Brushes.White;
|
||||
|
||||
private string? _redeemCodeUpdateNewVersion;
|
||||
|
||||
private bool _firstActivated = true;
|
||||
|
||||
@@ -53,6 +61,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
|
||||
public MainWindowViewModel(INavigationService navigationService, IConfigService configService)
|
||||
{
|
||||
_navigationService = navigationService;
|
||||
_configService = configService;
|
||||
Config = _configService.Get();
|
||||
_logger = App.GetLogger<MainWindowViewModel>();
|
||||
@@ -188,6 +197,12 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
WindowHelper.ApplyThemeToWindow(Application.Current.MainWindow, themeType);
|
||||
}
|
||||
|
||||
// 根据当前主题更新兑换码按钮的默认前景色(若无更新高亮)
|
||||
if (_redeemCodeUpdateNewVersion == null)
|
||||
{
|
||||
UpdateRedeemCodeButtonDefaultForeground();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -200,6 +215,21 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnOpenFeed()
|
||||
{
|
||||
if (_redeemCodeUpdateNewVersion != null)
|
||||
{
|
||||
Config.CommonConfig.RedeemCodeFeedsUpdateVersion = _redeemCodeUpdateNewVersion;
|
||||
// 重置为主题默认前景色,避免浅色主题下显示为白色
|
||||
UpdateRedeemCodeButtonDefaultForeground();
|
||||
_redeemCodeUpdateNewVersion = null;
|
||||
}
|
||||
|
||||
var feedWindow = new FeedWindow(new FeedWindowViewModel());
|
||||
feedWindow.Show();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task OnLoaded()
|
||||
{
|
||||
@@ -242,6 +272,9 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
|
||||
// 检查更新
|
||||
await App.GetService<IUpdateService>()!.CheckUpdateAsync(new UpdateOption());
|
||||
|
||||
// 检查兑换码更新
|
||||
await CheckRedeemCodeFeedsUpdateAsync();
|
||||
|
||||
// Win11下 BitBlt截图方式不可用,需要关闭窗口优化功能
|
||||
if (OsVersionHelper.IsWindows11_OrGreater && TaskContext.Instance().Config.AutoFixWin11BitBlt)
|
||||
@@ -410,4 +443,58 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
_configService.Save();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CheckRedeemCodeFeedsUpdateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, "https://cnb.cool/bettergi/genshin-redeem-code/-/git/raw/main/update_time.txt");
|
||||
var response = await HttpClientFactory.GetCommonSendClient().SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var txt = await response.Content.ReadAsStringAsync();
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(txt))
|
||||
{
|
||||
if (long.TryParse(txt, out long v2)
|
||||
&& long.TryParse(Config.CommonConfig.RedeemCodeFeedsUpdateVersion, out long v1))
|
||||
{
|
||||
if (v2 > v1)
|
||||
{
|
||||
RedeemCodeButtonForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1E9BFA"));
|
||||
_redeemCodeUpdateNewVersion = txt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogDebug(ex, $"获取兑换码是否存在更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 更新兑换码按钮在当前主题下的默认前景色
|
||||
private void UpdateRedeemCodeButtonDefaultForeground()
|
||||
{
|
||||
try
|
||||
{
|
||||
var brush = Application.Current.TryFindResource("TextFillColorPrimaryBrush") as Brush;
|
||||
if (brush != null)
|
||||
{
|
||||
RedeemCodeButtonForeground = brush;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略资源查找异常,走回退逻辑
|
||||
}
|
||||
|
||||
// 回退:根据当前主题类型使用黑/白色
|
||||
var isLightTheme = Config.CommonConfig.CurrentThemeType == ThemeType.LightNone
|
||||
|| Config.CommonConfig.CurrentThemeType == ThemeType.LightMica
|
||||
|| Config.CommonConfig.CurrentThemeType == ThemeType.LightAcrylic;
|
||||
RedeemCodeButtonForeground = isLightTheme ? Brushes.Black : Brushes.White;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Service.Notification;
|
||||
@@ -35,6 +37,79 @@ public class ScriptGroupProjectEditorViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
public bool? AllowJsHTTP
|
||||
{
|
||||
get
|
||||
{
|
||||
return _project.AllowJsHTTP;
|
||||
}
|
||||
set
|
||||
{
|
||||
// 为了避免误用,AllowJsHTTP禁止set,通过更新Hash来控制
|
||||
// 脚本作者更新时,如果Hash变更会自动禁用http权限,避免安全风险
|
||||
if (value == null || value == false)
|
||||
{
|
||||
_project.AllowJsHTTPHash = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_project.AllowJsHTTPHash = _project.GetHttpAllowedUrlsHash();
|
||||
}
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public record JsText(string Text, Brush Color);
|
||||
public List<JsText> JsHTTPInfoText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_project.Project == null)
|
||||
{
|
||||
_project.BuildScriptProjectRelation();
|
||||
}
|
||||
if (_project.Project == null)
|
||||
{
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText("当前脚本项目未加载", Brushes.Red)
|
||||
};
|
||||
}
|
||||
var urls = _project.Project.Manifest?.HttpAllowedUrls ?? [];
|
||||
if (urls.Length == 0)
|
||||
{
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText("当前脚本无需使用HTTP资源", Brushes.Green)
|
||||
};
|
||||
}
|
||||
return new List<JsText>
|
||||
{
|
||||
new JsText($"当前脚本使用 {urls.Length} 个HTTP资源", Brushes.OrangeRed)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public record JsLine(string Text, Brush Color);
|
||||
|
||||
public List<JsLine> JsHTTPInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_project.Project == null)
|
||||
{
|
||||
_project.BuildScriptProjectRelation();
|
||||
}
|
||||
var urls = _project.Project?.Manifest?.HttpAllowedUrls ?? [];
|
||||
var blocks = new List<JsLine>();
|
||||
foreach (var url in urls)
|
||||
{
|
||||
blocks.Add(new JsLine(url, Brushes.OrangeRed));
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
||||
public string Status
|
||||
{
|
||||
get => _project.Status;
|
||||
@@ -58,6 +133,10 @@ public class ScriptGroupProjectEditorViewModel : ObservableObject
|
||||
{
|
||||
OnPropertyChanged(nameof(AllowJsNotification));
|
||||
}
|
||||
if (e.PropertyName == nameof(ScriptGroupProject.AllowJsHTTPHash))
|
||||
{
|
||||
OnPropertyChanged(nameof(AllowJsHTTP));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
using BetterGenshinImpact.ViewModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.UseRedeemCode;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using BetterGenshinImpact.Helpers.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Windows;
|
||||
|
||||
public partial class FeedWindowViewModel : ViewModel
|
||||
{
|
||||
[ObservableProperty] private ObservableCollection<FeedItem> _feedItems = new();
|
||||
[ObservableProperty] private bool _isLoading;
|
||||
[ObservableProperty] private bool _isDisplayBtnGetLiveCodes;
|
||||
|
||||
private readonly HttpClient _httpClient = HttpClientFactory.GetCommonSendClient();
|
||||
private const string CodesJsonUrl = "https://cnb.cool/bettergi/genshin-redeem-code/-/git/raw/main/codes.json";
|
||||
|
||||
public FeedWindowViewModel()
|
||||
{
|
||||
IsDisplayBtnGetLiveCodes = GamePreviewLiveDateCalculator.IsWithinPreviewRange(DateTime.Now);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task GetLiveRedeemCodes()
|
||||
{
|
||||
IsLoading = true;
|
||||
try
|
||||
{
|
||||
var getter = new GetLiveRedeemCode();
|
||||
var codeList = await getter.GetCodeMsgAsync();
|
||||
|
||||
if (codeList.Count == 0)
|
||||
{
|
||||
Toast.Warning("暂无前瞻兑换码信息");
|
||||
return;
|
||||
}
|
||||
|
||||
var displayItems = codeList
|
||||
.Select(c => string.IsNullOrWhiteSpace(c.Items) ? null : c.Items)
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s))
|
||||
.ToList();
|
||||
|
||||
var item = new FeedItem
|
||||
{
|
||||
Title = "【实时获取】前瞻直播兑换码",
|
||||
Content = displayItems.Count > 0 ? string.Join("\n", displayItems) : string.Empty,
|
||||
Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
|
||||
Codes = codeList.Select(c => c.Code).ToList()
|
||||
};
|
||||
|
||||
// 插入到列表顶部,方便查看
|
||||
if (FeedItems.Count > 0 && FeedItems[0].Title == item.Title)
|
||||
{
|
||||
// 如果已经存在相同标题的项,则更新内容和时间
|
||||
FeedItems[0].Content = item.Content;
|
||||
FeedItems[0].Time = item.Time;
|
||||
FeedItems[0].Codes = item.Codes;
|
||||
}
|
||||
else
|
||||
{
|
||||
FeedItems.Insert(0, item);
|
||||
}
|
||||
|
||||
|
||||
Toast.Success("已实时获取前瞻兑换码");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"获取前瞻兑换码失败: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task Refresh()
|
||||
{
|
||||
await LoadRemoteDataAsync();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CopyItemCodes(FeedItem item)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (item?.Codes != null && item.Codes.Any())
|
||||
{
|
||||
var codes = string.Join("\n", item.Codes);
|
||||
UIDispatcherHelper.Invoke(() => Clipboard.SetDataObject(codes));
|
||||
RedeemCodeManager.AddNotDetectClipboardText(codes);
|
||||
Toast.Information("兑换码已复制到剪贴板");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"复制兑换码失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task AutoRedeemItem(FeedItem item)
|
||||
{
|
||||
if (item?.Codes != null && item.Codes.Count != 0)
|
||||
{
|
||||
await new TaskRunner().RunSoloTaskAsync(new UseRedemptionCodeTask(item.Codes));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LoadRemoteDataAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
try
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, CodesJsonUrl);
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var items = JsonConvert.DeserializeObject<List<FeedItem>>(json) ?? [];
|
||||
|
||||
FeedItems.Clear();
|
||||
foreach (var feed in items)
|
||||
{
|
||||
// 若存在标签文本,设置 HasTag
|
||||
feed.HasTag = !string.IsNullOrWhiteSpace(feed.Tag);
|
||||
FeedItems.Add(feed);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"获取兑换码失败: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class FeedItem : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private string _title = string.Empty;
|
||||
|
||||
[ObservableProperty] private string _content = string.Empty;
|
||||
|
||||
[ObservableProperty] private string _time = string.Empty;
|
||||
|
||||
[ObservableProperty] private string _tag = string.Empty;
|
||||
|
||||
[ObservableProperty] private bool _hasTag = false;
|
||||
|
||||
[ObservableProperty] private List<string> _codes = new();
|
||||
|
||||
[ObservableProperty] private string _valid = string.Empty;
|
||||
}
|
||||
Reference in new issue
Block a user