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

thorstenalpers / CleanMyPosts / 15132144310

20 May 2025 08:01AM UTC coverage: 11.466% (-0.2%) from 11.636%
15132144310

push

github

thorstenalpers
Fix lint issues

17 of 278 branches covered (6.12%)

Branch coverage included in aggregate %.

0 of 41 new or added lines in 3 files covered. (0.0%)

1 existing line in 1 file now uncovered.

116 of 882 relevant lines covered (13.15%)

0.34 hits per line

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

0.0
/src/UI/ViewModels/ShellViewModel.cs
1
using System.Collections.ObjectModel;
2
using System.Windows;
3
using CleanMyPosts.UI.Contracts.Services;
4
using CleanMyPosts.UI.Properties;
5
using CommunityToolkit.Mvvm.ComponentModel;
6
using CommunityToolkit.Mvvm.Input;
7
using MahApps.Metro.Controls;
8
using MahApps.Metro.IconPacks;
9

10
namespace CleanMyPosts.UI.ViewModels;
11

12
public partial class ShellViewModel : ObservableObject, IDisposable
13
{
14
    private readonly INavigationService _navigationService;
15
    private readonly IAppSettingsService _appSettingsService;
16
    private readonly HamburgerMenuItem _logMenuItem;
17
    private bool _disposed;
18

19
    public ShellViewModel(INavigationService navigationService, IAppSettingsService appSettingsService)
×
20
    {
21
        _navigationService = navigationService;
×
22
        _appSettingsService = appSettingsService;
×
23

24
        MenuItems =
×
25
        [
×
26
            new HamburgerMenuIconItem
×
27
            {
×
28
                Label = Resources.XPage,
×
29
                Icon = new PackIconFontAwesome  { Kind = PackIconFontAwesomeKind.XTwitterBrands },
×
30
                TargetPageType = typeof(XViewModel)
×
31
            },
×
32
        ];
×
33

34
        _logMenuItem = new HamburgerMenuIconItem
×
35
        {
×
36
            Label = Resources.LogPage,
×
37
            Icon = new PackIconMaterial { Kind = PackIconMaterialKind.MathLog },
×
38
            TargetPageType = typeof(LogViewModel)
×
39
        };
×
40

41
        if (_appSettingsService.GetShowLogs())
×
42
        {
43
            MenuItems.Add(_logMenuItem);
×
44
        }
45

46
        OptionMenuItems =
×
47
        [
×
48
            new HamburgerMenuGlyphItem { Label = Resources.ShellSettingsPage, Glyph = "\uE713", TargetPageType = typeof(SettingsViewModel) }
×
49
        ];
×
50
        _appSettingsService.SettingChanged += OnAppSettingChanged;
×
51
    }
×
52
    ~ShellViewModel()
53
    {
NEW
54
        Dispose(false);
×
NEW
55
    }
×
56

57
    [ObservableProperty]
58
    private HamburgerMenuItem _selectedMenuItem;
59

60
    [ObservableProperty]
61
    private HamburgerMenuItem _selectedOptionsMenuItem;
62

63
    public ObservableCollection<HamburgerMenuItem> MenuItems { get; }
×
64
    public ObservableCollection<HamburgerMenuItem> OptionMenuItems { get; }
×
65

66
    [RelayCommand]
67
    public void OnLoaded()
68
    {
69
        _navigationService.Navigated += OnNavigated;
×
70
    }
×
71

72
    [RelayCommand]
73
    public void OnUnloaded()
74
    {
75
        _navigationService.Navigated -= OnNavigated;
×
76
    }
×
77

78
    [RelayCommand(CanExecute = nameof(CanGoBack))]
79
    private void GoBack()
80
    {
81
        _navigationService.GoBack();
×
82
    }
×
83

84
    private bool CanGoBack() => _navigationService.CanGoBack;
×
85

86
    [RelayCommand]
87
    private void MenuItemInvoked()
88
    {
89
        NavigateTo(SelectedMenuItem?.TargetPageType);
×
90
    }
×
91

92
    [RelayCommand]
93
    private void OptionsMenuItemInvoked()
94
    {
95
        NavigateTo(SelectedOptionsMenuItem?.TargetPageType);
×
96
    }
×
97

98
    private void NavigateTo(Type targetViewModel)
99
    {
100
        if (targetViewModel != null)
×
101
        {
102
            _navigationService.NavigateTo(targetViewModel.FullName);
×
103
        }
104
    }
×
105

106
    private void OnNavigated(object sender, string viewModelName)
107
    {
108
        SelectedMenuItem = MenuItems.FirstOrDefault(i => viewModelName == i.TargetPageType?.FullName);
×
109
        if (SelectedMenuItem == null)
×
110
        {
111
            SelectedOptionsMenuItem = OptionMenuItems.FirstOrDefault(i => viewModelName == i.TargetPageType?.FullName);
×
112
        }
113
        GoBackCommand.NotifyCanExecuteChanged();
×
114
    }
×
115

116
    private void OnAppSettingChanged(object sender, string key)
117
    {
118
        if (key == "ShowLogs")
×
119
        {
120
            Application.Current.Dispatcher.Invoke(() =>
×
121
            {
×
122
                if (_appSettingsService.GetShowLogs())
×
123
                {
×
124
                    if (!MenuItems.Contains(_logMenuItem))
×
125
                    {
×
126
                        MenuItems.Insert(1, _logMenuItem!);
×
127
                    }
×
128
                }
×
129
                else
×
130
                {
×
131
                    MenuItems.Remove(_logMenuItem!);
×
132
                }
×
133
            });
×
134
        }
135
    }
×
136
    public void Dispose()
137
    {
NEW
138
        Dispose(true);
×
139
        GC.SuppressFinalize(this);
×
140
    }
×
141
    protected virtual void Dispose(bool disposing)
142
    {
NEW
143
        if (_disposed)
×
144
        {
NEW
145
            return;
×
146
        }
147

NEW
148
        if (disposing)
×
149
        {
NEW
150
            _appSettingsService.SettingChanged -= OnAppSettingChanged;
×
NEW
151
            _navigationService.Navigated -= OnNavigated;
×
152
        }
153

NEW
154
        _disposed = true;
×
NEW
155
    }
×
156
}
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