Repository navigation
Expand file tree
/
Copy pathSidebarViewModel.cs
More file actions
109 lines (88 loc) · 4.62 KB
/
Copy pathSidebarViewModel.cs
File metadata and controls
109 lines (88 loc) · 4.62 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using UniGetUI.Avalonia.Infrastructure;
using UniGetUI.Avalonia.Views;
using UniGetUI.Core.Data;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
namespace UniGetUI.Avalonia.ViewModels;
public partial class SidebarViewModel : ViewModelBase
{
// ─── Badge properties ─────────────────────────────────────────────────────
[ObservableProperty]
private int _updatesBadgeCount;
[ObservableProperty]
private bool _updatesBadgeVisible;
[ObservableProperty]
private bool _bundlesBadgeVisible;
// When the count changes, sync the badge visibility
partial void OnUpdatesBadgeCountChanged(int value) =>
UpdatesBadgeVisible = value > 0;
partial void OnUpdatesBadgeVisibleChanged(bool value)
{
OnPropertyChanged(nameof(UpdatesBadgeExpandedVisible));
OnPropertyChanged(nameof(UpdatesBadgeCompactVisible));
}
partial void OnBundlesBadgeVisibleChanged(bool value)
{
OnPropertyChanged(nameof(BundlesBadgeExpandedVisible));
OnPropertyChanged(nameof(BundlesBadgeCompactVisible));
}
// ─── Loading indicators ───────────────────────────────────────────────────
[ObservableProperty]
private bool _discoverIsLoading;
[ObservableProperty]
private bool _updatesIsLoading;
[ObservableProperty]
private bool _installedIsLoading;
// ─── Pane open/closed ─────────────────────────────────────────────────────
// Starts collapsed: the pane is a floating overlay in every size class (see MainWindow's
// adaptive logic), so there is no persistent open-on-launch state.
[ObservableProperty]
private bool isPaneOpen;
// Only persist the open/closed choice as the "collapse on wide screen" preference
// while the pane is inline (Expanded mode). In the overlay modes used on smaller
// windows, opening/closing is transient and must not overwrite the saved preference.
// The MainWindow's adaptive logic keeps this in sync with the SplitView display mode.
public bool PersistPaneCollapsePreference { get; set; } = true;
partial void OnIsPaneOpenChanged(bool value)
{
if (PersistPaneCollapsePreference)
Settings.Set(Settings.K.CollapseNavMenuOnWideScreen, !value);
OnPropertyChanged(nameof(UpdatesBadgeExpandedVisible));
OnPropertyChanged(nameof(UpdatesBadgeCompactVisible));
OnPropertyChanged(nameof(BundlesBadgeExpandedVisible));
OnPropertyChanged(nameof(BundlesBadgeCompactVisible));
}
public bool UpdatesBadgeExpandedVisible => UpdatesBadgeVisible && IsPaneOpen;
public bool UpdatesBadgeCompactVisible => UpdatesBadgeVisible && !IsPaneOpen;
public bool BundlesBadgeExpandedVisible => BundlesBadgeVisible && IsPaneOpen;
public bool BundlesBadgeCompactVisible => BundlesBadgeVisible && !IsPaneOpen;
// ─── Selected page ────────────────────────────────────────────────────────
[ObservableProperty]
private PageType _selectedPageType = PageType.Null;
// ─── Navigation ──────────────────────────────────────────────────────────
public event EventHandler<PageType>? NavigationRequested;
public string VersionLabel { get; } =
CoreTools.Translate("UniGetUI Version {0} by Devolutions", CoreData.VersionName);
[RelayCommand]
public void RequestNavigation(string? pageName)
{
if (Enum.TryParse<PageType>(pageName, out var page))
NavigationRequested?.Invoke(this, page);
}
[RelayCommand]
private static Task CheckForUpdates() =>
AvaloniaAutoUpdater.CheckAndInstallUpdatesAsync(autoLaunch: false, manualCheck: true);
public void SelectNavButtonForPage(PageType page) =>
SelectedPageType = page;
public void SetNavItemLoading(PageType page, bool isLoading)
{
switch (page)
{
case PageType.Discover: DiscoverIsLoading = isLoading; break;
case PageType.Updates: UpdatesIsLoading = isLoading; break;
case PageType.Installed: InstalledIsLoading = isLoading; break;
}
}
}