Skip to content

Commit 3db22a6

Browse files
feat: CommunityToolkit.Mvvm
1 parent 677b902 commit 3db22a6

File tree

6 files changed

+19
-45
lines changed

6 files changed

+19
-45
lines changed

src/[ApplicationNameUpperCamelCase]/ViewModels/MainWindowViewModel.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,24 @@
1212
using ReactiveUI;
1313

1414
using ApplicationNameUpperCamelCase.Models;
15+
using CommunityToolkit.Mvvm.ComponentModel;
1516

1617
namespace ApplicationNameUpperCamelCase.ViewModels;
1718

1819
/// <summary>
1920
/// The view model for the main UI.
2021
/// </summary>
21-
public class MainWindowViewModel : ViewModelBase {
22+
public partial class MainWindowViewModel : ViewModelBase {
2223
/// <summary>
2324
/// True if the application is updating, false otherwise.
2425
/// </summary>
26+
[ObservableProperty]
2527
private bool _isUpdating;
28+
2629
/// <summary>
2730
/// Initializes a new instance of the <see cref="MainWindowViewModel" /> class.
2831
/// </summary>
2932
public MainWindowViewModel() {
3033
_isUpdating = Environment.GetCommandLineArgs().ToList().Contains("--update");
3134
}
32-
/// <summary>
33-
/// True if the application is updating, false otherwise.
34-
/// </summary>
35-
public bool IsUpdating {
36-
get => _isUpdating;
37-
set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
38-
}
3935
}

src/[ApplicationNameUpperCamelCase]/ViewModels/NewVersionWindowViewModel.cs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
using ApplicationNameUpperCamelCase.Views;
55
using Avalonia.Controls;
66
using Avalonia.Threading;
7-
7+
using CommunityToolkit.Mvvm.ComponentModel;
8+
using CommunityToolkit.Mvvm.Input;
89
using Nullinside.Api.Common.Desktop;
910

1011
using ReactiveUI;
@@ -14,10 +15,11 @@ namespace ApplicationNameUpperCamelCase.ViewModels;
1415
/// <summary>
1516
/// The view model for the <seealso cref="NewVersionWindow" /> class.
1617
/// </summary>
17-
public class NewVersionWindowViewModel : ViewModelBase {
18+
public partial class NewVersionWindowViewModel : ViewModelBase {
1819
/// <summary>
1920
/// True if updating the application currently, false otherwise.
2021
/// </summary>
22+
[ObservableProperty]
2123
private bool _isUpdating;
2224

2325
/// <summary>
@@ -33,15 +35,13 @@ public class NewVersionWindowViewModel : ViewModelBase {
3335
/// <summary>
3436
/// The version of the application on the GitHub server.
3537
/// </summary>
38+
[ObservableProperty]
3639
private string? _serverVersion;
3740

3841
/// <summary>
3942
/// Initializes a new instance of the <see cref="NewVersionWindowViewModel" /> class.
4043
/// </summary>
4144
public NewVersionWindowViewModel() {
42-
UpdateSoftware = ReactiveCommand.Create(StartUpdateSoftware);
43-
CloseWindow = ReactiveCommand.Create<Window>(CloseWindowCommand);
44-
4545
Task.Factory.StartNew(async () => {
4646
GithubLatestReleaseJson? version =
4747
await GitHubUpdateManager.GetLatestVersion("nullinside-development-group", "ApplicationNameUpperCamelCase").ConfigureAwait(false);
@@ -63,43 +63,19 @@ public string? LocalVersion {
6363
set => _localVersion = value;
6464
}
6565

66-
/// <summary>
67-
/// The version of the software on the GitHub server.
68-
/// </summary>
69-
public string? ServerVersion {
70-
get => _serverVersion;
71-
set => this.RaiseAndSetIfChanged(ref _serverVersion, value);
72-
}
73-
74-
/// <summary>
75-
/// True if updating the application currently, false otherwise.
76-
/// </summary>
77-
public bool IsUpdating {
78-
get => _isUpdating;
79-
set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
80-
}
81-
82-
/// <summary>
83-
/// A command to update the software.
84-
/// </summary>
85-
public ICommand UpdateSoftware { get; }
86-
87-
/// <summary>
88-
/// A command to close the current window.
89-
/// </summary>
90-
public ICommand CloseWindow { get; }
91-
9266
/// <summary>
9367
/// A command to close the current window.
9468
/// </summary>
9569
/// <param name="self">The reference to our own window.</param>
96-
private void CloseWindowCommand(Window self) {
70+
[RelayCommand]
71+
private void CloseWindow(Window self) {
9772
self.Close();
9873
}
9974

10075
/// <summary>
10176
/// Launches the web browser at the new release page.
10277
/// </summary>
78+
[RelayCommand]
10379
private void StartUpdateSoftware() {
10480
IsUpdating = true;
10581
GitHubUpdateManager.PrepareUpdate()
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using ReactiveUI;
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using ReactiveUI;
23

34
namespace ApplicationNameUpperCamelCase.ViewModels;
45

56
/// <summary>
67
/// A base class for all view models.
78
/// </summary>
8-
public class ViewModelBase : ReactiveObject { }
9+
public class ViewModelBase : ObservableObject { }

src/[ApplicationNameUpperCamelCase]/Views/MainWindow.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected override void OnInitialized() {
4444

4545
var args = Environment.GetCommandLineArgs().ToList();
4646
if (args.Contains("--update")) {
47-
_ = GitHubUpdateManager.PerformUpdateAndRestart("nullinside-development-group", "ApplicationNameUpperCamelCase", args[2], "windows-x64.zip");
47+
_ = GitHubUpdateManager.PerformUpdateAndRestart("nullinside-development-group", "ApplicationNameUpperCamelCase", args[2].Trim('"').Trim(), "windows-x64.zip");
4848
return;
4949
}
5050

src/[ApplicationNameUpperCamelCase]/Views/NewVersionWindow.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<TextBlock Text="{Binding ServerVersion}" HorizontalAlignment="Center" VerticalAlignment="Center" />
3636
</StackPanel>
3737
<StackPanel Orientation="Horizontal">
38-
<Button Command="{Binding UpdateSoftware}" Margin="0 10 0 0">Install New Version</Button>
39-
<Button Command="{Binding CloseWindow}" CommandParameter="{Binding ElementName=Window}"
38+
<Button Command="{Binding StartUpdateSoftwareCommand}" Margin="0 10 0 0">Install New Version</Button>
39+
<Button Command="{Binding CloseWindowCommand}" CommandParameter="{Binding ElementName=Window}"
4040
Margin="10 10 0 0">
4141
Close
4242
</Button>

src/[ApplicationNameUpperCamelCase]/[ApplicationNameUpperCamelCase].csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
3535
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10"/>
3636
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.6" />
37+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
3738
</ItemGroup>
3839

3940
<ItemGroup>

0 commit comments

Comments
 (0)