引入了托盘菜单,提供了应用启动台隐藏应用功能,优化了自动刷新功能,为STCN 24组件提供了更多信息选项。
This commit is contained in:
lincube
2026-03-06 10:32:02 +08:00
parent de40471af6
commit 72a0be16b3
29 changed files with 1752 additions and 153 deletions

View File

@@ -76,6 +76,7 @@ public partial class WeatherWidget : UserControl, IDesktopComponentWidget, IDesk
double Longitude);
private static readonly IWeatherInfoService DefaultWeatherInfoService = new XiaomiWeatherService();
private static readonly IReadOnlyList<int> SupportedAutoRefreshIntervalsMinutes = RefreshIntervalCatalog.SupportedIntervalsMinutes;
private readonly DispatcherTimer _refreshTimer = new()
{
@@ -88,6 +89,7 @@ public partial class WeatherWidget : UserControl, IDesktopComponentWidget, IDesk
};
private readonly AppSettingsService _settingsService = new();
private readonly ComponentSettingsService _componentSettingsService = new();
private readonly LocalizationService _localizationService = new();
private readonly Dictionary<WeatherVisualKind, IBrush> _backgroundBrushCache = new();
private readonly Dictionary<HyperOS3WeatherVisualKind, IBrush> _particleBrushCache = new();
@@ -109,6 +111,7 @@ public partial class WeatherWidget : UserControl, IDesktopComponentWidget, IDesk
private bool _isAttached;
private bool _isOnActivePage = true;
private bool _isRefreshing;
private bool _autoRefreshEnabled = true;
public WeatherWidget()
{
@@ -125,6 +128,7 @@ public partial class WeatherWidget : UserControl, IDesktopComponentWidget, IDesk
ApplyVisualTheme(WeatherVisualKind.ClearDay);
ApplyNotConfiguredState();
ApplyCellSize(_currentCellSize);
ApplyAutoRefreshSettings();
}
public void SetTimeZoneService(TimeZoneService timeZoneService)
@@ -154,6 +158,15 @@ public partial class WeatherWidget : UserControl, IDesktopComponentWidget, IDesk
}
}
public void RefreshFromSettings()
{
ApplyAutoRefreshSettings();
if (_isAttached && _isOnActivePage)
{
_ = RefreshWeatherAsync(forceRefresh: true);
}
}
public void SetDesktopPageContext(bool isOnActivePage, bool isEditMode)
{
_ = isEditMode;
@@ -194,6 +207,7 @@ public partial class WeatherWidget : UserControl, IDesktopComponentWidget, IDesk
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
{
_isAttached = true;
ApplyAutoRefreshSettings();
UpdateTimerState();
if (_isOnActivePage)
{
@@ -1021,10 +1035,14 @@ public partial class WeatherWidget : UserControl, IDesktopComponentWidget, IDesk
{
if (_isAttached && _isOnActivePage)
{
if (!_refreshTimer.IsEnabled)
if (_autoRefreshEnabled && !_refreshTimer.IsEnabled)
{
_refreshTimer.Start();
}
else if (!_autoRefreshEnabled && _refreshTimer.IsEnabled)
{
_refreshTimer.Stop();
}
if (!_backgroundAnimationTimer.IsEnabled)
{
@@ -1038,6 +1056,48 @@ public partial class WeatherWidget : UserControl, IDesktopComponentWidget, IDesk
_backgroundAnimationTimer.Stop();
}
private void ApplyAutoRefreshSettings()
{
var enabled = true;
var intervalMinutes = 12;
try
{
var snapshot = _componentSettingsService.Load();
enabled = snapshot.WeatherAutoRefreshEnabled;
intervalMinutes = NormalizeAutoRefreshIntervalMinutes(snapshot.WeatherAutoRefreshIntervalMinutes);
}
catch
{
// Keep fallback defaults.
}
_autoRefreshEnabled = enabled;
_refreshTimer.Interval = TimeSpan.FromMinutes(intervalMinutes);
if (_isAttached)
{
UpdateTimerState();
}
}
private static int NormalizeAutoRefreshIntervalMinutes(int minutes)
{
if (minutes <= 0)
{
return 12;
}
if (SupportedAutoRefreshIntervalsMinutes.Contains(minutes))
{
return minutes;
}
return SupportedAutoRefreshIntervalsMinutes
.OrderBy(value => Math.Abs(value - minutes))
.FirstOrDefault(12);
}
private void InitializeParticleVisuals()
{
if (_particleVisuals.Count > 0)