-
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: 自定义信仰の源 #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 自定义信仰の源 #578
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,8 @@ private void ToggleSwitchEnableNibMode_Toggled(object sender, RoutedEventArgs e) | |
|
|
||
| private static readonly Lazy<object> HitokotoHttpClient = new Lazy<object>(CreateHitokotoClient, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication); | ||
|
|
||
| private DispatcherTimer _chickenSoupAutoRotationTimer; | ||
|
|
||
| /// <summary> | ||
| /// 创建用于获取一言(Hitokoto)数据的HttpClient | ||
| /// </summary> | ||
|
|
@@ -136,8 +138,11 @@ private static object CreateHitokotoClient() | |
| /// 根据当前外观设置更新白板水印的名言文本。 | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// 当配置为内置来源时(0:OSUPlayer、1:名言警句、2:高考俗语)从对应数组中随机选择一条并设置为水印文本; | ||
| /// 当配置为一言(3)时会异步请求 Hitokoto API 并在请求中显示占位提示,成功时将返回文本设为水印,失败时记录警告日志并设置可读的失败提示文本。此方法会修改 BlackBoardWaterMark.Text,并在发生异常时记录日志且设置合适的回退文本。 | ||
| /// 汇总所有启用的来源(预设来源 + 自定义方案),从中随机选取一个: | ||
| /// 若选中预设为 osu/mottos/gaokao/phigros,从对应数组中随机选择一条; | ||
| /// 若选中预设为 hitokoto,则异步请求 Hitokoto API,并在请求中显示占位提示,成功时将返回文本设为水印,失败时记录警告日志并设置可读的失败提示文本; | ||
| /// 若选中的是自定义方案,则按行拆分其 Content 并随机选取一行。 | ||
| /// 当启用列表为空时直接返回,不修改当前文本。 | ||
| /// </remarks> | ||
| internal async Task UpdateChickenSoupTextAsync() | ||
| { | ||
|
|
@@ -148,22 +153,40 @@ internal async Task UpdateChickenSoupTextAsync() | |
| return; | ||
| } | ||
|
|
||
| if (Settings.Appearance.ChickenSoupSource == 0) | ||
| // 汇总所有启用的方案 | ||
| var enabledSchemes = new List<TipsScheme>(); | ||
|
|
||
| var enabledPresets = Settings.Appearance.EnabledPresetTipsSources; | ||
| foreach (var preset in ChickenSoup.GetPresetSchemes()) | ||
| { | ||
| int randChickenSoupIndex = new Random().Next(ChickenSoup.OSUPlayerYuLu.Length); | ||
| BlackBoardWaterMark.Text = ChickenSoup.OSUPlayerYuLu[randChickenSoupIndex]; | ||
| if (enabledPresets != null && enabledPresets.Contains(preset.PresetId)) | ||
| { | ||
| enabledSchemes.Add(preset); | ||
| } | ||
| } | ||
| else if (Settings.Appearance.ChickenSoupSource == 1) | ||
|
|
||
| var customSchemes = Settings.Appearance.CustomTipsSchemes; | ||
| if (customSchemes != null) | ||
| { | ||
| int randChickenSoupIndex = new Random().Next(ChickenSoup.MingYanJingJu.Length); | ||
| BlackBoardWaterMark.Text = ChickenSoup.MingYanJingJu[randChickenSoupIndex]; | ||
| foreach (var custom in customSchemes) | ||
| { | ||
| if (custom != null && custom.IsEnabled) | ||
| { | ||
| enabledSchemes.Add(custom); | ||
| } | ||
| } | ||
| } | ||
| else if (Settings.Appearance.ChickenSoupSource == 2) | ||
|
|
||
| if (enabledSchemes.Count == 0) | ||
| { | ||
| int randChickenSoupIndex = new Random().Next(ChickenSoup.GaoKaoPhrases.Length); | ||
| BlackBoardWaterMark.Text = ChickenSoup.GaoKaoPhrases[randChickenSoupIndex]; | ||
| return; | ||
| } | ||
| else if (Settings.Appearance.ChickenSoupSource == 3) | ||
|
|
||
| var rnd = new Random(); | ||
| var selected = enabledSchemes[rnd.Next(enabledSchemes.Count)]; | ||
|
|
||
| // Hitokoto 预设走 HTTP API | ||
| if (selected.IsPreset && selected.PresetId == "hitokoto") | ||
| { | ||
| BlackBoardWaterMark.Text = Properties.MainWindowStrings.Main_Hitokoto_Loading; | ||
|
|
||
|
|
@@ -215,17 +238,39 @@ internal async Task UpdateChickenSoupTextAsync() | |
| LogHelper.WriteLogToFile($"一言 API 请求失败: {ex.Message}", LogHelper.LogType.Warning); | ||
| BlackBoardWaterMark.Text = Properties.MainWindowStrings.Main_Hitokoto_Unavailable; | ||
| } | ||
| return; | ||
| } | ||
| else if (Settings.Appearance.ChickenSoupSource == 4) | ||
|
|
||
| // 其它预设来源 | ||
| if (selected.IsPreset && !string.IsNullOrEmpty(selected.PresetId)) | ||
| { | ||
| int randChickenSoupIndex = new Random().Next(ChickenSoup.PhigrosTips.Length); | ||
| BlackBoardWaterMark.Text = ChickenSoup.PhigrosTips[randChickenSoupIndex]; | ||
| var tips = ChickenSoup.GetTipsFromPreset(selected.PresetId); | ||
| if (tips != null && tips.Length > 0) | ||
| { | ||
| BlackBoardWaterMark.Text = tips[rnd.Next(tips.Length)]; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // 自定义方案 | ||
| if (!selected.IsPreset) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(selected.Content)) | ||
| { | ||
| return; | ||
| } | ||
| var lines = selected.Content.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); | ||
| if (lines.Length == 0) | ||
| { | ||
| return; | ||
| } | ||
| BlackBoardWaterMark.Text = lines[rnd.Next(lines.Length)]; | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| LogHelper.WriteLogToFile($"更新白板名言时出错: {ex.Message}", LogHelper.LogType.Warning); | ||
| if (Settings.Appearance.ChickenSoupSource == 3 && BlackBoardWaterMark != null) | ||
| if (BlackBoardWaterMark != null) | ||
| { | ||
| try { BlackBoardWaterMark.Text = Properties.MainWindowStrings.Main_Hitokoto_Unavailable; } catch (Exception innerEx) { System.Diagnostics.Debug.WriteLine(innerEx); } | ||
| } | ||
|
|
@@ -399,6 +444,44 @@ private static BitmapImage CreateBitmapImage(Uri uri, int decodePixelWidth = 0) | |
| return image; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 启动白板名言自动轮换计时器。 | ||
| /// </summary> | ||
| internal void StartChickenSoupAutoRotation() | ||
| { | ||
| if (!Settings.Appearance.EnableChickenSoupInWhiteboardMode) return; | ||
| if (!Settings.Appearance.EnableChickenSoupAutoRotation) return; | ||
|
|
||
| if (_chickenSoupAutoRotationTimer == null) | ||
| { | ||
| _chickenSoupAutoRotationTimer = new DispatcherTimer(); | ||
| _chickenSoupAutoRotationTimer.Tick += async (s, e) => await UpdateChickenSoupTextAsync(); | ||
| } | ||
|
|
||
| _chickenSoupAutoRotationTimer.Interval = TimeSpan.FromSeconds(Settings.Appearance.ChickenSoupAutoRotationInterval); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ink Canvas/MainWindow_cs/MW_Settings.cs:461 — Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| _chickenSoupAutoRotationTimer.Start(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 停止白板名言自动轮换计时器。 | ||
| /// </summary> | ||
| internal void StopChickenSoupAutoRotation() | ||
| { | ||
| if (_chickenSoupAutoRotationTimer != null) | ||
| { | ||
| _chickenSoupAutoRotationTimer.Stop(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 重启白板名言自动轮换计时器。 | ||
| /// </summary> | ||
| internal void RestartChickenSoupAutoRotation() | ||
| { | ||
| StopChickenSoupAutoRotation(); | ||
| StartChickenSoupAutoRotation(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 更新组合框中的自定义图标选项 | ||
| /// </summary> | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs:956 —
StartChickenSoupAutoRotation()starts rotating using the new multi-source scheme logic, but the initialBlackBoardWaterMark.Textset just above still relies on legacySettings.Appearance.ChickenSoupSource. This can make the first displayed tip not match what the user configured (e.g., custom schemes / enabled presets) until the first timer tick.Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.