• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thorstenalpers / CleanMyPosts / 15202427745

23 May 2025 04:37AM UTC coverage: 22.458% (+0.08%) from 22.379%
15202427745

push

github

thorstenalpers
Register ExceptionHandler only once in xaml

91 of 364 branches covered (25.0%)

Branch coverage included in aggregate %.

280 of 1288 relevant lines covered (21.74%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.18
/src/UI/ViewModels/SettingsViewModel.cs
1
using System.Diagnostics;
2
using CleanMyPosts.UI.Contracts.Services;
3
using CleanMyPosts.UI.Contracts.ViewModels;
4
using CleanMyPosts.UI.Helpers;
5
using CleanMyPosts.UI.Models;
6
using CommunityToolkit.Mvvm.ComponentModel;
7
using CommunityToolkit.Mvvm.Input;
8
using Microsoft.Extensions.Logging;
9

10
namespace CleanMyPosts.UI.ViewModels;
11

12
public partial class SettingsViewModel(ILogger<SettingsViewModel> logger,
1✔
13
    IUserSettingsService userSettingsService,
1✔
14
    IUpdateService updateService) : ObservableObject, INavigationAware
1✔
15
{
16
    private readonly ILogger<SettingsViewModel> _logger = logger ?? throw new ArgumentNullException(nameof(logger));
1!
17
    private readonly IUserSettingsService _userSettingsService = userSettingsService ?? throw new ArgumentNullException(nameof(userSettingsService));
1!
18
    private readonly IUpdateService _updateService = updateService ?? throw new ArgumentNullException(nameof(updateService));
1!
19

20
    [ObservableProperty]
21
    private string _versionDescription;
22

23
    [ObservableProperty]
24
    private AppTheme _theme;
25

26
    [ObservableProperty]
27
    private bool _showLogs;
28

29
    [ObservableProperty]
30
    private bool _confirmDeletion;
31

32
    [ObservableProperty]
33
    private int _waitAfterDelete;
34

35
    [ObservableProperty]
36
    private int _waitAfterDocumentLoad;
37

38
    [ObservableProperty]
39
    private int _waitBetweenRetryDeleteAttempts;
40

41
    [RelayCommand]
42
    private void SetTheme(string themeName)
43
    {
44
        if (Enum.TryParse<AppTheme>(themeName, out var theme))
1✔
45
        {
46
            _userSettingsService.SetTheme(theme);
1✔
47
        }
48
    }
1✔
49

50
    [RelayCommand]
51
    private void OpenLicense()
52
    {
53
        Process.Start(new ProcessStartInfo
×
54
        {
×
55
            FileName = "license.txt",
×
56
            UseShellExecute = true
×
57
        });
×
58
    }
×
59

60
    [RelayCommand]
61
    private void OpenHomepage()
62
    {
63
        Process.Start(new ProcessStartInfo
×
64
        {
×
65
            FileName = "https://github.com/thorstenalpers/CleanMyPosts/blob/main/THIRD_PARTY_LICENSES.txt",
×
66
            UseShellExecute = true
×
67
        });
×
68
    }
×
69

70
    [RelayCommand]
71
    private void OpenReportBug()
72
    {
73
        Process.Start(new ProcessStartInfo
×
74
        {
×
75
            FileName = "https://github.com/thorstenalpers/CleanMyPosts/issues",
×
76
            UseShellExecute = true
×
77
        });
×
78
    }
×
79

80
    [RelayCommand]
81
    private async Task CheckUpdatesAsync()
82
    {
83
        try
84
        {
85
            await _updateService.CheckForUpdatesAsync();
×
86
        }
×
87
        catch (Exception ex)
×
88
        {
89
            _logger.LogError(ex, "Check for updates failed.");
×
90
        }
×
91
    }
×
92
    partial void OnThemeChanged(AppTheme value)
93
    {
94
        _userSettingsService.SetTheme(value);
×
95
    }
×
96

97
    partial void OnShowLogsChanged(bool value)
98
    {
99
        _userSettingsService.SetShowLogs(value);
×
100
    }
×
101

102
    partial void OnConfirmDeletionChanged(bool value)
103
    {
104
        _userSettingsService.SetConfirmDeletion(value);
×
105
    }
×
106

107
    partial void OnWaitAfterDeleteChanged(int value)
108
    {
109
        _userSettingsService.SaveTimeoutSettings(new TimeoutSettings
×
110
        {
×
111
            WaitAfterDelete = WaitAfterDelete,
×
112
            WaitAfterDocumentLoad = WaitAfterDocumentLoad,
×
113
            WaitBetweenRetryDeleteAttempts = WaitBetweenRetryDeleteAttempts
×
114
        });
×
115
    }
×
116

117
    partial void OnWaitBetweenRetryDeleteAttemptsChanged(int value)
118
    {
119
        _userSettingsService.SaveTimeoutSettings(new TimeoutSettings
×
120
        {
×
121
            WaitAfterDelete = WaitAfterDelete,
×
122
            WaitAfterDocumentLoad = WaitAfterDocumentLoad,
×
123
            WaitBetweenRetryDeleteAttempts = WaitBetweenRetryDeleteAttempts
×
124
        });
×
125
    }
×
126

127
    partial void OnWaitAfterDocumentLoadChanged(int value)
128
    {
129
        _userSettingsService.SaveTimeoutSettings(new TimeoutSettings
×
130
        {
×
131
            WaitAfterDelete = WaitAfterDelete,
×
132
            WaitAfterDocumentLoad = WaitAfterDocumentLoad,
×
133
            WaitBetweenRetryDeleteAttempts = WaitBetweenRetryDeleteAttempts
×
134
        });
×
135
    }
×
136

137
    public void OnNavigatedTo(object parameter)
138
    {
139
        VersionDescription = $"{Properties.Resources.AppDisplayName} - {Helper.GetVersion()}";
×
140
        Theme = _userSettingsService.GetCurrentTheme();
×
141
        ShowLogs = _userSettingsService.GetShowLogs();
×
142
        ConfirmDeletion = _userSettingsService.GetConfirmDeletion();
×
143

144
        var timeoutSettings = _userSettingsService.GetTimeoutSettings();
×
145
        WaitAfterDocumentLoad = timeoutSettings.WaitAfterDocumentLoad;
×
146
        WaitAfterDelete = timeoutSettings.WaitAfterDelete;
×
147
        WaitBetweenRetryDeleteAttempts = timeoutSettings.WaitBetweenRetryDeleteAttempts;
×
148
    }
×
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc