mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-29 22:24:26 +08:00
0.4.5
新增STCN 24组件,优化应用启动台,允许用户隐藏应用启动台图标。优化组件拖动排放。
This commit is contained in:
@@ -55,7 +55,8 @@ public partial class AnalogClockWidget : UserControl, IDesktopComponentWidget, I
|
||||
private const double DialSize = 258;
|
||||
private const double Center = DialSize / 2;
|
||||
|
||||
private readonly AppSettingsService _settingsService = new();
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private TimeZoneService? _timeZoneService;
|
||||
private double _currentCellSize = 48;
|
||||
@@ -357,15 +358,16 @@ public partial class AnalogClockWidget : UserControl, IDesktopComponentWidget, I
|
||||
|
||||
private void LoadClockSettings()
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
var configuredTimeZoneId = string.IsNullOrWhiteSpace(snapshot.DesktopClockTimeZoneId)
|
||||
var configuredTimeZoneId = string.IsNullOrWhiteSpace(componentSnapshot.DesktopClockTimeZoneId)
|
||||
? "China Standard Time"
|
||||
: snapshot.DesktopClockTimeZoneId.Trim();
|
||||
: componentSnapshot.DesktopClockTimeZoneId.Trim();
|
||||
|
||||
_clockTimeZone = WorldClockTimeZoneCatalog.ResolveTimeZoneOrLocal(configuredTimeZoneId);
|
||||
_secondHandMode = ClockSecondHandMode.Normalize(snapshot.DesktopClockSecondHandMode);
|
||||
_secondHandMode = ClockSecondHandMode.Normalize(componentSnapshot.DesktopClockSecondHandMode);
|
||||
}
|
||||
|
||||
private void ApplySecondHandTimerInterval()
|
||||
|
||||
@@ -28,6 +28,7 @@ public partial class AnalogClockWidgetSettingsWindow : UserControl
|
||||
};
|
||||
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly TimeZoneService _timeZoneService = new();
|
||||
private bool _suppressEvents;
|
||||
@@ -48,12 +49,13 @@ public partial class AnalogClockWidgetSettingsWindow : UserControl
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
_selectedTimeZoneId = string.IsNullOrWhiteSpace(snapshot.DesktopClockTimeZoneId)
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
_selectedTimeZoneId = string.IsNullOrWhiteSpace(componentSnapshot.DesktopClockTimeZoneId)
|
||||
? "China Standard Time"
|
||||
: snapshot.DesktopClockTimeZoneId.Trim();
|
||||
_secondHandMode = ClockSecondHandMode.Normalize(snapshot.DesktopClockSecondHandMode);
|
||||
: componentSnapshot.DesktopClockTimeZoneId.Trim();
|
||||
_secondHandMode = ClockSecondHandMode.Normalize(componentSnapshot.DesktopClockSecondHandMode);
|
||||
|
||||
_allTimeZones = _timeZoneService
|
||||
.GetAllTimeZones()
|
||||
@@ -147,10 +149,10 @@ public partial class AnalogClockWidgetSettingsWindow : UserControl
|
||||
_selectedTimeZoneId = normalizedId;
|
||||
_secondHandMode = GetSelectedSecondHandMode();
|
||||
|
||||
var snapshot = _appSettingsService.Load();
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
snapshot.DesktopClockTimeZoneId = normalizedId;
|
||||
snapshot.DesktopClockSecondHandMode = _secondHandMode;
|
||||
_appSettingsService.Save(snapshot);
|
||||
_componentSettingsService.Save(snapshot);
|
||||
|
||||
SettingsChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="420"
|
||||
d:DesignHeight="300"
|
||||
x:Class="LanMountainDesktop.Views.Components.BilibiliHotSearchSettingsWindow">
|
||||
<Border Background="{DynamicResource AdaptiveBackgroundBrush}"
|
||||
Padding="16">
|
||||
<Grid RowDefinitions="Auto,Auto,*"
|
||||
RowSpacing="10">
|
||||
<TextBlock x:Name="TitleTextBlock"
|
||||
Text="Bilibili hot search settings"
|
||||
FontSize="18"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
|
||||
<TextBlock x:Name="DescriptionTextBlock"
|
||||
Grid.Row="1"
|
||||
Text="Configure auto refresh and refresh interval."
|
||||
FontSize="12"
|
||||
TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}" />
|
||||
|
||||
<ScrollViewer Grid.Row="2"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Spacing="10"
|
||||
Margin="0,0,6,0">
|
||||
<Border Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="12"
|
||||
Padding="12">
|
||||
<StackPanel Spacing="6">
|
||||
<TextBlock x:Name="AutoRefreshLabelTextBlock"
|
||||
Text="Auto refresh"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
<CheckBox x:Name="AutoRefreshCheckBox"
|
||||
Content="Enable auto refresh"
|
||||
Checked="OnAutoRefreshChanged"
|
||||
Unchecked="OnAutoRefreshChanged" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="FrequencyCardBorder"
|
||||
Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="12"
|
||||
Padding="12"
|
||||
IsVisible="False">
|
||||
<StackPanel Spacing="6">
|
||||
<TextBlock x:Name="FrequencyLabelTextBlock"
|
||||
Text="Refresh interval"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
<ComboBox x:Name="FrequencyComboBox"
|
||||
HorizontalAlignment="Stretch"
|
||||
MinWidth="0"
|
||||
SelectionChanged="OnFrequencySelectionChanged">
|
||||
<ComboBoxItem x:Name="Frequency5mItem"
|
||||
Tag="5"
|
||||
Content="5 min" />
|
||||
<ComboBoxItem x:Name="Frequency10mItem"
|
||||
Tag="10"
|
||||
Content="10 min" />
|
||||
<ComboBoxItem x:Name="Frequency15mItem"
|
||||
Tag="15"
|
||||
Content="15 min" />
|
||||
<ComboBoxItem x:Name="Frequency30mItem"
|
||||
Tag="30"
|
||||
Content="30 min" />
|
||||
<ComboBoxItem x:Name="Frequency1hItem"
|
||||
Tag="60"
|
||||
Content="1 hour" />
|
||||
<ComboBoxItem x:Name="Frequency3hItem"
|
||||
Tag="180"
|
||||
Content="3 hours" />
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Interactivity;
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class BilibiliHotSearchSettingsWindow : UserControl
|
||||
{
|
||||
private static readonly int[] SupportedIntervals = [5, 10, 15, 30, 60, 180];
|
||||
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private bool _suppressEvents;
|
||||
private string _languageCode = "zh-CN";
|
||||
|
||||
public event EventHandler? SettingsChanged;
|
||||
|
||||
public BilibiliHotSearchSettingsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
LoadState();
|
||||
ApplyLocalization();
|
||||
}
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
var enabled = componentSnapshot.BilibiliHotSearchAutoRefreshEnabled;
|
||||
var interval = NormalizeInterval(componentSnapshot.BilibiliHotSearchAutoRefreshIntervalMinutes);
|
||||
|
||||
_suppressEvents = true;
|
||||
AutoRefreshCheckBox.IsChecked = enabled;
|
||||
SelectInterval(interval);
|
||||
FrequencyCardBorder.IsVisible = enabled;
|
||||
_suppressEvents = false;
|
||||
}
|
||||
|
||||
private void ApplyLocalization()
|
||||
{
|
||||
TitleTextBlock.Text = L("bilihot.settings.title", "Bilibili hot search settings");
|
||||
DescriptionTextBlock.Text = L("bilihot.settings.desc", "Configure auto refresh and refresh interval.");
|
||||
AutoRefreshLabelTextBlock.Text = L("bilihot.settings.auto_refresh_label", "Auto refresh");
|
||||
AutoRefreshCheckBox.Content = L("bilihot.settings.auto_refresh_enabled", "Enable auto refresh");
|
||||
FrequencyLabelTextBlock.Text = L("bilihot.settings.frequency_label", "Refresh interval");
|
||||
Frequency5mItem.Content = L("bilihot.settings.frequency_5m", "5 min");
|
||||
Frequency10mItem.Content = L("bilihot.settings.frequency_10m", "10 min");
|
||||
Frequency15mItem.Content = L("bilihot.settings.frequency_15m", "15 min");
|
||||
Frequency30mItem.Content = L("bilihot.settings.frequency_30m", "30 min");
|
||||
Frequency1hItem.Content = L("bilihot.settings.frequency_1h", "1 hour");
|
||||
Frequency3hItem.Content = L("bilihot.settings.frequency_3h", "3 hours");
|
||||
}
|
||||
|
||||
private void OnAutoRefreshChanged(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
if (_suppressEvents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var enabled = AutoRefreshCheckBox.IsChecked == true;
|
||||
FrequencyCardBorder.IsVisible = enabled;
|
||||
SaveState();
|
||||
}
|
||||
|
||||
private void OnFrequencySelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
if (_suppressEvents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SaveState();
|
||||
}
|
||||
|
||||
private void SaveState()
|
||||
{
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
snapshot.BilibiliHotSearchAutoRefreshEnabled = AutoRefreshCheckBox.IsChecked == true;
|
||||
snapshot.BilibiliHotSearchAutoRefreshIntervalMinutes = GetSelectedInterval();
|
||||
_componentSettingsService.Save(snapshot);
|
||||
SettingsChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private int GetSelectedInterval()
|
||||
{
|
||||
if (FrequencyComboBox.SelectedItem is ComboBoxItem item &&
|
||||
item.Tag is string tagText &&
|
||||
int.TryParse(tagText, out var minutes))
|
||||
{
|
||||
return NormalizeInterval(minutes);
|
||||
}
|
||||
|
||||
return 15;
|
||||
}
|
||||
|
||||
private void SelectInterval(int intervalMinutes)
|
||||
{
|
||||
var selected = FrequencyComboBox.Items
|
||||
.OfType<ComboBoxItem>()
|
||||
.FirstOrDefault(item =>
|
||||
item.Tag is string tagText &&
|
||||
int.TryParse(tagText, out var minutes) &&
|
||||
minutes == intervalMinutes);
|
||||
FrequencyComboBox.SelectedItem = selected ?? FrequencyComboBox.Items.OfType<ComboBoxItem>().FirstOrDefault();
|
||||
}
|
||||
|
||||
private static int NormalizeInterval(int minutes)
|
||||
{
|
||||
if (minutes <= 0)
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
|
||||
if (SupportedIntervals.Contains(minutes))
|
||||
{
|
||||
return minutes;
|
||||
}
|
||||
|
||||
return SupportedIntervals
|
||||
.OrderBy(value => Math.Abs(value - minutes))
|
||||
.FirstOrDefault(15);
|
||||
}
|
||||
|
||||
private string L(string key, string fallback)
|
||||
{
|
||||
return _localizationService.GetString(_languageCode, key, fallback);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -24,13 +25,15 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
private const int BaseWidthCells = 4;
|
||||
private const int BaseHeightCells = 2;
|
||||
private const int MaxDisplayItemCount = 4;
|
||||
private static readonly int[] SupportedAutoRefreshIntervalsMinutes = [5, 10, 15, 30, 60, 180];
|
||||
|
||||
private readonly DispatcherTimer _refreshTimer = new()
|
||||
{
|
||||
Interval = TimeSpan.FromMinutes(15)
|
||||
};
|
||||
|
||||
private readonly AppSettingsService _settingsService = new();
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly List<BilibiliHotSearchItemSnapshot> _activeItems = [];
|
||||
private readonly List<HotItemVisual> _hotItemVisuals = [];
|
||||
@@ -42,6 +45,7 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
private double _currentCellSize = BaseCellSize;
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRefreshEnabled = true;
|
||||
|
||||
private sealed record HotItemVisual(
|
||||
Border Host,
|
||||
@@ -77,6 +81,7 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
ApplyAutoRefreshSettings();
|
||||
ApplyLoadingState();
|
||||
}
|
||||
|
||||
@@ -98,6 +103,7 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
public void RefreshFromSettings()
|
||||
{
|
||||
_recommendationService.ClearCache();
|
||||
ApplyAutoRefreshSettings();
|
||||
if (_isAttached)
|
||||
{
|
||||
_ = RefreshHotSearchAsync(forceRefresh: true);
|
||||
@@ -107,7 +113,7 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
_isAttached = true;
|
||||
_refreshTimer.Start();
|
||||
ApplyAutoRefreshSettings();
|
||||
_ = RefreshHotSearchAsync(forceRefresh: false);
|
||||
}
|
||||
|
||||
@@ -417,7 +423,7 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
{
|
||||
try
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
}
|
||||
catch
|
||||
@@ -426,6 +432,60 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyAutoRefreshSettings()
|
||||
{
|
||||
var enabled = true;
|
||||
var intervalMinutes = 15;
|
||||
|
||||
try
|
||||
{
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
enabled = snapshot.BilibiliHotSearchAutoRefreshEnabled;
|
||||
intervalMinutes = NormalizeAutoRefreshIntervalMinutes(snapshot.BilibiliHotSearchAutoRefreshIntervalMinutes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Keep fallback defaults.
|
||||
}
|
||||
|
||||
_autoRefreshEnabled = enabled;
|
||||
_refreshTimer.Interval = TimeSpan.FromMinutes(intervalMinutes);
|
||||
|
||||
if (!_isAttached)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_autoRefreshEnabled)
|
||||
{
|
||||
if (!_refreshTimer.IsEnabled)
|
||||
{
|
||||
_refreshTimer.Start();
|
||||
}
|
||||
}
|
||||
else if (_refreshTimer.IsEnabled)
|
||||
{
|
||||
_refreshTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private static int NormalizeAutoRefreshIntervalMinutes(int minutes)
|
||||
{
|
||||
if (minutes <= 0)
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
|
||||
if (SupportedAutoRefreshIntervalsMinutes.Contains(minutes))
|
||||
{
|
||||
return minutes;
|
||||
}
|
||||
|
||||
return SupportedAutoRefreshIntervalsMinutes
|
||||
.OrderBy(value => Math.Abs(value - minutes))
|
||||
.FirstOrDefault(15);
|
||||
}
|
||||
|
||||
private static string NormalizeCompactText(string? text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace LanMountainDesktop.Views.Components;
|
||||
public partial class ClassScheduleSettingsWindow : UserControl
|
||||
{
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly List<ImportedClassScheduleSnapshot> _importedSchedules = [];
|
||||
private string _activeScheduleId = string.Empty;
|
||||
@@ -35,11 +36,12 @@ public partial class ClassScheduleSettingsWindow : UserControl
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
_importedSchedules.Clear();
|
||||
foreach (var item in snapshot.ImportedClassSchedules)
|
||||
foreach (var item in componentSnapshot.ImportedClassSchedules)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(item.Id) ||
|
||||
string.IsNullOrWhiteSpace(item.FilePath))
|
||||
@@ -55,7 +57,7 @@ public partial class ClassScheduleSettingsWindow : UserControl
|
||||
});
|
||||
}
|
||||
|
||||
_activeScheduleId = snapshot.ActiveImportedClassScheduleId?.Trim() ?? string.Empty;
|
||||
_activeScheduleId = componentSnapshot.ActiveImportedClassScheduleId?.Trim() ?? string.Empty;
|
||||
if (_importedSchedules.Count > 0 &&
|
||||
!_importedSchedules.Any(item => string.Equals(item.Id, _activeScheduleId, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
@@ -297,7 +299,7 @@ public partial class ClassScheduleSettingsWindow : UserControl
|
||||
|
||||
private void SaveState()
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
snapshot.ImportedClassSchedules = _importedSchedules
|
||||
.Select(item => new ImportedClassScheduleSnapshot
|
||||
{
|
||||
@@ -307,7 +309,7 @@ public partial class ClassScheduleSettingsWindow : UserControl
|
||||
})
|
||||
.ToList();
|
||||
snapshot.ActiveImportedClassScheduleId = _activeScheduleId ?? string.Empty;
|
||||
_appSettingsService.Save(snapshot);
|
||||
_componentSettingsService.Save(snapshot);
|
||||
SettingsChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
};
|
||||
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly IClassIslandScheduleDataService _scheduleService = new ClassIslandScheduleDataService();
|
||||
|
||||
@@ -115,11 +116,12 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
private void RefreshSchedule()
|
||||
{
|
||||
var appSettings = _appSettingsService.Load();
|
||||
var componentSettings = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSettings.LanguageCode);
|
||||
var now = _timeZoneService?.GetCurrentTime() ?? DateTime.Now;
|
||||
UpdateHeader(now);
|
||||
|
||||
var importedSchedulePath = ResolveImportedSchedulePath(appSettings);
|
||||
var importedSchedulePath = ResolveImportedSchedulePath(componentSettings);
|
||||
var readResult = _scheduleService.Load(importedSchedulePath);
|
||||
if (!readResult.Success || readResult.Snapshot is null)
|
||||
{
|
||||
@@ -273,7 +275,7 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
return dayOfWeek.ToString()[..3];
|
||||
}
|
||||
|
||||
private static string? ResolveImportedSchedulePath(AppSettingsSnapshot snapshot)
|
||||
private static string? ResolveImportedSchedulePath(ComponentSettingsSnapshot snapshot)
|
||||
{
|
||||
if (snapshot.ImportedClassSchedules.Count == 0)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ public partial class CnrDailyNewsSettingsWindow : UserControl
|
||||
private static readonly int[] SupportedIntervals = [5, 10, 40, 60, 720, 1440];
|
||||
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private bool _suppressEvents;
|
||||
private string _languageCode = "zh-CN";
|
||||
@@ -27,11 +28,12 @@ public partial class CnrDailyNewsSettingsWindow : UserControl
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
var enabled = snapshot.CnrDailyNewsAutoRotateEnabled;
|
||||
var interval = NormalizeInterval(snapshot.CnrDailyNewsAutoRotateIntervalMinutes);
|
||||
var enabled = componentSnapshot.CnrDailyNewsAutoRotateEnabled;
|
||||
var interval = NormalizeInterval(componentSnapshot.CnrDailyNewsAutoRotateIntervalMinutes);
|
||||
|
||||
_suppressEvents = true;
|
||||
AutoRotateCheckBox.IsChecked = enabled;
|
||||
@@ -83,10 +85,10 @@ public partial class CnrDailyNewsSettingsWindow : UserControl
|
||||
|
||||
private void SaveState()
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
snapshot.CnrDailyNewsAutoRotateEnabled = AutoRotateCheckBox.IsChecked == true;
|
||||
snapshot.CnrDailyNewsAutoRotateIntervalMinutes = GetSelectedInterval();
|
||||
_appSettingsService.Save(snapshot);
|
||||
_componentSettingsService.Save(snapshot);
|
||||
SettingsChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
Interval = TimeSpan.FromMinutes(30)
|
||||
};
|
||||
|
||||
private readonly AppSettingsService _settingsService = new();
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly Bitmap?[] _newsBitmaps = new Bitmap?[2];
|
||||
private readonly List<string?> _newsUrls = [];
|
||||
@@ -705,7 +706,7 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
{
|
||||
try
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
}
|
||||
catch
|
||||
@@ -721,7 +722,7 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
|
||||
try
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
enabled = snapshot.CnrDailyNewsAutoRotateEnabled;
|
||||
intervalMinutes = NormalizeAutoRotateIntervalMinutes(snapshot.CnrDailyNewsAutoRotateIntervalMinutes);
|
||||
}
|
||||
|
||||
@@ -10,14 +10,13 @@ namespace LanMountainDesktop.Views.Components;
|
||||
public partial class DailyArtworkSettingsWindow : UserControl
|
||||
{
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private string _languageCode = "zh-CN";
|
||||
private bool _suppressEvents;
|
||||
|
||||
public event EventHandler? SettingsChanged;
|
||||
|
||||
public string CurrentSource => GetSelectedSource();
|
||||
|
||||
public DailyArtworkSettingsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -27,10 +26,11 @@ public partial class DailyArtworkSettingsWindow : UserControl
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
var source = DailyArtworkMirrorSources.Normalize(snapshot.DailyArtworkMirrorSource);
|
||||
var source = DailyArtworkMirrorSources.Normalize(componentSnapshot.DailyArtworkMirrorSource);
|
||||
_suppressEvents = true;
|
||||
MirrorSourceComboBox.SelectedIndex = string.Equals(source, DailyArtworkMirrorSources.Domestic, StringComparison.OrdinalIgnoreCase)
|
||||
? 0
|
||||
@@ -59,9 +59,9 @@ public partial class DailyArtworkSettingsWindow : UserControl
|
||||
}
|
||||
|
||||
var source = GetSelectedSource();
|
||||
var snapshot = _appSettingsService.Load();
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
snapshot.DailyArtworkMirrorSource = source;
|
||||
_appSettingsService.Save(snapshot);
|
||||
_componentSettingsService.Save(snapshot);
|
||||
|
||||
UpdateSourceStatus(source);
|
||||
SettingsChanged?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="420"
|
||||
d:DesignHeight="300"
|
||||
x:Class="LanMountainDesktop.Views.Components.DailyWordSettingsWindow">
|
||||
<Border Background="{DynamicResource AdaptiveBackgroundBrush}"
|
||||
Padding="16">
|
||||
<Grid RowDefinitions="Auto,Auto,*"
|
||||
RowSpacing="10">
|
||||
<TextBlock x:Name="TitleTextBlock"
|
||||
Text="Daily word settings"
|
||||
FontSize="18"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
|
||||
<TextBlock x:Name="DescriptionTextBlock"
|
||||
Grid.Row="1"
|
||||
Text="Configure auto refresh and refresh interval."
|
||||
FontSize="12"
|
||||
TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}" />
|
||||
|
||||
<ScrollViewer Grid.Row="2"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Spacing="10"
|
||||
Margin="0,0,6,0">
|
||||
<Border Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="12"
|
||||
Padding="12">
|
||||
<StackPanel Spacing="6">
|
||||
<TextBlock x:Name="AutoRefreshLabelTextBlock"
|
||||
Text="Auto refresh"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
<CheckBox x:Name="AutoRefreshCheckBox"
|
||||
Content="Enable auto refresh"
|
||||
Checked="OnAutoRefreshChanged"
|
||||
Unchecked="OnAutoRefreshChanged" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="FrequencyCardBorder"
|
||||
Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="12"
|
||||
Padding="12"
|
||||
IsVisible="False">
|
||||
<StackPanel Spacing="6">
|
||||
<TextBlock x:Name="FrequencyLabelTextBlock"
|
||||
Text="Refresh interval"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
<ComboBox x:Name="FrequencyComboBox"
|
||||
HorizontalAlignment="Stretch"
|
||||
MinWidth="0"
|
||||
SelectionChanged="OnFrequencySelectionChanged">
|
||||
<ComboBoxItem x:Name="Frequency30mItem"
|
||||
Tag="30"
|
||||
Content="30 min" />
|
||||
<ComboBoxItem x:Name="Frequency1hItem"
|
||||
Tag="60"
|
||||
Content="1 hour" />
|
||||
<ComboBoxItem x:Name="Frequency3hItem"
|
||||
Tag="180"
|
||||
Content="3 hours" />
|
||||
<ComboBoxItem x:Name="Frequency6hItem"
|
||||
Tag="360"
|
||||
Content="6 hours" />
|
||||
<ComboBoxItem x:Name="Frequency12hItem"
|
||||
Tag="720"
|
||||
Content="12 hours" />
|
||||
<ComboBoxItem x:Name="Frequency24hItem"
|
||||
Tag="1440"
|
||||
Content="24 hours" />
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Interactivity;
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class DailyWordSettingsWindow : UserControl
|
||||
{
|
||||
private static readonly int[] SupportedIntervals = [30, 60, 180, 360, 720, 1440];
|
||||
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private bool _suppressEvents;
|
||||
private string _languageCode = "zh-CN";
|
||||
|
||||
public event EventHandler? SettingsChanged;
|
||||
|
||||
public DailyWordSettingsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
LoadState();
|
||||
ApplyLocalization();
|
||||
}
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
var enabled = componentSnapshot.DailyWordAutoRefreshEnabled;
|
||||
var interval = NormalizeInterval(componentSnapshot.DailyWordAutoRefreshIntervalMinutes);
|
||||
|
||||
_suppressEvents = true;
|
||||
AutoRefreshCheckBox.IsChecked = enabled;
|
||||
SelectInterval(interval);
|
||||
FrequencyCardBorder.IsVisible = enabled;
|
||||
_suppressEvents = false;
|
||||
}
|
||||
|
||||
private void ApplyLocalization()
|
||||
{
|
||||
TitleTextBlock.Text = L("dailyword.settings.title", "Daily word settings");
|
||||
DescriptionTextBlock.Text = L("dailyword.settings.desc", "Configure auto refresh and refresh interval.");
|
||||
AutoRefreshLabelTextBlock.Text = L("dailyword.settings.auto_refresh_label", "Auto refresh");
|
||||
AutoRefreshCheckBox.Content = L("dailyword.settings.auto_refresh_enabled", "Enable auto refresh");
|
||||
FrequencyLabelTextBlock.Text = L("dailyword.settings.frequency_label", "Refresh interval");
|
||||
Frequency30mItem.Content = L("dailyword.settings.frequency_30m", "30 min");
|
||||
Frequency1hItem.Content = L("dailyword.settings.frequency_1h", "1 hour");
|
||||
Frequency3hItem.Content = L("dailyword.settings.frequency_3h", "3 hours");
|
||||
Frequency6hItem.Content = L("dailyword.settings.frequency_6h", "6 hours");
|
||||
Frequency12hItem.Content = L("dailyword.settings.frequency_12h", "12 hours");
|
||||
Frequency24hItem.Content = L("dailyword.settings.frequency_24h", "24 hours");
|
||||
}
|
||||
|
||||
private void OnAutoRefreshChanged(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
if (_suppressEvents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var enabled = AutoRefreshCheckBox.IsChecked == true;
|
||||
FrequencyCardBorder.IsVisible = enabled;
|
||||
SaveState();
|
||||
}
|
||||
|
||||
private void OnFrequencySelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
if (_suppressEvents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SaveState();
|
||||
}
|
||||
|
||||
private void SaveState()
|
||||
{
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
snapshot.DailyWordAutoRefreshEnabled = AutoRefreshCheckBox.IsChecked == true;
|
||||
snapshot.DailyWordAutoRefreshIntervalMinutes = GetSelectedInterval();
|
||||
_componentSettingsService.Save(snapshot);
|
||||
SettingsChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private int GetSelectedInterval()
|
||||
{
|
||||
if (FrequencyComboBox.SelectedItem is ComboBoxItem item &&
|
||||
item.Tag is string tagText &&
|
||||
int.TryParse(tagText, out var minutes))
|
||||
{
|
||||
return NormalizeInterval(minutes);
|
||||
}
|
||||
|
||||
return 360;
|
||||
}
|
||||
|
||||
private void SelectInterval(int intervalMinutes)
|
||||
{
|
||||
var selected = FrequencyComboBox.Items
|
||||
.OfType<ComboBoxItem>()
|
||||
.FirstOrDefault(item =>
|
||||
item.Tag is string tagText &&
|
||||
int.TryParse(tagText, out var minutes) &&
|
||||
minutes == intervalMinutes);
|
||||
FrequencyComboBox.SelectedItem = selected ?? FrequencyComboBox.Items.OfType<ComboBoxItem>().FirstOrDefault();
|
||||
}
|
||||
|
||||
private static int NormalizeInterval(int minutes)
|
||||
{
|
||||
if (minutes <= 0)
|
||||
{
|
||||
return 360;
|
||||
}
|
||||
|
||||
if (SupportedIntervals.Contains(minutes))
|
||||
{
|
||||
return minutes;
|
||||
}
|
||||
|
||||
return SupportedIntervals
|
||||
.OrderBy(value => Math.Abs(value - minutes))
|
||||
.FirstOrDefault(360);
|
||||
}
|
||||
|
||||
private string L(string key, string fallback)
|
||||
{
|
||||
return _localizationService.GetString(_languageCode, key, fallback);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -21,13 +22,15 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
private const double BaseCellSize = 48d;
|
||||
private const int BaseWidthCells = 4;
|
||||
private const int BaseHeightCells = 2;
|
||||
private static readonly int[] SupportedAutoRefreshIntervalsMinutes = [30, 60, 180, 360, 720, 1440];
|
||||
|
||||
private readonly DispatcherTimer _refreshTimer = new()
|
||||
{
|
||||
Interval = TimeSpan.FromHours(6)
|
||||
};
|
||||
|
||||
private readonly AppSettingsService _settingsService = new();
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
|
||||
private IRecommendationInfoService _recommendationService = DefaultRecommendationService;
|
||||
@@ -36,6 +39,7 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
private double _currentCellSize = BaseCellSize;
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRefreshEnabled = true;
|
||||
|
||||
public DailyWordWidget()
|
||||
{
|
||||
@@ -56,6 +60,7 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
ApplyAutoRefreshSettings();
|
||||
ApplyLoadingState();
|
||||
UpdateRefreshButtonState();
|
||||
}
|
||||
@@ -78,6 +83,7 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
public void RefreshFromSettings()
|
||||
{
|
||||
_recommendationService.ClearCache();
|
||||
ApplyAutoRefreshSettings();
|
||||
if (_isAttached)
|
||||
{
|
||||
_ = RefreshWordAsync(forceRefresh: true);
|
||||
@@ -87,8 +93,8 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
_isAttached = true;
|
||||
ApplyAutoRefreshSettings();
|
||||
UpdateRefreshButtonState();
|
||||
_refreshTimer.Start();
|
||||
_ = RefreshWordAsync(forceRefresh: false);
|
||||
}
|
||||
|
||||
@@ -343,7 +349,7 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
{
|
||||
try
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
}
|
||||
catch
|
||||
@@ -352,6 +358,60 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyAutoRefreshSettings()
|
||||
{
|
||||
var enabled = true;
|
||||
var intervalMinutes = 360;
|
||||
|
||||
try
|
||||
{
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
enabled = snapshot.DailyWordAutoRefreshEnabled;
|
||||
intervalMinutes = NormalizeAutoRefreshIntervalMinutes(snapshot.DailyWordAutoRefreshIntervalMinutes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Keep fallback defaults.
|
||||
}
|
||||
|
||||
_autoRefreshEnabled = enabled;
|
||||
_refreshTimer.Interval = TimeSpan.FromMinutes(intervalMinutes);
|
||||
|
||||
if (!_isAttached)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_autoRefreshEnabled)
|
||||
{
|
||||
if (!_refreshTimer.IsEnabled)
|
||||
{
|
||||
_refreshTimer.Start();
|
||||
}
|
||||
}
|
||||
else if (_refreshTimer.IsEnabled)
|
||||
{
|
||||
_refreshTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private static int NormalizeAutoRefreshIntervalMinutes(int minutes)
|
||||
{
|
||||
if (minutes <= 0)
|
||||
{
|
||||
return 360;
|
||||
}
|
||||
|
||||
if (SupportedAutoRefreshIntervalsMinutes.Contains(minutes))
|
||||
{
|
||||
return minutes;
|
||||
}
|
||||
|
||||
return SupportedAutoRefreshIntervalsMinutes
|
||||
.OrderBy(value => Math.Abs(value - minutes))
|
||||
.FirstOrDefault(360);
|
||||
}
|
||||
|
||||
private void CancelRefreshRequest()
|
||||
{
|
||||
var cts = Interlocked.Exchange(ref _refreshCts, null);
|
||||
|
||||
@@ -250,6 +250,11 @@ public sealed class DesktopComponentRuntimeRegistry
|
||||
"component.bilibili_hot_search",
|
||||
() => new BilibiliHotSearchWidget(),
|
||||
cellSize => Math.Clamp(cellSize * 0.34, 14, 30)),
|
||||
new DesktopComponentRuntimeRegistration(
|
||||
BuiltInComponentIds.DesktopStcn24Forum,
|
||||
"component.stcn24_forum",
|
||||
() => new Stcn24ForumWidget(),
|
||||
cellSize => Math.Clamp(cellSize * 0.28, 12, 24)),
|
||||
new DesktopComponentRuntimeRegistration(
|
||||
BuiltInComponentIds.DesktopExchangeRateCalculator,
|
||||
"component.exchange_rate_converter",
|
||||
|
||||
246
LanMountainDesktop/Views/Components/Stcn24ForumWidget.axaml
Normal file
246
LanMountainDesktop/Views/Components/Stcn24ForumWidget.axaml
Normal file
@@ -0,0 +1,246 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
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:fi="using:FluentIcons.Avalonia"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="320"
|
||||
d:DesignHeight="320"
|
||||
x:Class="LanMountainDesktop.Views.Components.Stcn24ForumWidget">
|
||||
|
||||
<Border x:Name="RootBorder"
|
||||
CornerRadius="28"
|
||||
Background="Transparent"
|
||||
ClipToBounds="True"
|
||||
BorderThickness="0"
|
||||
Padding="0">
|
||||
<Grid>
|
||||
<Border x:Name="CardBorder"
|
||||
Background="#FCFCFD"
|
||||
CornerRadius="28"
|
||||
BorderBrush="Transparent"
|
||||
BorderThickness="0"
|
||||
Padding="12,12,12,12">
|
||||
<Grid x:Name="ContentGrid"
|
||||
RowDefinitions="Auto,Auto,Auto,Auto,Auto"
|
||||
RowSpacing="6">
|
||||
<Grid x:Name="HeaderGrid"
|
||||
Grid.Row="0"
|
||||
ColumnDefinitions="*,Auto"
|
||||
ColumnSpacing="8">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Spacing="8"
|
||||
VerticalAlignment="Center">
|
||||
<Border x:Name="HeaderDot"
|
||||
Width="8"
|
||||
Height="8"
|
||||
CornerRadius="4"
|
||||
Background="#FF4D4F"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBlock x:Name="HeaderTitleTextBlock"
|
||||
Text="STCN 24"
|
||||
Foreground="#202327"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
VerticalAlignment="Center"
|
||||
MaxLines="1"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</StackPanel>
|
||||
|
||||
<Button x:Name="RefreshButton"
|
||||
Grid.Column="1"
|
||||
Width="34"
|
||||
Height="34"
|
||||
CornerRadius="17"
|
||||
Background="#EFF1F5"
|
||||
BorderBrush="Transparent"
|
||||
BorderThickness="0"
|
||||
Padding="0"
|
||||
Focusable="False"
|
||||
Click="OnRefreshButtonClick">
|
||||
<fi:SymbolIcon x:Name="RefreshGlyphIcon"
|
||||
Symbol="ArrowClockwise"
|
||||
IconVariant="Regular"
|
||||
Foreground="#5E6671"
|
||||
FontSize="16"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<Border x:Name="PostItem1Host"
|
||||
Grid.Row="1"
|
||||
Tag="0"
|
||||
Background="#F7F8FA"
|
||||
CornerRadius="10"
|
||||
Padding="8,6"
|
||||
PointerPressed="OnPostItemPointerPressed">
|
||||
<Grid x:Name="PostItem1Grid"
|
||||
ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="8">
|
||||
<Border x:Name="PostItem1AvatarHost"
|
||||
Width="30"
|
||||
Height="30"
|
||||
CornerRadius="15"
|
||||
Background="#E7EBF4"
|
||||
ClipToBounds="True">
|
||||
<Grid>
|
||||
<Image x:Name="PostItem1AvatarImage"
|
||||
Stretch="UniformToFill" />
|
||||
<TextBlock x:Name="PostItem1AvatarFallbackText"
|
||||
Text="?"
|
||||
Foreground="#4A5466"
|
||||
FontSize="13"
|
||||
FontWeight="SemiBold"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<TextBlock x:Name="PostItem1TitleTextBlock"
|
||||
Grid.Column="1"
|
||||
Text="Loading..."
|
||||
Foreground="#202327"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
MaxLines="1"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="PostItem2Host"
|
||||
Grid.Row="2"
|
||||
Tag="1"
|
||||
Background="#F7F8FA"
|
||||
CornerRadius="10"
|
||||
Padding="8,6"
|
||||
PointerPressed="OnPostItemPointerPressed">
|
||||
<Grid x:Name="PostItem2Grid"
|
||||
ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="8">
|
||||
<Border x:Name="PostItem2AvatarHost"
|
||||
Width="30"
|
||||
Height="30"
|
||||
CornerRadius="15"
|
||||
Background="#E7EBF4"
|
||||
ClipToBounds="True">
|
||||
<Grid>
|
||||
<Image x:Name="PostItem2AvatarImage"
|
||||
Stretch="UniformToFill" />
|
||||
<TextBlock x:Name="PostItem2AvatarFallbackText"
|
||||
Text="?"
|
||||
Foreground="#4A5466"
|
||||
FontSize="13"
|
||||
FontWeight="SemiBold"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<TextBlock x:Name="PostItem2TitleTextBlock"
|
||||
Grid.Column="1"
|
||||
Text="Loading..."
|
||||
Foreground="#202327"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
MaxLines="1"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="PostItem3Host"
|
||||
Grid.Row="3"
|
||||
Tag="2"
|
||||
Background="#F7F8FA"
|
||||
CornerRadius="10"
|
||||
Padding="8,6"
|
||||
PointerPressed="OnPostItemPointerPressed">
|
||||
<Grid x:Name="PostItem3Grid"
|
||||
ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="8">
|
||||
<Border x:Name="PostItem3AvatarHost"
|
||||
Width="30"
|
||||
Height="30"
|
||||
CornerRadius="15"
|
||||
Background="#E7EBF4"
|
||||
ClipToBounds="True">
|
||||
<Grid>
|
||||
<Image x:Name="PostItem3AvatarImage"
|
||||
Stretch="UniformToFill" />
|
||||
<TextBlock x:Name="PostItem3AvatarFallbackText"
|
||||
Text="?"
|
||||
Foreground="#4A5466"
|
||||
FontSize="13"
|
||||
FontWeight="SemiBold"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<TextBlock x:Name="PostItem3TitleTextBlock"
|
||||
Grid.Column="1"
|
||||
Text="Loading..."
|
||||
Foreground="#202327"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
MaxLines="1"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="PostItem4Host"
|
||||
Grid.Row="4"
|
||||
Tag="3"
|
||||
Background="#F7F8FA"
|
||||
CornerRadius="10"
|
||||
Padding="8,6"
|
||||
PointerPressed="OnPostItemPointerPressed">
|
||||
<Grid x:Name="PostItem4Grid"
|
||||
ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="8">
|
||||
<Border x:Name="PostItem4AvatarHost"
|
||||
Width="30"
|
||||
Height="30"
|
||||
CornerRadius="15"
|
||||
Background="#E7EBF4"
|
||||
ClipToBounds="True">
|
||||
<Grid>
|
||||
<Image x:Name="PostItem4AvatarImage"
|
||||
Stretch="UniformToFill" />
|
||||
<TextBlock x:Name="PostItem4AvatarFallbackText"
|
||||
Text="?"
|
||||
Foreground="#4A5466"
|
||||
FontSize="13"
|
||||
FontWeight="SemiBold"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<TextBlock x:Name="PostItem4TitleTextBlock"
|
||||
Grid.Column="1"
|
||||
Text="Loading..."
|
||||
Foreground="#202327"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
MaxLines="1"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<TextBlock x:Name="StatusTextBlock"
|
||||
IsVisible="False"
|
||||
Text="Loading..."
|
||||
Foreground="#6A6F77"
|
||||
FontSize="14"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
618
LanMountainDesktop/Views/Components/Stcn24ForumWidget.axaml.cs
Normal file
618
LanMountainDesktop/Views/Components/Stcn24ForumWidget.axaml.cs
Normal file
@@ -0,0 +1,618 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class Stcn24ForumWidget : UserControl, IDesktopComponentWidget, IRecommendationInfoAwareComponentWidget
|
||||
{
|
||||
private static readonly Regex MultiWhitespaceRegex = new(@"\s+", RegexOptions.Compiled);
|
||||
private static readonly FontFamily MiSansFontFamily = new("MiSans VF, avares://LanMountainDesktop/Assets/Fonts#MiSans");
|
||||
private static readonly IRecommendationInfoService DefaultRecommendationService = new RecommendationDataService();
|
||||
private static readonly HttpClient AvatarHttpClient = new()
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(8)
|
||||
};
|
||||
|
||||
private const string AvatarRequestUserAgent =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0 Safari/537.36";
|
||||
|
||||
private const double BaseCellSize = 48d;
|
||||
private const int BaseWidthCells = 4;
|
||||
private const int BaseHeightCells = 4;
|
||||
private const int MaxDisplayItemCount = 4;
|
||||
|
||||
private readonly DispatcherTimer _refreshTimer = new()
|
||||
{
|
||||
Interval = TimeSpan.FromMinutes(20)
|
||||
};
|
||||
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly List<Stcn24ForumPostItemSnapshot> _activeItems = [];
|
||||
private readonly List<ForumItemVisual> _itemVisuals = [];
|
||||
private readonly Bitmap?[] _avatarBitmaps = new Bitmap?[MaxDisplayItemCount];
|
||||
|
||||
private IRecommendationInfoService _recommendationService = DefaultRecommendationService;
|
||||
private CancellationTokenSource? _refreshCts;
|
||||
private string _languageCode = "zh-CN";
|
||||
private double _currentCellSize = BaseCellSize;
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
|
||||
private sealed record ForumItemVisual(
|
||||
Border Host,
|
||||
Grid RowGrid,
|
||||
Border AvatarHost,
|
||||
Image AvatarImage,
|
||||
TextBlock AvatarFallbackText,
|
||||
TextBlock TitleTextBlock);
|
||||
|
||||
public Stcn24ForumWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
HeaderTitleTextBlock.FontFamily = MiSansFontFamily;
|
||||
PostItem1TitleTextBlock.FontFamily = MiSansFontFamily;
|
||||
PostItem2TitleTextBlock.FontFamily = MiSansFontFamily;
|
||||
PostItem3TitleTextBlock.FontFamily = MiSansFontFamily;
|
||||
PostItem4TitleTextBlock.FontFamily = MiSansFontFamily;
|
||||
PostItem1AvatarFallbackText.FontFamily = MiSansFontFamily;
|
||||
PostItem2AvatarFallbackText.FontFamily = MiSansFontFamily;
|
||||
PostItem3AvatarFallbackText.FontFamily = MiSansFontFamily;
|
||||
PostItem4AvatarFallbackText.FontFamily = MiSansFontFamily;
|
||||
StatusTextBlock.FontFamily = MiSansFontFamily;
|
||||
|
||||
_itemVisuals.Add(new ForumItemVisual(
|
||||
PostItem1Host,
|
||||
PostItem1Grid,
|
||||
PostItem1AvatarHost,
|
||||
PostItem1AvatarImage,
|
||||
PostItem1AvatarFallbackText,
|
||||
PostItem1TitleTextBlock));
|
||||
_itemVisuals.Add(new ForumItemVisual(
|
||||
PostItem2Host,
|
||||
PostItem2Grid,
|
||||
PostItem2AvatarHost,
|
||||
PostItem2AvatarImage,
|
||||
PostItem2AvatarFallbackText,
|
||||
PostItem2TitleTextBlock));
|
||||
_itemVisuals.Add(new ForumItemVisual(
|
||||
PostItem3Host,
|
||||
PostItem3Grid,
|
||||
PostItem3AvatarHost,
|
||||
PostItem3AvatarImage,
|
||||
PostItem3AvatarFallbackText,
|
||||
PostItem3TitleTextBlock));
|
||||
_itemVisuals.Add(new ForumItemVisual(
|
||||
PostItem4Host,
|
||||
PostItem4Grid,
|
||||
PostItem4AvatarHost,
|
||||
PostItem4AvatarImage,
|
||||
PostItem4AvatarFallbackText,
|
||||
PostItem4TitleTextBlock));
|
||||
|
||||
_refreshTimer.Tick += OnRefreshTimerTick;
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
ApplyLoadingState();
|
||||
UpdateInteractionState();
|
||||
UpdateRefreshButtonState();
|
||||
}
|
||||
|
||||
public void ApplyCellSize(double cellSize)
|
||||
{
|
||||
_currentCellSize = Math.Max(1, cellSize);
|
||||
UpdateAdaptiveLayout();
|
||||
}
|
||||
|
||||
public void SetRecommendationInfoService(IRecommendationInfoService recommendationInfoService)
|
||||
{
|
||||
_recommendationService = recommendationInfoService ?? DefaultRecommendationService;
|
||||
if (_isAttached)
|
||||
{
|
||||
_ = RefreshPostsAsync(forceRefresh: false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
_isAttached = true;
|
||||
if (!_refreshTimer.IsEnabled)
|
||||
{
|
||||
_refreshTimer.Start();
|
||||
}
|
||||
|
||||
_ = RefreshPostsAsync(forceRefresh: false);
|
||||
}
|
||||
|
||||
private void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
_isAttached = false;
|
||||
_refreshTimer.Stop();
|
||||
CancelRefreshRequest();
|
||||
DisposeAvatarBitmaps();
|
||||
}
|
||||
|
||||
private void OnSizeChanged(object? sender, SizeChangedEventArgs e)
|
||||
{
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private async void OnRefreshButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isRefreshing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RefreshPostsAsync(forceRefresh: true);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async void OnRefreshTimerTick(object? sender, EventArgs e)
|
||||
{
|
||||
await RefreshPostsAsync(forceRefresh: false);
|
||||
}
|
||||
|
||||
private void OnPostItemPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed ||
|
||||
sender is not Border host ||
|
||||
host.Tag is null ||
|
||||
!int.TryParse(host.Tag.ToString(), out var index) ||
|
||||
index < 0 ||
|
||||
index >= _activeItems.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TryOpenUrl(_activeItems[index].Url);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async Task RefreshPostsAsync(bool forceRefresh)
|
||||
{
|
||||
if (!_isAttached || _isRefreshing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isRefreshing = true;
|
||||
UpdateRefreshButtonState();
|
||||
UpdateLanguageCode();
|
||||
|
||||
var cts = new CancellationTokenSource();
|
||||
var previous = Interlocked.Exchange(ref _refreshCts, cts);
|
||||
previous?.Cancel();
|
||||
previous?.Dispose();
|
||||
|
||||
try
|
||||
{
|
||||
var query = new Stcn24ForumPostsQuery(
|
||||
Locale: _languageCode,
|
||||
ItemCount: MaxDisplayItemCount,
|
||||
ForceRefresh: forceRefresh);
|
||||
var result = await _recommendationService.GetStcn24ForumPostsAsync(query, cts.Token);
|
||||
if (!_isAttached || cts.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.Success || result.Data is null)
|
||||
{
|
||||
ApplyFailedState();
|
||||
return;
|
||||
}
|
||||
|
||||
await ApplySnapshotAsync(result.Data, cts.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Ignore canceled requests.
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (_isAttached && !cts.IsCancellationRequested)
|
||||
{
|
||||
ApplyFailedState();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ReferenceEquals(_refreshCts, cts))
|
||||
{
|
||||
_refreshCts = null;
|
||||
}
|
||||
|
||||
cts.Dispose();
|
||||
_isRefreshing = false;
|
||||
UpdateRefreshButtonState();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApplySnapshotAsync(Stcn24ForumPostsSnapshot snapshot, CancellationToken cancellationToken)
|
||||
{
|
||||
_activeItems.Clear();
|
||||
foreach (var item in snapshot.Items)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(item.Title) || string.IsNullOrWhiteSpace(item.Url))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_activeItems.Add(item);
|
||||
if (_activeItems.Count >= MaxDisplayItemCount)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var fallbackItemText = L("stcn24.widget.fallback_item", "暂无帖子");
|
||||
for (var i = 0; i < _itemVisuals.Count; i++)
|
||||
{
|
||||
var visual = _itemVisuals[i];
|
||||
if (i < _activeItems.Count)
|
||||
{
|
||||
var item = _activeItems[i];
|
||||
visual.TitleTextBlock.Text = NormalizeCompactText(item.Title);
|
||||
visual.AvatarFallbackText.Text = ResolveAvatarFallbackText(item.AuthorDisplayName);
|
||||
}
|
||||
else
|
||||
{
|
||||
visual.TitleTextBlock.Text = fallbackItemText;
|
||||
visual.AvatarFallbackText.Text = "?";
|
||||
}
|
||||
|
||||
SetAvatarBitmap(i, null);
|
||||
}
|
||||
|
||||
StatusTextBlock.IsVisible = false;
|
||||
UpdateInteractionState();
|
||||
UpdateAdaptiveLayout();
|
||||
|
||||
var tasks = _activeItems
|
||||
.Select(item => TryDownloadAvatarBitmapAsync(item.AuthorAvatarUrl, cancellationToken))
|
||||
.ToArray();
|
||||
if (tasks.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var bitmaps = await Task.WhenAll(tasks);
|
||||
if (cancellationToken.IsCancellationRequested || !_isAttached)
|
||||
{
|
||||
foreach (var bitmap in bitmaps)
|
||||
{
|
||||
bitmap?.Dispose();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < bitmaps.Length && i < _itemVisuals.Count; i++)
|
||||
{
|
||||
SetAvatarBitmap(i, bitmaps[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyLoadingState()
|
||||
{
|
||||
_activeItems.Clear();
|
||||
StatusTextBlock.Text = L("stcn24.widget.loading", "加载中...");
|
||||
StatusTextBlock.IsVisible = true;
|
||||
|
||||
var loadingText = L("stcn24.widget.loading_item", "加载中...");
|
||||
for (var i = 0; i < _itemVisuals.Count; i++)
|
||||
{
|
||||
var visual = _itemVisuals[i];
|
||||
visual.TitleTextBlock.Text = loadingText;
|
||||
visual.AvatarFallbackText.Text = "?";
|
||||
SetAvatarBitmap(i, null);
|
||||
}
|
||||
|
||||
UpdateInteractionState();
|
||||
UpdateAdaptiveLayout();
|
||||
}
|
||||
|
||||
private void ApplyFailedState()
|
||||
{
|
||||
_activeItems.Clear();
|
||||
StatusTextBlock.Text = L("stcn24.widget.fetch_failed", "帖子获取失败");
|
||||
StatusTextBlock.IsVisible = true;
|
||||
|
||||
var fallbackText = L("stcn24.widget.fallback_item", "暂无帖子");
|
||||
for (var i = 0; i < _itemVisuals.Count; i++)
|
||||
{
|
||||
var visual = _itemVisuals[i];
|
||||
visual.TitleTextBlock.Text = fallbackText;
|
||||
visual.AvatarFallbackText.Text = "?";
|
||||
SetAvatarBitmap(i, null);
|
||||
}
|
||||
|
||||
UpdateInteractionState();
|
||||
UpdateAdaptiveLayout();
|
||||
}
|
||||
|
||||
private void UpdateInteractionState()
|
||||
{
|
||||
var enabledBackground = new SolidColorBrush(Color.Parse("#F7F8FA"));
|
||||
var disabledBackground = new SolidColorBrush(Color.Parse("#F2F3F5"));
|
||||
|
||||
for (var i = 0; i < _itemVisuals.Count; i++)
|
||||
{
|
||||
var visual = _itemVisuals[i];
|
||||
var enabled = i < _activeItems.Count && !string.IsNullOrWhiteSpace(_activeItems[i].Url);
|
||||
visual.Host.IsHitTestVisible = enabled;
|
||||
visual.Host.Opacity = enabled ? 1.0 : 0.72;
|
||||
visual.Host.Cursor = enabled
|
||||
? new Cursor(StandardCursorType.Hand)
|
||||
: new Cursor(StandardCursorType.Arrow);
|
||||
visual.Host.Background = enabled
|
||||
? enabledBackground
|
||||
: disabledBackground;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRefreshButtonState()
|
||||
{
|
||||
RefreshButton.IsEnabled = !_isRefreshing;
|
||||
RefreshButton.Opacity = _isRefreshing ? 0.58 : 1.0;
|
||||
}
|
||||
|
||||
private void UpdateLanguageCode()
|
||||
{
|
||||
try
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_languageCode = "zh-CN";
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAdaptiveLayout()
|
||||
{
|
||||
var scale = ResolveScale();
|
||||
var softScale = Math.Clamp(scale, 0.80, 1.40);
|
||||
var totalWidth = Bounds.Width > 1 ? Bounds.Width : _currentCellSize * BaseWidthCells;
|
||||
var totalHeight = Bounds.Height > 1 ? Bounds.Height : _currentCellSize * BaseHeightCells;
|
||||
|
||||
RootBorder.CornerRadius = new CornerRadius(Math.Clamp(30 * softScale, 14, 44));
|
||||
CardBorder.CornerRadius = new CornerRadius(Math.Clamp(30 * softScale, 14, 44));
|
||||
CardBorder.Padding = new Thickness(
|
||||
Math.Clamp(12 * softScale, 8, 18),
|
||||
Math.Clamp(12 * softScale, 8, 18),
|
||||
Math.Clamp(12 * softScale, 8, 18),
|
||||
Math.Clamp(12 * softScale, 8, 18));
|
||||
|
||||
var rowSpacing = Math.Clamp(6 * softScale, 3, 10);
|
||||
ContentGrid.RowSpacing = rowSpacing;
|
||||
HeaderGrid.ColumnSpacing = Math.Clamp(8 * softScale, 5, 12);
|
||||
|
||||
HeaderDot.Width = Math.Clamp(8 * softScale, 5, 12);
|
||||
HeaderDot.Height = HeaderDot.Width;
|
||||
HeaderDot.CornerRadius = new CornerRadius(HeaderDot.Width / 2d);
|
||||
HeaderTitleTextBlock.FontSize = Math.Clamp(20 * softScale, 12, 28);
|
||||
|
||||
var refreshSize = Math.Clamp(34 * softScale, 22, 42);
|
||||
RefreshButton.Width = refreshSize;
|
||||
RefreshButton.Height = refreshSize;
|
||||
RefreshButton.CornerRadius = new CornerRadius(refreshSize / 2d);
|
||||
RefreshGlyphIcon.FontSize = Math.Clamp(16 * softScale, 10, 20);
|
||||
|
||||
var innerWidth = Math.Max(100, totalWidth - CardBorder.Padding.Left - CardBorder.Padding.Right);
|
||||
var rowPaddingHorizontal = Math.Clamp(8 * softScale, 5, 14);
|
||||
var rowPaddingVertical = Math.Clamp(6 * softScale, 3, 10);
|
||||
var itemCornerRadius = Math.Clamp(10 * softScale, 6, 14);
|
||||
var avatarSize = Math.Clamp(30 * softScale, 20, 40);
|
||||
var avatarFont = Math.Clamp(13 * softScale, 9, 18);
|
||||
var titleFont = Math.Clamp(14 * softScale, 10, 19);
|
||||
var titleMaxWidth = Math.Max(60, innerWidth - avatarSize - (rowPaddingHorizontal * 2d) - 18);
|
||||
|
||||
foreach (var visual in _itemVisuals)
|
||||
{
|
||||
visual.Host.CornerRadius = new CornerRadius(itemCornerRadius);
|
||||
visual.Host.Padding = new Thickness(rowPaddingHorizontal, rowPaddingVertical);
|
||||
visual.RowGrid.ColumnSpacing = Math.Clamp(8 * softScale, 4, 12);
|
||||
|
||||
visual.AvatarHost.Width = avatarSize;
|
||||
visual.AvatarHost.Height = avatarSize;
|
||||
visual.AvatarHost.CornerRadius = new CornerRadius(avatarSize / 2d);
|
||||
|
||||
visual.AvatarFallbackText.FontSize = avatarFont;
|
||||
visual.TitleTextBlock.FontSize = titleFont;
|
||||
visual.TitleTextBlock.MaxWidth = titleMaxWidth;
|
||||
}
|
||||
|
||||
StatusTextBlock.FontSize = Math.Clamp(14 * softScale, 10, 18);
|
||||
}
|
||||
|
||||
private static string NormalizeCompactText(string? text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return MultiWhitespaceRegex.Replace(text.Trim(), " ");
|
||||
}
|
||||
|
||||
private static string ResolveAvatarFallbackText(string? displayName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(displayName))
|
||||
{
|
||||
return "?";
|
||||
}
|
||||
|
||||
var compact = displayName.Trim();
|
||||
var first = compact[0];
|
||||
return first.ToString().ToUpperInvariant();
|
||||
}
|
||||
|
||||
private static async Task<Bitmap?> TryDownloadAvatarBitmapAsync(string? avatarUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
var normalizedUrl = NormalizeHttpUrl(avatarUrl);
|
||||
if (string.IsNullOrWhiteSpace(normalizedUrl))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, normalizedUrl);
|
||||
request.Headers.TryAddWithoutValidation("User-Agent", AvatarRequestUserAgent);
|
||||
request.Headers.TryAddWithoutValidation("Accept", "image/avif,image/webp,image/apng,image/*,*/*;q=0.8");
|
||||
using var response = await AvatarHttpClient.SendAsync(
|
||||
request,
|
||||
HttpCompletionOption.ResponseHeadersRead,
|
||||
cancellationToken);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken);
|
||||
var memory = new MemoryStream();
|
||||
await stream.CopyToAsync(memory, cancellationToken);
|
||||
memory.Position = 0;
|
||||
return new Bitmap(memory);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAvatarBitmap(int index, Bitmap? bitmap)
|
||||
{
|
||||
if (index < 0 || index >= _avatarBitmaps.Length || index >= _itemVisuals.Count)
|
||||
{
|
||||
bitmap?.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
var visual = _itemVisuals[index];
|
||||
var oldBitmap = _avatarBitmaps[index];
|
||||
if (ReferenceEquals(visual.AvatarImage.Source, oldBitmap))
|
||||
{
|
||||
visual.AvatarImage.Source = null;
|
||||
}
|
||||
|
||||
oldBitmap?.Dispose();
|
||||
_avatarBitmaps[index] = bitmap;
|
||||
visual.AvatarImage.Source = bitmap;
|
||||
visual.AvatarFallbackText.IsVisible = bitmap is null;
|
||||
}
|
||||
|
||||
private void DisposeAvatarBitmaps()
|
||||
{
|
||||
for (var i = 0; i < _avatarBitmaps.Length; i++)
|
||||
{
|
||||
SetAvatarBitmap(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static string? NormalizeHttpUrl(string? rawUrl)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rawUrl))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var candidate = rawUrl.Trim();
|
||||
if (!Uri.TryCreate(candidate, UriKind.Absolute, out var uri))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!string.Equals(uri.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(uri.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return uri.ToString();
|
||||
}
|
||||
|
||||
private void TryOpenUrl(string? rawUrl)
|
||||
{
|
||||
var normalizedUrl = NormalizeHttpUrl(rawUrl);
|
||||
if (string.IsNullOrWhiteSpace(normalizedUrl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = normalizedUrl,
|
||||
UseShellExecute = true
|
||||
};
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore malformed URLs or shell launch failures.
|
||||
}
|
||||
}
|
||||
|
||||
private double ResolveScale()
|
||||
{
|
||||
var expectedWidth = _currentCellSize * BaseWidthCells;
|
||||
var expectedHeight = _currentCellSize * BaseHeightCells;
|
||||
if (expectedWidth <= 0 || expectedHeight <= 0)
|
||||
{
|
||||
return 1d;
|
||||
}
|
||||
|
||||
var actualWidth = Bounds.Width > 1 ? Bounds.Width : expectedWidth;
|
||||
var actualHeight = Bounds.Height > 1 ? Bounds.Height : expectedHeight;
|
||||
var scaleX = actualWidth / expectedWidth;
|
||||
var scaleY = actualHeight / expectedHeight;
|
||||
return Math.Clamp(Math.Min(scaleX, scaleY), 0.62, 2.6);
|
||||
}
|
||||
|
||||
private string L(string key, string fallback)
|
||||
{
|
||||
return _localizationService.GetString(_languageCode, key, fallback);
|
||||
}
|
||||
|
||||
private void CancelRefreshRequest()
|
||||
{
|
||||
var cts = Interlocked.Exchange(ref _refreshCts, null);
|
||||
if (cts is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cts.Cancel();
|
||||
cts.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ public partial class StudyEnvironmentWidget : UserControl, IDesktopComponentWidg
|
||||
{
|
||||
private readonly IStudyAnalyticsService _studyAnalyticsService = StudyAnalyticsServiceFactory.CreateDefault();
|
||||
private readonly StudyAnalyticsMonitoringLeaseCoordinator _monitoringLeaseCoordinator = StudyAnalyticsMonitoringLeaseCoordinatorFactory.CreateDefault();
|
||||
private readonly AppSettingsService _settingsService = new();
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly DispatcherTimer _uiTimer = new()
|
||||
{
|
||||
@@ -127,10 +128,11 @@ public partial class StudyEnvironmentWidget : UserControl, IDesktopComponentWidg
|
||||
|
||||
private void ReloadDisplaySettings()
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
_showDisplayDb = snapshot.StudyEnvironmentShowDisplayDb;
|
||||
_showDbfs = snapshot.StudyEnvironmentShowDbfs;
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
_showDisplayDb = componentSnapshot.StudyEnvironmentShowDisplayDb;
|
||||
_showDbfs = componentSnapshot.StudyEnvironmentShowDbfs;
|
||||
if (!_showDisplayDb && !_showDbfs)
|
||||
{
|
||||
_showDisplayDb = true;
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace LanMountainDesktop.Views.Components;
|
||||
public partial class StudyEnvironmentWidgetSettingsWindow : UserControl
|
||||
{
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private string _languageCode = "zh-CN";
|
||||
private bool _suppressEvents;
|
||||
@@ -23,11 +24,12 @@ public partial class StudyEnvironmentWidgetSettingsWindow : UserControl
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
var showDisplayDb = snapshot.StudyEnvironmentShowDisplayDb;
|
||||
var showDbfs = snapshot.StudyEnvironmentShowDbfs;
|
||||
var showDisplayDb = componentSnapshot.StudyEnvironmentShowDisplayDb;
|
||||
var showDbfs = componentSnapshot.StudyEnvironmentShowDbfs;
|
||||
if (!showDisplayDb && !showDbfs)
|
||||
{
|
||||
showDisplayDb = true;
|
||||
@@ -75,10 +77,10 @@ public partial class StudyEnvironmentWidgetSettingsWindow : UserControl
|
||||
showDisplayDb = true;
|
||||
}
|
||||
|
||||
var snapshot = _appSettingsService.Load();
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
snapshot.StudyEnvironmentShowDisplayDb = showDisplayDb;
|
||||
snapshot.StudyEnvironmentShowDbfs = showDbfs;
|
||||
_appSettingsService.Save(snapshot);
|
||||
_componentSettingsService.Save(snapshot);
|
||||
|
||||
SettingsChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,8 @@ public partial class WorldClockWidget : UserControl, IDesktopComponentWidget, IT
|
||||
Interval = TimeSpan.FromSeconds(1)
|
||||
};
|
||||
|
||||
private readonly AppSettingsService _settingsService = new();
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly ClockEntryVisual[] _entryVisuals = new ClockEntryVisual[WorldClockTimeZoneCatalog.ClockCount];
|
||||
private readonly TimeZoneInfo[] _entryTimeZones = new TimeZoneInfo[WorldClockTimeZoneCatalog.ClockCount];
|
||||
@@ -445,17 +446,18 @@ public partial class WorldClockWidget : UserControl, IDesktopComponentWidget, IT
|
||||
|
||||
private void LoadFromSettings()
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
var ids = WorldClockTimeZoneCatalog.NormalizeTimeZoneIds(snapshot.WorldClockTimeZoneIds);
|
||||
var ids = WorldClockTimeZoneCatalog.NormalizeTimeZoneIds(componentSnapshot.WorldClockTimeZoneIds);
|
||||
for (var index = 0; index < WorldClockTimeZoneCatalog.ClockCount; index++)
|
||||
{
|
||||
var resolvedId = ids[index];
|
||||
_entryTimeZones[index] = WorldClockTimeZoneCatalog.ResolveTimeZoneOrLocal(resolvedId);
|
||||
}
|
||||
|
||||
_secondHandMode = ClockSecondHandMode.Normalize(snapshot.WorldClockSecondHandMode);
|
||||
_secondHandMode = ClockSecondHandMode.Normalize(componentSnapshot.WorldClockSecondHandMode);
|
||||
}
|
||||
|
||||
private void ApplySecondHandTimerInterval()
|
||||
@@ -533,7 +535,7 @@ public partial class WorldClockWidget : UserControl, IDesktopComponentWidget, IT
|
||||
_nextLanguageProbeUtc = utcNow.AddSeconds(25);
|
||||
try
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -28,6 +28,7 @@ public partial class WorldClockWidgetSettingsWindow : UserControl
|
||||
};
|
||||
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly TimeZoneService _timeZoneService = new();
|
||||
private readonly ComboBox[] _timeZoneComboBoxes;
|
||||
@@ -58,8 +59,9 @@ public partial class WorldClockWidgetSettingsWindow : UserControl
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
var snapshot = _appSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
|
||||
var appSnapshot = _appSettingsService.Load();
|
||||
var componentSnapshot = _componentSettingsService.Load();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(appSnapshot.LanguageCode);
|
||||
|
||||
_allTimeZones = _timeZoneService
|
||||
.GetAllTimeZones()
|
||||
@@ -68,9 +70,9 @@ public partial class WorldClockWidgetSettingsWindow : UserControl
|
||||
.ToList();
|
||||
|
||||
_selectedTimeZoneIds = WorldClockTimeZoneCatalog.NormalizeTimeZoneIds(
|
||||
snapshot.WorldClockTimeZoneIds,
|
||||
componentSnapshot.WorldClockTimeZoneIds,
|
||||
_allTimeZones);
|
||||
_secondHandMode = ClockSecondHandMode.Normalize(snapshot.WorldClockSecondHandMode);
|
||||
_secondHandMode = ClockSecondHandMode.Normalize(componentSnapshot.WorldClockSecondHandMode);
|
||||
}
|
||||
|
||||
private void ApplyLocalization()
|
||||
@@ -165,10 +167,10 @@ public partial class WorldClockWidgetSettingsWindow : UserControl
|
||||
var normalizedIds = WorldClockTimeZoneCatalog.NormalizeTimeZoneIds(selectedIds, _allTimeZones);
|
||||
_secondHandMode = GetSelectedSecondHandMode();
|
||||
|
||||
var snapshot = _appSettingsService.Load();
|
||||
var snapshot = _componentSettingsService.Load();
|
||||
snapshot.WorldClockTimeZoneIds = normalizedIds.ToList();
|
||||
snapshot.WorldClockSecondHandMode = _secondHandMode;
|
||||
_appSettingsService.Save(snapshot);
|
||||
_componentSettingsService.Save(snapshot);
|
||||
|
||||
_selectedTimeZoneIds = normalizedIds;
|
||||
SettingsChanged?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
@@ -731,6 +731,18 @@ public partial class MainWindow
|
||||
return;
|
||||
}
|
||||
|
||||
if (placement.ComponentId == BuiltInComponentIds.DesktopDailyWord)
|
||||
{
|
||||
OpenDailyWordComponentSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
if (placement.ComponentId == BuiltInComponentIds.DesktopBilibiliHotSearch)
|
||||
{
|
||||
OpenBilibiliHotSearchComponentSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
if (placement.ComponentId == BuiltInComponentIds.DesktopStudyEnvironment)
|
||||
{
|
||||
OpenStudyEnvironmentComponentSettings();
|
||||
@@ -850,6 +862,38 @@ public partial class MainWindow
|
||||
ComponentSettingsWindow.Opacity = 1;
|
||||
}
|
||||
|
||||
private void OpenDailyWordComponentSettings()
|
||||
{
|
||||
if (ComponentSettingsWindow is null || ComponentSettingsContentHost is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var settingsContent = new DailyWordSettingsWindow();
|
||||
settingsContent.SettingsChanged += OnDailyWordSettingsChanged;
|
||||
ComponentSettingsContentHost.Content = settingsContent;
|
||||
|
||||
ComponentSettingsWindow.IsVisible = true;
|
||||
ComponentSettingsWindow.Opacity = 0;
|
||||
ComponentSettingsWindow.Opacity = 1;
|
||||
}
|
||||
|
||||
private void OpenBilibiliHotSearchComponentSettings()
|
||||
{
|
||||
if (ComponentSettingsWindow is null || ComponentSettingsContentHost is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var settingsContent = new BilibiliHotSearchSettingsWindow();
|
||||
settingsContent.SettingsChanged += OnBilibiliHotSearchSettingsChanged;
|
||||
ComponentSettingsContentHost.Content = settingsContent;
|
||||
|
||||
ComponentSettingsWindow.IsVisible = true;
|
||||
ComponentSettingsWindow.Opacity = 0;
|
||||
ComponentSettingsWindow.Opacity = 1;
|
||||
}
|
||||
|
||||
private void OnClassScheduleSettingsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (_selectedDesktopComponentHost is null)
|
||||
@@ -883,8 +927,6 @@ public partial class MainWindow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PersistSettings();
|
||||
}
|
||||
|
||||
private void OnStudyEnvironmentSettingsChanged(object? sender, EventArgs e)
|
||||
@@ -907,10 +949,6 @@ public partial class MainWindow
|
||||
_ = sender;
|
||||
_ = e;
|
||||
|
||||
_dailyArtworkMirrorSource = sender is DailyArtworkSettingsWindow settingsWindow
|
||||
? DailyArtworkMirrorSources.Normalize(settingsWindow.CurrentSource)
|
||||
: DailyArtworkMirrorSources.Normalize(_appSettingsService.Load().DailyArtworkMirrorSource);
|
||||
|
||||
foreach (var pageGrid in _desktopPageComponentGrids.Values)
|
||||
{
|
||||
foreach (var host in pageGrid.Children.OfType<Border>())
|
||||
@@ -926,8 +964,6 @@ public partial class MainWindow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PersistSettings();
|
||||
}
|
||||
|
||||
private void OnWorldClockSettingsChanged(object? sender, EventArgs e)
|
||||
@@ -950,8 +986,6 @@ public partial class MainWindow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PersistSettings();
|
||||
}
|
||||
|
||||
private void OnCnrDailyNewsSettingsChanged(object? sender, EventArgs e)
|
||||
@@ -974,8 +1008,50 @@ public partial class MainWindow
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PersistSettings();
|
||||
private void OnDailyWordSettingsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
|
||||
foreach (var pageGrid in _desktopPageComponentGrids.Values)
|
||||
{
|
||||
foreach (var host in pageGrid.Children.OfType<Border>())
|
||||
{
|
||||
if (!host.Classes.Contains(DesktopComponentHostClass))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TryGetContentHost(host)?.Child is DailyWordWidget widget)
|
||||
{
|
||||
widget.RefreshFromSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBilibiliHotSearchSettingsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
|
||||
foreach (var pageGrid in _desktopPageComponentGrids.Values)
|
||||
{
|
||||
foreach (var host in pageGrid.Children.OfType<Border>())
|
||||
{
|
||||
if (!host.Classes.Contains(DesktopComponentHostClass))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TryGetContentHost(host)?.Child is BilibiliHotSearchWidget widget)
|
||||
{
|
||||
widget.RefreshFromSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseComponentSettingsWindow()
|
||||
@@ -1015,6 +1091,16 @@ public partial class MainWindow
|
||||
cnrDailyNewsSettingsWindow.SettingsChanged -= OnCnrDailyNewsSettingsChanged;
|
||||
}
|
||||
|
||||
if (ComponentSettingsContentHost?.Content is DailyWordSettingsWindow dailyWordSettingsWindow)
|
||||
{
|
||||
dailyWordSettingsWindow.SettingsChanged -= OnDailyWordSettingsChanged;
|
||||
}
|
||||
|
||||
if (ComponentSettingsContentHost?.Content is BilibiliHotSearchSettingsWindow bilibiliHotSearchSettingsWindow)
|
||||
{
|
||||
bilibiliHotSearchSettingsWindow.SettingsChanged -= OnBilibiliHotSearchSettingsChanged;
|
||||
}
|
||||
|
||||
ComponentSettingsWindow.Opacity = 0;
|
||||
|
||||
DispatcherTimer.RunOnce(() =>
|
||||
@@ -1434,6 +1520,14 @@ public partial class MainWindow
|
||||
new ComponentScaleRule(WidthUnit: 2, HeightUnit: 1, MinScale: 2));
|
||||
}
|
||||
|
||||
if (string.Equals(componentId, BuiltInComponentIds.DesktopStcn24Forum, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Keep STCN forum widget square with a minimum footprint of 4x4.
|
||||
return SnapSpanToScaleRules(
|
||||
span,
|
||||
new ComponentScaleRule(WidthUnit: 1, HeightUnit: 1, MinScale: 4));
|
||||
}
|
||||
|
||||
if (string.Equals(componentId, BuiltInComponentIds.DesktopExchangeRateCalculator, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Keep exchange rate converter square with minimum size 4x4.
|
||||
@@ -2826,12 +2920,16 @@ public partial class MainWindow
|
||||
_weatherDataService,
|
||||
_recommendationInfoService,
|
||||
_calculatorDataService);
|
||||
// Component library previews must stay non-interactive so drag gesture is reliable.
|
||||
previewControl.IsHitTestVisible = false;
|
||||
previewControl.Focusable = false;
|
||||
|
||||
var previewSurface = new Border
|
||||
{
|
||||
Width = previewSpan.WidthCells * renderCellSize,
|
||||
Height = previewSpan.HeightCells * renderCellSize,
|
||||
Background = Brushes.Transparent,
|
||||
IsHitTestVisible = false,
|
||||
Child = previewControl
|
||||
};
|
||||
|
||||
|
||||
@@ -22,9 +22,26 @@ public partial class MainWindow
|
||||
{
|
||||
private const int MinDesktopPageCount = 1;
|
||||
private const int MaxDesktopPageCount = 12;
|
||||
private enum LauncherEntryKind
|
||||
{
|
||||
Folder,
|
||||
Shortcut
|
||||
}
|
||||
|
||||
private sealed record LauncherHiddenItemToken(LauncherEntryKind Kind, string Key);
|
||||
|
||||
private sealed record LauncherHiddenItemView(
|
||||
LauncherEntryKind Kind,
|
||||
string Key,
|
||||
string DisplayName,
|
||||
string Monogram,
|
||||
Bitmap? IconBitmap);
|
||||
|
||||
private readonly WindowsStartMenuService _windowsStartMenuService = new();
|
||||
private readonly Dictionary<string, Bitmap> _launcherIconCache = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Stack<StartMenuFolderNode> _launcherFolderStack = [];
|
||||
private readonly HashSet<string> _hiddenLauncherFolderPaths = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly HashSet<string> _hiddenLauncherAppPaths = new(StringComparer.OrdinalIgnoreCase);
|
||||
private StartMenuFolderNode _startMenuRoot = new("All Apps", string.Empty);
|
||||
private byte[]? _launcherFolderIconPngBytes;
|
||||
private Bitmap? _launcherFolderIconBitmap;
|
||||
@@ -52,6 +69,35 @@ public partial class MainWindow
|
||||
_currentDesktopSurfaceIndex = Math.Clamp(snapshot.CurrentDesktopSurfaceIndex, 0, LauncherSurfaceIndex);
|
||||
}
|
||||
|
||||
private void InitializeLauncherVisibilitySettings(AppSettingsSnapshot snapshot)
|
||||
{
|
||||
_hiddenLauncherFolderPaths.Clear();
|
||||
if (snapshot.HiddenLauncherFolderPaths is not null)
|
||||
{
|
||||
foreach (var folderPath in snapshot.HiddenLauncherFolderPaths)
|
||||
{
|
||||
var key = NormalizeLauncherHiddenKey(folderPath);
|
||||
if (!string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
_hiddenLauncherFolderPaths.Add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_hiddenLauncherAppPaths.Clear();
|
||||
if (snapshot.HiddenLauncherAppPaths is not null)
|
||||
{
|
||||
foreach (var appPath in snapshot.HiddenLauncherAppPaths)
|
||||
{
|
||||
var key = NormalizeLauncherHiddenKey(appPath);
|
||||
if (!string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
_hiddenLauncherAppPaths.Add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeDesktopSurfaceSwipeHandlers()
|
||||
{
|
||||
// Capture swipe intent before child controls consume pointer events.
|
||||
@@ -80,6 +126,7 @@ public partial class MainWindow
|
||||
_launcherFolderIconBitmap?.Dispose();
|
||||
_launcherFolderIconBitmap = null;
|
||||
RenderLauncherRootTiles();
|
||||
RenderLauncherHiddenItemsList();
|
||||
}, DispatcherPriority.Background);
|
||||
}
|
||||
catch
|
||||
@@ -89,6 +136,7 @@ public partial class MainWindow
|
||||
_launcherFolderIconBitmap?.Dispose();
|
||||
_launcherFolderIconBitmap = null;
|
||||
RenderLauncherRootTiles();
|
||||
RenderLauncherHiddenItemsList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -695,11 +743,21 @@ public partial class MainWindow
|
||||
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
if (!IsLauncherFolderVisible(folder))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LauncherRootTilePanel.Children.Add(CreateLauncherFolderTile(folder));
|
||||
}
|
||||
|
||||
foreach (var app in apps)
|
||||
{
|
||||
if (!IsLauncherAppVisible(app))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LauncherRootTilePanel.Children.Add(CreateLauncherAppTile(app));
|
||||
}
|
||||
|
||||
@@ -719,24 +777,28 @@ public partial class MainWindow
|
||||
var title = folder.Name;
|
||||
var subtitle = Lf("launcher.folder_items_format", "{0} apps", folder.TotalAppCount);
|
||||
var folderIconBitmap = GetLauncherFolderIconBitmap();
|
||||
var folderKey = NormalizeLauncherHiddenKey(folder.RelativePath);
|
||||
return CreateLauncherTileButton(
|
||||
title,
|
||||
subtitle,
|
||||
monogram: "DIR",
|
||||
iconBitmap: folderIconBitmap,
|
||||
() => OpenLauncherFolder(folder));
|
||||
() => OpenLauncherFolder(folder),
|
||||
hideAction: string.IsNullOrWhiteSpace(folderKey) ? null : () => HideLauncherFolder(folder));
|
||||
}
|
||||
|
||||
private Button CreateLauncherAppTile(StartMenuAppEntry app)
|
||||
{
|
||||
var iconBitmap = GetLauncherIconBitmap(app);
|
||||
var monogram = BuildMonogram(app.DisplayName);
|
||||
var appKey = NormalizeLauncherHiddenKey(app.RelativePath);
|
||||
return CreateLauncherTileButton(
|
||||
app.DisplayName,
|
||||
subtitle: string.Empty,
|
||||
monogram,
|
||||
iconBitmap,
|
||||
() => LaunchStartMenuEntry(app));
|
||||
() => LaunchStartMenuEntry(app),
|
||||
hideAction: string.IsNullOrWhiteSpace(appKey) ? null : () => HideLauncherApp(app));
|
||||
}
|
||||
|
||||
private Control CreateLauncherHintTile(string title, string subtitle)
|
||||
@@ -779,7 +841,8 @@ public partial class MainWindow
|
||||
string subtitle,
|
||||
string monogram,
|
||||
Bitmap? iconBitmap,
|
||||
Action clickAction)
|
||||
Action clickAction,
|
||||
Action? hideAction = null)
|
||||
{
|
||||
Control iconControl = iconBitmap is not null
|
||||
? new Image
|
||||
@@ -853,9 +916,310 @@ public partial class MainWindow
|
||||
// 不设置固定 Width 和 Height,由 UpdateLauncherTileLayout 动态设置
|
||||
};
|
||||
button.Click += (_, _) => clickAction();
|
||||
AttachLauncherTileContextMenu(button, hideAction);
|
||||
return button;
|
||||
}
|
||||
|
||||
private static string NormalizeLauncherHiddenKey(string? key)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(key) ? string.Empty : key.Trim();
|
||||
}
|
||||
|
||||
private bool IsLauncherFolderVisible(StartMenuFolderNode folder)
|
||||
{
|
||||
var key = NormalizeLauncherHiddenKey(folder.RelativePath);
|
||||
return string.IsNullOrWhiteSpace(key) || !_hiddenLauncherFolderPaths.Contains(key);
|
||||
}
|
||||
|
||||
private bool IsLauncherAppVisible(StartMenuAppEntry app)
|
||||
{
|
||||
var key = NormalizeLauncherHiddenKey(app.RelativePath);
|
||||
return string.IsNullOrWhiteSpace(key) || !_hiddenLauncherAppPaths.Contains(key);
|
||||
}
|
||||
|
||||
private void AttachLauncherTileContextMenu(Button tileButton, Action? hideAction)
|
||||
{
|
||||
if (hideAction is null)
|
||||
{
|
||||
tileButton.ContextMenu = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var hideItem = new MenuItem
|
||||
{
|
||||
Header = L("launcher.context.hide_icon", "Hide Icon")
|
||||
};
|
||||
hideItem.Click += (_, _) => hideAction();
|
||||
|
||||
var contextMenu = new ContextMenu();
|
||||
contextMenu.Items.Add(hideItem);
|
||||
tileButton.ContextMenu = contextMenu;
|
||||
}
|
||||
|
||||
private void HideLauncherFolder(StartMenuFolderNode folder)
|
||||
{
|
||||
var key = NormalizeLauncherHiddenKey(folder.RelativePath);
|
||||
if (string.IsNullOrWhiteSpace(key) || !_hiddenLauncherFolderPaths.Add(key))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyLauncherVisibilitySettingsChange();
|
||||
}
|
||||
|
||||
private void HideLauncherApp(StartMenuAppEntry app)
|
||||
{
|
||||
var key = NormalizeLauncherHiddenKey(app.RelativePath);
|
||||
if (string.IsNullOrWhiteSpace(key) || !_hiddenLauncherAppPaths.Add(key))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyLauncherVisibilitySettingsChange();
|
||||
}
|
||||
|
||||
private void ApplyLauncherVisibilitySettingsChange()
|
||||
{
|
||||
RenderLauncherRootTiles();
|
||||
if (_launcherFolderStack.Count > 0)
|
||||
{
|
||||
RenderLauncherFolderFromStack();
|
||||
}
|
||||
|
||||
RenderLauncherHiddenItemsList();
|
||||
PersistSettings();
|
||||
}
|
||||
|
||||
private void RenderLauncherHiddenItemsList()
|
||||
{
|
||||
if (LauncherHiddenItemsListPanel is null || LauncherHiddenItemsEmptyTextBlock is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LauncherHiddenItemsListPanel.Children.Clear();
|
||||
var hiddenItems = BuildLauncherHiddenItems();
|
||||
LauncherHiddenItemsEmptyTextBlock.IsVisible = hiddenItems.Count == 0;
|
||||
if (hiddenItems.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var hiddenItem in hiddenItems)
|
||||
{
|
||||
LauncherHiddenItemsListPanel.Children.Add(CreateLauncherHiddenItemRow(hiddenItem));
|
||||
}
|
||||
}
|
||||
|
||||
private IReadOnlyList<LauncherHiddenItemView> BuildLauncherHiddenItems()
|
||||
{
|
||||
var items = new List<LauncherHiddenItemView>();
|
||||
var seenFolders = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var seenApps = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
CollectHiddenLauncherItems(_startMenuRoot, items, seenFolders, seenApps);
|
||||
|
||||
foreach (var key in _hiddenLauncherFolderPaths.OrderBy(path => path, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
if (!seenFolders.Contains(key))
|
||||
{
|
||||
items.Add(new LauncherHiddenItemView(
|
||||
LauncherEntryKind.Folder,
|
||||
key,
|
||||
BuildLauncherHiddenFallbackDisplayName(key),
|
||||
"DIR",
|
||||
GetLauncherFolderIconBitmap()));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var key in _hiddenLauncherAppPaths.OrderBy(path => path, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
if (!seenApps.Contains(key))
|
||||
{
|
||||
var fallbackName = BuildLauncherHiddenFallbackDisplayName(key);
|
||||
items.Add(new LauncherHiddenItemView(
|
||||
LauncherEntryKind.Shortcut,
|
||||
key,
|
||||
fallbackName,
|
||||
BuildMonogram(fallbackName),
|
||||
IconBitmap: null));
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
.OrderBy(item => item.DisplayName, StringComparer.CurrentCultureIgnoreCase)
|
||||
.ThenBy(item => item.Key, StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void CollectHiddenLauncherItems(
|
||||
StartMenuFolderNode folder,
|
||||
List<LauncherHiddenItemView> items,
|
||||
HashSet<string> seenFolders,
|
||||
HashSet<string> seenApps)
|
||||
{
|
||||
foreach (var subFolder in folder.Folders)
|
||||
{
|
||||
var folderKey = NormalizeLauncherHiddenKey(subFolder.RelativePath);
|
||||
if (!string.IsNullOrWhiteSpace(folderKey) &&
|
||||
_hiddenLauncherFolderPaths.Contains(folderKey) &&
|
||||
seenFolders.Add(folderKey))
|
||||
{
|
||||
items.Add(new LauncherHiddenItemView(
|
||||
LauncherEntryKind.Folder,
|
||||
folderKey,
|
||||
subFolder.Name,
|
||||
"DIR",
|
||||
GetLauncherFolderIconBitmap()));
|
||||
}
|
||||
|
||||
CollectHiddenLauncherItems(subFolder, items, seenFolders, seenApps);
|
||||
}
|
||||
|
||||
foreach (var app in folder.Apps)
|
||||
{
|
||||
var appKey = NormalizeLauncherHiddenKey(app.RelativePath);
|
||||
if (string.IsNullOrWhiteSpace(appKey) ||
|
||||
!_hiddenLauncherAppPaths.Contains(appKey) ||
|
||||
!seenApps.Add(appKey))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
items.Add(new LauncherHiddenItemView(
|
||||
LauncherEntryKind.Shortcut,
|
||||
appKey,
|
||||
app.DisplayName,
|
||||
BuildMonogram(app.DisplayName),
|
||||
GetLauncherIconBitmap(app)));
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildLauncherHiddenFallbackDisplayName(string key)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
var normalized = key.Replace('\\', '/');
|
||||
var fileName = Path.GetFileNameWithoutExtension(normalized);
|
||||
return string.IsNullOrWhiteSpace(fileName)
|
||||
? key
|
||||
: fileName;
|
||||
}
|
||||
|
||||
private Control CreateLauncherHiddenItemRow(LauncherHiddenItemView hiddenItem)
|
||||
{
|
||||
Control icon = hiddenItem.IconBitmap is not null
|
||||
? new Image
|
||||
{
|
||||
Source = hiddenItem.IconBitmap,
|
||||
Width = 24,
|
||||
Height = 24,
|
||||
Stretch = Stretch.Uniform
|
||||
}
|
||||
: new Border
|
||||
{
|
||||
Width = 24,
|
||||
Height = 24,
|
||||
CornerRadius = new CornerRadius(999),
|
||||
Background = GetThemeBrush("AdaptiveButtonBackgroundBrush"),
|
||||
Child = new TextBlock
|
||||
{
|
||||
Text = hiddenItem.Monogram,
|
||||
FontSize = 10,
|
||||
FontWeight = FontWeight.Bold,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
}
|
||||
};
|
||||
|
||||
var typeText = hiddenItem.Kind == LauncherEntryKind.Folder
|
||||
? L("settings.launcher.hidden_type_folder", "Folder")
|
||||
: L("settings.launcher.hidden_type_shortcut", "Shortcut");
|
||||
|
||||
var infoPanel = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
Spacing = 10,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch
|
||||
};
|
||||
infoPanel.Children.Add(icon);
|
||||
infoPanel.Children.Add(new StackPanel
|
||||
{
|
||||
Spacing = 2,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
Children =
|
||||
{
|
||||
new TextBlock
|
||||
{
|
||||
Text = hiddenItem.DisplayName,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
MaxLines = 1
|
||||
},
|
||||
new TextBlock
|
||||
{
|
||||
Text = typeText,
|
||||
FontSize = 11,
|
||||
Opacity = 0.7
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var restoreButton = new Button
|
||||
{
|
||||
Content = L("settings.launcher.restore_button", "Show Again"),
|
||||
MinWidth = 110,
|
||||
Padding = new Thickness(12, 6),
|
||||
Tag = new LauncherHiddenItemToken(hiddenItem.Kind, hiddenItem.Key)
|
||||
};
|
||||
restoreButton.Click += OnRestoreLauncherHiddenItemClick;
|
||||
|
||||
var row = new Grid
|
||||
{
|
||||
ColumnDefinitions = new ColumnDefinitions("*,Auto"),
|
||||
ColumnSpacing = 10
|
||||
};
|
||||
row.Children.Add(infoPanel);
|
||||
Grid.SetColumn(infoPanel, 0);
|
||||
row.Children.Add(restoreButton);
|
||||
Grid.SetColumn(restoreButton, 1);
|
||||
|
||||
return new Border
|
||||
{
|
||||
Classes = { "glass-panel" },
|
||||
BorderThickness = new Thickness(0),
|
||||
CornerRadius = new CornerRadius(14),
|
||||
Padding = new Thickness(10, 8),
|
||||
Child = row
|
||||
};
|
||||
}
|
||||
|
||||
private void OnRestoreLauncherHiddenItemClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button { Tag: LauncherHiddenItemToken token })
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var removed = token.Kind switch
|
||||
{
|
||||
LauncherEntryKind.Folder => _hiddenLauncherFolderPaths.Remove(token.Key),
|
||||
LauncherEntryKind.Shortcut => _hiddenLauncherAppPaths.Remove(token.Key),
|
||||
_ => false
|
||||
};
|
||||
|
||||
if (!removed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyLauncherVisibilitySettingsChange();
|
||||
}
|
||||
|
||||
private Bitmap? GetLauncherIconBitmap(StartMenuAppEntry app)
|
||||
{
|
||||
if (app.IconPngBytes is null || app.IconPngBytes.Length == 0)
|
||||
@@ -950,11 +1314,21 @@ public partial class MainWindow
|
||||
LauncherFolderTilePanel.Children.Clear();
|
||||
foreach (var subFolder in folder.Folders)
|
||||
{
|
||||
if (!IsLauncherFolderVisible(subFolder))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LauncherFolderTilePanel.Children.Add(CreateLauncherFolderTile(subFolder));
|
||||
}
|
||||
|
||||
foreach (var app in folder.Apps)
|
||||
{
|
||||
if (!IsLauncherAppVisible(app))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LauncherFolderTilePanel.Children.Add(CreateLauncherAppTile(app));
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ public partial class MainWindow
|
||||
SettingsNavWeatherTextBlock.Text = L("settings.nav.weather", "Weather");
|
||||
SettingsNavRegionTextBlock.Text = L("settings.nav.region", "Region");
|
||||
SettingsNavUpdateTextBlock.Text = L("settings.nav.update", "Update");
|
||||
SettingsNavLauncherTextBlock.Text = L("settings.nav.launcher", "App Launcher");
|
||||
|
||||
WallpaperPanelTitleTextBlock.Text = L("settings.wallpaper.title", "Personalize your wallpaper");
|
||||
WallpaperPlacementSettingsExpander.Header = L("settings.wallpaper.placement_label", "Placement");
|
||||
@@ -251,6 +252,16 @@ public partial class MainWindow
|
||||
|
||||
ApplyUpdateLocalization();
|
||||
|
||||
LauncherSettingsPanelTitleTextBlock.Text = L("settings.launcher.title", "App Launcher");
|
||||
LauncherHiddenItemsSettingsExpander.Header = L("settings.launcher.hidden_header", "Hidden Items");
|
||||
LauncherHiddenItemsSettingsExpander.Description = L(
|
||||
"settings.launcher.hidden_desc",
|
||||
"Review hidden launcher entries and show them again.");
|
||||
LauncherHiddenItemsDescriptionTextBlock.Text = L(
|
||||
"settings.launcher.hidden_hint",
|
||||
"Right-click an icon in launcher to hide it. Hidden entries appear here.");
|
||||
LauncherHiddenItemsEmptyTextBlock.Text = L("settings.launcher.hidden_empty", "No hidden items.");
|
||||
|
||||
SettingsNavAboutTextBlock.Text = L("settings.nav.about", "About");
|
||||
AboutPanelTitleTextBlock.Text = L("settings.about.title", "About");
|
||||
VersionTextBlock.Text = Lf(
|
||||
@@ -269,9 +280,6 @@ public partial class MainWindow
|
||||
AboutStartupSettingsExpander.Description = L(
|
||||
"settings.about.startup_desc",
|
||||
"Launch the app automatically when signing in to Windows.");
|
||||
AutoStartWithWindowsToggleSwitch.Content = L(
|
||||
"settings.about.startup_toggle",
|
||||
"Launch at Windows sign-in");
|
||||
|
||||
if (WallpaperPlacementComboBox?.ItemCount >= 5)
|
||||
{
|
||||
@@ -293,6 +301,7 @@ public partial class MainWindow
|
||||
InitializeTimeZoneSettings();
|
||||
BuildComponentLibraryCategoryPages();
|
||||
RenderLauncherRootTiles();
|
||||
RenderLauncherHiddenItemsList();
|
||||
UpdateOpenSettingsActionVisualState();
|
||||
UpdateWallpaperDisplay();
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public partial class MainWindow
|
||||
WeatherSettingsPanel is null ||
|
||||
RegionSettingsPanel is null ||
|
||||
UpdateSettingsPanel is null ||
|
||||
LauncherSettingsPanel is null ||
|
||||
AboutSettingsPanel is null)
|
||||
{
|
||||
return;
|
||||
@@ -80,6 +81,12 @@ public partial class MainWindow
|
||||
RegionSettingsPanel.IsVisible = selectedIndex == 5;
|
||||
UpdateSettingsPanel.IsVisible = selectedIndex == 6;
|
||||
AboutSettingsPanel.IsVisible = selectedIndex == 7;
|
||||
LauncherSettingsPanel.IsVisible = selectedIndex == 8;
|
||||
|
||||
if (selectedIndex == 8)
|
||||
{
|
||||
RenderLauncherHiddenItemsList();
|
||||
}
|
||||
|
||||
if (selectedIndex == 1)
|
||||
{
|
||||
@@ -877,7 +884,6 @@ public partial class MainWindow
|
||||
WeatherExcludedAlerts = _weatherExcludedAlertsRaw,
|
||||
WeatherIconPackId = _weatherIconPackId,
|
||||
WeatherNoTlsRequests = _weatherNoTlsRequests,
|
||||
DailyArtworkMirrorSource = DailyArtworkMirrorSources.Normalize(_dailyArtworkMirrorSource),
|
||||
AutoStartWithWindows = _autoStartWithWindows,
|
||||
AutoCheckUpdates = _autoCheckUpdates,
|
||||
IncludePrereleaseUpdates = IncludePrereleaseUpdates,
|
||||
@@ -891,7 +897,9 @@ public partial class MainWindow
|
||||
StatusBarCustomSpacingPercent = _statusBarCustomSpacingPercent,
|
||||
DesktopPageCount = _desktopPageCount,
|
||||
CurrentDesktopSurfaceIndex = _currentDesktopSurfaceIndex,
|
||||
DesktopComponentPlacements = _desktopComponentPlacements.ToList()
|
||||
DesktopComponentPlacements = _desktopComponentPlacements.ToList(),
|
||||
HiddenLauncherFolderPaths = _hiddenLauncherFolderPaths.OrderBy(path => path, StringComparer.OrdinalIgnoreCase).ToList(),
|
||||
HiddenLauncherAppPaths = _hiddenLauncherAppPaths.OrderBy(path => path, StringComparer.OrdinalIgnoreCase).ToList()
|
||||
};
|
||||
|
||||
_appSettingsService.Save(snapshot);
|
||||
|
||||
@@ -460,6 +460,12 @@
|
||||
<TextBlock x:Name="SettingsNavAboutTextBlock" Text="关于" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</ListBoxItem>
|
||||
<ListBoxItem x:Name="SettingsNavLauncherItem" ToolTip.Tip="应用启动台">
|
||||
<StackPanel Orientation="Horizontal" Spacing="12">
|
||||
<fi:FluentIcon x:Name="SettingsNavLauncherIcon" Icon="Apps" IconVariant="Regular" />
|
||||
<TextBlock x:Name="SettingsNavLauncherTextBlock" Text="应用启动台" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
@@ -1493,6 +1499,39 @@
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="LauncherSettingsPanel" IsVisible="False" Spacing="16">
|
||||
<TextBlock x:Name="LauncherSettingsPanelTitleTextBlock"
|
||||
FontSize="24"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
Text="App Launcher" />
|
||||
|
||||
<Border Classes="settings-expander-shell">
|
||||
<ui:SettingsExpander x:Name="LauncherHiddenItemsSettingsExpander"
|
||||
Header="Hidden Items"
|
||||
Description="Review hidden launcher entries and show them again."
|
||||
IsExpanded="True">
|
||||
<ui:SettingsExpander.Footer>
|
||||
<StackPanel Spacing="10">
|
||||
<TextBlock x:Name="LauncherHiddenItemsDescriptionTextBlock"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"
|
||||
Text="Right-click an icon in launcher to hide it. Hidden entries appear here." />
|
||||
<TextBlock x:Name="LauncherHiddenItemsEmptyTextBlock"
|
||||
IsVisible="False"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"
|
||||
Text="No hidden items." />
|
||||
<ScrollViewer MaxHeight="420"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel x:Name="LauncherHiddenItemsListPanel"
|
||||
Spacing="8" />
|
||||
</ScrollViewer>
|
||||
</StackPanel>
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="AboutSettingsPanel" IsVisible="False" Spacing="20">
|
||||
<TextBlock x:Name="AboutPanelTitleTextBlock" FontSize="24" FontWeight="SemiBold" Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" Text="About" />
|
||||
<Border Background="{DynamicResource AdaptiveSurfaceRaisedBrush}" CornerRadius="{DynamicResource DesignCornerRadiusMd}" Padding="20">
|
||||
@@ -1513,8 +1552,7 @@
|
||||
<ui:SettingsExpander.Footer>
|
||||
<ToggleSwitch x:Name="AutoStartWithWindowsToggleSwitch"
|
||||
Checked="OnAutoStartWithWindowsToggled"
|
||||
Unchecked="OnAutoStartWithWindowsToggled"
|
||||
Content="Launch at Windows sign-in" />
|
||||
Unchecked="OnAutoStartWithWindowsToggled" />
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
</Border>
|
||||
|
||||
@@ -88,6 +88,7 @@ public partial class MainWindow : Window
|
||||
}
|
||||
private readonly MonetColorService _monetColorService = new();
|
||||
private readonly AppSettingsService _appSettingsService = new();
|
||||
private readonly ComponentSettingsService _componentSettingsService = new();
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly TimeZoneService _timeZoneService = new();
|
||||
private readonly WindowsStartupService _windowsStartupService = new();
|
||||
@@ -167,7 +168,6 @@ public partial class MainWindow : Window
|
||||
private string _weatherExcludedAlertsRaw = string.Empty;
|
||||
private string _weatherIconPackId = "FluentRegular";
|
||||
private bool _weatherNoTlsRequests;
|
||||
private string _dailyArtworkMirrorSource = DailyArtworkMirrorSources.Overseas;
|
||||
private bool _autoStartWithWindows;
|
||||
private bool _suppressAutoStartToggleEvents;
|
||||
private string _weatherSearchKeyword = string.Empty;
|
||||
@@ -236,7 +236,7 @@ public partial class MainWindow : Window
|
||||
GridSizeSlider.ValueChanged += OnGridSizeSliderChanged;
|
||||
GridSizeNumberBox.ValueChanged += OnGridSizeNumberBoxChanged;
|
||||
|
||||
SettingsNavListBox.SelectedIndex = Math.Clamp(snapshot.SettingsTabIndex, 0, 7);
|
||||
SettingsNavListBox.SelectedIndex = Math.Clamp(snapshot.SettingsTabIndex, 0, 8);
|
||||
UpdateSettingsTabContent();
|
||||
|
||||
WallpaperPlacementComboBox.SelectedIndex = GetPlacementIndexFromSetting(snapshot.WallpaperPlacement);
|
||||
@@ -244,10 +244,11 @@ public partial class MainWindow : Window
|
||||
ApplyTaskbarSettings(snapshot);
|
||||
InitializeLocalization(snapshot.LanguageCode);
|
||||
InitializeWeatherSettings(snapshot);
|
||||
_dailyArtworkMirrorSource = DailyArtworkMirrorSources.Normalize(snapshot.DailyArtworkMirrorSource);
|
||||
_ = _componentSettingsService.Load();
|
||||
InitializeAutoStartWithWindowsSetting(snapshot);
|
||||
InitializeUpdateSettings(snapshot);
|
||||
InitializeDesktopSurfaceState(snapshot);
|
||||
InitializeLauncherVisibilitySettings(snapshot);
|
||||
InitializeDesktopComponentPlacements(snapshot);
|
||||
InitializeSettingsIcons();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user