diff --git a/src/SiteMonitor/Program.cs b/src/SiteMonitor/Program.cs
index 27f6431..bccb1c6 100644
--- a/src/SiteMonitor/Program.cs
+++ b/src/SiteMonitor/Program.cs
@@ -14,7 +14,7 @@ internal sealed class Program {
/// The logger.
///
private static readonly ILog LOG = LogManager.GetLogger(typeof(Program));
-
+
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
@@ -25,13 +25,13 @@ public static void Main(string[] args) {
#else
XmlConfigurator.Configure(new FileInfo("log4net.config"));
#endif
-
+
LOG.Info("Started application");
AppDomain.CurrentDomain.UnhandledException += (_, exceptArgs) => {
LOG.Fatal("Unhandled exception", exceptArgs.ExceptionObject as Exception);
};
-
+
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
diff --git a/src/SiteMonitor/SiteMonitor.csproj b/src/SiteMonitor/SiteMonitor.csproj
index e302719..2071164 100644
--- a/src/SiteMonitor/SiteMonitor.csproj
+++ b/src/SiteMonitor/SiteMonitor.csproj
@@ -26,13 +26,14 @@
-
-
-
-
+
+
+
+
-
+
+
@@ -40,13 +41,13 @@
-
-
- PreserveNewest
-
-
-
- PreserveNewest
-
+
+
+ PreserveNewest
+
+
+
+ PreserveNewest
+
diff --git a/src/SiteMonitor/ViewModels/MainWindowViewModel.cs b/src/SiteMonitor/ViewModels/MainWindowViewModel.cs
index 2b9e4ef..b32ffa7 100644
--- a/src/SiteMonitor/ViewModels/MainWindowViewModel.cs
+++ b/src/SiteMonitor/ViewModels/MainWindowViewModel.cs
@@ -5,11 +5,11 @@
using System.Net.NetworkInformation;
using System.Threading;
using System.Threading.Tasks;
-using System.Windows.Input;
using Avalonia.Controls;
-using ReactiveUI;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
using Renci.SshNet;
@@ -20,26 +20,32 @@ namespace SiteMonitor.ViewModels;
///
/// The view model for the main UI.
///
-public class MainWindowViewModel : ViewModelBase {
- private bool _apiUp = true;
- private string? _chatTimestamp;
- private bool _isDisplayingAdvancedCommands;
- private bool _isMinimized;
- private bool _nullUp = true;
+public partial class MainWindowViewModel : ViewModelBase {
+ [ObservableProperty] private bool _apiUp = true;
+
+ [ObservableProperty] private string? _chatTimestamp;
+
+ [ObservableProperty] private bool _isDisplayingAdvancedCommands;
+
+ [ObservableProperty] private bool _isMinimized;
+
+ [ObservableProperty] private bool _nullUp = true;
+
private string? _serverAddress;
- private bool _serverUp = true;
+
+ [ObservableProperty] private bool _serverUp = true;
+
private string? _sshPassword;
private string? _sshUsername;
- private bool _websiteUp = true;
+
+ [ObservableProperty] private bool _websiteUp = true;
+
private WindowState _windowState;
///
/// Initializes a new instance of the class.
///
public MainWindowViewModel() {
- OnShowCommandsCommand = ReactiveCommand.Create(OnShowCommands);
- OnRestartCommand = ReactiveCommand.Create(OnRestart);
- OnRestartImagesCommand = ReactiveCommand.Create(OnRestartImages);
Task.Factory.StartNew(PingServer);
Task.Factory.StartNew(PingSite);
ServerAddress = Configuration.Instance.ServerAddress;
@@ -53,7 +59,7 @@ public MainWindowViewModel() {
public string? ServerAddress {
get => _serverAddress;
set {
- this.RaiseAndSetIfChanged(ref _serverAddress, value);
+ SetProperty(ref _serverAddress, value);
try {
Configuration.Instance.ServerAddress = value;
@@ -63,78 +69,17 @@ public string? ServerAddress {
}
}
- ///
- /// The timestamp of the last chat message that was received.
- ///
- public string? ChatTimestamp {
- get => _chatTimestamp;
- set => this.RaiseAndSetIfChanged(ref _chatTimestamp, value);
- }
-
- ///
- /// True if the server is online.
- ///
- public bool ServerUp {
- get => _serverUp;
- set => this.RaiseAndSetIfChanged(ref _serverUp, value);
- }
-
- ///
- /// True if the website is returning a 200.
- ///
- public bool WebsiteUp {
- get => _websiteUp;
- set => this.RaiseAndSetIfChanged(ref _websiteUp, value);
- }
-
- ///
- /// True if the API is online.
- ///
- public bool ApiUp {
- get => _apiUp;
- set => this.RaiseAndSetIfChanged(ref _apiUp, value);
- }
-
- ///
- /// True if the null API is online.
- ///
- public bool NullUp {
- get => _nullUp;
- set => this.RaiseAndSetIfChanged(ref _nullUp, value);
- }
-
///
/// Sets the window to normal, minimized, maximized, etc.
///
public WindowState WindowState {
get => _windowState;
set {
- this.RaiseAndSetIfChanged(ref _windowState, value);
+ SetProperty(ref _windowState, value);
IsMinimized = _windowState == WindowState.Minimized;
}
}
- ///
- /// True if the application is minimized, false otherwise.
- ///
- public bool IsMinimized {
- get => _isMinimized;
- set => this.RaiseAndSetIfChanged(ref _isMinimized, value);
- }
-
- ///
- /// Shows the commands in the UI.
- ///
- public ICommand OnShowCommandsCommand { get; set; }
-
- ///
- /// True if displaying advanced commands, false otherwise.
- ///
- public bool IsDisplayingAdvancedCommands {
- get => _isDisplayingAdvancedCommands;
- set => this.RaiseAndSetIfChanged(ref _isDisplayingAdvancedCommands, value);
- }
-
///
/// The username to use for the SSH session for commands.
///
@@ -142,7 +87,7 @@ public string? SshUsername {
get => _sshUsername;
set {
Configuration.Instance.ServerUsername = value;
- this.RaiseAndSetIfChanged(ref _sshUsername, value);
+ SetProperty(ref _sshUsername, value);
try {
Configuration.WriteConfiguration();
}
@@ -157,7 +102,7 @@ public string? SshPassword {
get => _sshPassword;
set {
Configuration.Instance.ServerPassword = value;
- this.RaiseAndSetIfChanged(ref _sshPassword, value);
+ SetProperty(ref _sshPassword, value);
try {
Configuration.WriteConfiguration();
}
@@ -168,16 +113,7 @@ public string? SshPassword {
///
/// Restarts the remote machine.
///
- public ICommand OnRestartCommand { get; set; }
-
- ///
- /// Restarts the remote docker images.
- ///
- public ICommand OnRestartImagesCommand { get; set; }
-
- ///
- /// Restarts the remote machine.
- ///
+ [RelayCommand]
private async Task OnRestart() {
using SshClient client = new(_serverAddress!, _sshUsername!, _sshPassword!);
await client.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
@@ -188,6 +124,7 @@ private async Task OnRestart() {
///
/// Restarts the docker images.
///
+ [RelayCommand]
private async Task OnRestartImages() {
await Task.Run(async () => {
using SshClient client = new(_serverAddress!, _sshUsername!, _sshPassword!);
@@ -208,6 +145,7 @@ await Task.Run(async () => {
///
/// Handles showing the server commands.
///
+ [RelayCommand]
private void OnShowCommands() {
IsDisplayingAdvancedCommands = true;
}
diff --git a/src/SiteMonitor/ViewModels/NewVersionWindowViewModel.cs b/src/SiteMonitor/ViewModels/NewVersionWindowViewModel.cs
index 4d3d249..591aa9e 100644
--- a/src/SiteMonitor/ViewModels/NewVersionWindowViewModel.cs
+++ b/src/SiteMonitor/ViewModels/NewVersionWindowViewModel.cs
@@ -5,6 +5,8 @@
using Avalonia.Controls;
using Avalonia.Threading;
+using CommunityToolkit.Mvvm.ComponentModel;
+
using Nullinside.Api.Common.Desktop;
using ReactiveUI;
@@ -16,11 +18,11 @@ namespace SiteMonitor.ViewModels;
///
/// The view model for the class.
///
-public class NewVersionWindowViewModel : ViewModelBase {
+public partial class NewVersionWindowViewModel : ViewModelBase {
///
/// True if updating the application currently, false otherwise.
///
- private bool _isUpdating;
+ [ObservableProperty] private bool _isUpdating;
///
/// The local version of the software.
@@ -35,7 +37,7 @@ public class NewVersionWindowViewModel : ViewModelBase {
///
/// The version of the application on the GitHub server.
///
- private string? _serverVersion;
+ [ObservableProperty] private string? _serverVersion;
///
/// Initializes a new instance of the class.
@@ -66,22 +68,6 @@ public string? LocalVersion {
set => _localVersion = value;
}
- ///
- /// The version of the software on the GitHub server.
- ///
- public string? ServerVersion {
- get => _serverVersion;
- set => this.RaiseAndSetIfChanged(ref _serverVersion, value);
- }
-
- ///
- /// True if updating the application currently, false otherwise.
- ///
- public bool IsUpdating {
- get => _isUpdating;
- set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
- }
-
///
/// A command to update the software.
///
diff --git a/src/SiteMonitor/ViewModels/ViewModelBase.cs b/src/SiteMonitor/ViewModels/ViewModelBase.cs
index e93814f..a381ac5 100644
--- a/src/SiteMonitor/ViewModels/ViewModelBase.cs
+++ b/src/SiteMonitor/ViewModels/ViewModelBase.cs
@@ -1,9 +1,9 @@
-using ReactiveUI;
+using CommunityToolkit.Mvvm.ComponentModel;
namespace SiteMonitor.ViewModels;
///
/// A base class for all view models.
///
-public class ViewModelBase : ReactiveObject {
+public class ViewModelBase : ObservableObject {
}
\ No newline at end of file
diff --git a/src/SiteMonitor/Views/MainWindow.axaml b/src/SiteMonitor/Views/MainWindow.axaml
index 61154e9..7f117be 100644
--- a/src/SiteMonitor/Views/MainWindow.axaml
+++ b/src/SiteMonitor/Views/MainWindow.axaml
@@ -44,7 +44,7 @@
@@ -81,11 +81,11 @@
diff --git a/src/SiteMonitor/Views/MainWindow.axaml.cs b/src/SiteMonitor/Views/MainWindow.axaml.cs
index a53b802..1782211 100644
--- a/src/SiteMonitor/Views/MainWindow.axaml.cs
+++ b/src/SiteMonitor/Views/MainWindow.axaml.cs
@@ -1,3 +1,10 @@
+#if !DEBUG
+using Avalonia.Threading;
+
+using SiteMonitor.ViewModels;
+#else
+using Avalonia;
+#endif
using System;
using System.Linq;
using System.Threading.Tasks;
@@ -8,14 +15,6 @@
using Microsoft.Extensions.DependencyInjection;
using Nullinside.Api.Common.Desktop;
-#if !DEBUG
-using Avalonia.Threading;
-
-using SiteMonitor.ViewModels;
-
-#else
-using Avalonia;
-#endif
namespace SiteMonitor.Views;