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

thorstenalpers / CleanMyPosts / 15190007218

22 May 2025 02:59PM UTC coverage: 21.288% (-1.1%) from 22.394%
15190007218

push

github

thorstenalpers
Use spinner for int instead of textbox

84 of 364 branches covered (23.08%)

Branch coverage included in aggregate %.

263 of 1266 relevant lines covered (20.77%)

0.61 hits per line

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

19.72
/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 async Task CheckUpdatesAsync()
72
    {
73
        try
74
        {
75
            await _updateService.CheckForUpdatesAsync();
×
76
        }
×
77
        catch (Exception ex)
×
78
        {
79
            _logger.LogError(ex, "Check for updates failed.");
×
80
        }
×
81
    }
×
82
    partial void OnThemeChanged(AppTheme value)
83
    {
84
        _userSettingsService.SetTheme(value);
×
85
    }
×
86

87
    partial void OnShowLogsChanged(bool value)
88
    {
89
        _userSettingsService.SetShowLogs(value);
×
90
    }
×
91

92
    partial void OnConfirmDeletionChanged(bool value)
93
    {
94
        _userSettingsService.SetConfirmDeletion(value);
×
95
    }
×
96

97
    partial void OnWaitAfterDeleteChanged(int value)
98
    {
99
        _userSettingsService.SaveTimeoutSettings(new TimeoutSettings
×
100
        {
×
101
            WaitAfterDelete = WaitAfterDelete,
×
102
            WaitAfterDocumentLoad = WaitAfterDocumentLoad,
×
103
            WaitBetweenRetryDeleteAttempts = WaitBetweenRetryDeleteAttempts
×
104
        });
×
105
    }
×
106

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

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

127
    public void OnNavigatedTo(object parameter)
128
    {
129
        VersionDescription = $"{Properties.Resources.AppDisplayName} - {Helper.GetVersion()}";
×
130
        Theme = _userSettingsService.GetCurrentTheme();
×
131
        ShowLogs = _userSettingsService.GetShowLogs();
×
132
        ConfirmDeletion = _userSettingsService.GetConfirmDeletion();
×
133

134
        var timeoutSettings = _userSettingsService.GetTimeoutSettings();
×
135
        WaitAfterDocumentLoad = timeoutSettings.WaitAfterDocumentLoad;
×
136
        WaitAfterDelete = timeoutSettings.WaitAfterDelete;
×
137
        WaitBetweenRetryDeleteAttempts = timeoutSettings.WaitBetweenRetryDeleteAttempts;
×
138
    }
×
139
}
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