| Name | Message | Date |
|---|---|---|
| 📄 DateTimePanelViewModel.cs | 1 month ago | |
| 📄 ServiceCollectionExtensions.cs | 1 month ago | |
| 📄 SmhiPanelViewModel.cs | 1 month ago | |
| 📄 VasttrafikPanelViewModel.cs | 1 month ago |
📄
src/App/ViewModels/Panels/SmhiPanelViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System; using System.Threading; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.Extensions.DependencyInjection; using MMirror.Integrations.Smhi; namespace MMirror.App.ViewModels.Panels; public partial class SmhiPanelViewModel(TimeProvider timeProvider, SmhiClient smhiClient) : ViewModelBase { private readonly TimeProvider timeProvider = timeProvider; private readonly SmhiClient smhiClient = smhiClient; private CancellationTokenSource cts = new(); [ObservableProperty] public partial PointForecast? Forecast { get; private set; } [ObservableProperty] public required partial string LocationName { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } public void SubscribeToUpdates() { Task.Run(() => FetchLoop(cts.Token)); } private async Task FetchLoop(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { Forecast = await smhiClient.GetPointForecast(Longitude, Latitude, cancellationToken); await Task.Delay(TimeSpan.FromMinutes(15), timeProvider, cancellationToken); } } public void UnsubscribeFromUpdates() { cts.Cancel(); cts = new(); } } internal static class SmhiPanelViewModelServiceCollectionExtensions { extension(IServiceCollection services) { public IServiceCollection AddSmhiPanelViewModel() { services.AddTransient<SmhiPanelViewModel>(); return services; } } }