bloxstrap/Bloxstrap/UI/ViewModels/ContextMenu/ServerInformationViewModel.cs
pizzaboxer fd290f9ff7
Move activity watcher to separate process (#810)
this was done to:
- ensure robloxplayerbeta launches as an orphaned process
- help alleviate problems with multiple instances
- alleviate problems with the notifyicon causing blocking conflicts on the bootstrapper ui thread
- help reduce functional dependency on the bootstrapper, makes it less monolithic and more maintainable

ive always wanted to do this for a long while, but have always put it off because of how painful it would be

this may genuinely be the most painful refactoring i've ever had to do, but after 2 days, i managed to do it, and it works great!
2024-08-28 22:47:04 +01:00

40 lines
1.3 KiB
C#

using System.Windows;
using System.Windows.Input;
using Bloxstrap.Integrations;
using CommunityToolkit.Mvvm.Input;
namespace Bloxstrap.UI.ViewModels.ContextMenu
{
internal class ServerInformationViewModel : NotifyPropertyChangedViewModel
{
private readonly ActivityWatcher _activityWatcher;
public string InstanceId => _activityWatcher.ActivityJobId;
public string ServerType => Strings.ResourceManager.GetStringSafe($"Enums.ServerType.{_activityWatcher.ActivityServerType}");
public string ServerLocation { get; private set; } = Strings.ContextMenu_ServerInformation_Loading;
public ICommand CopyInstanceIdCommand => new RelayCommand(CopyInstanceId);
public ICommand CloseWindowCommand => new RelayCommand(RequestClose);
public EventHandler? RequestCloseEvent;
public ServerInformationViewModel(Watcher watcher)
{
_activityWatcher = watcher.ActivityWatcher!;
Task.Run(async () =>
{
ServerLocation = await _activityWatcher.GetServerLocation();
OnPropertyChanged(nameof(ServerLocation));
});
}
private void CopyInstanceId() => Clipboard.SetDataObject(InstanceId);
private void RequestClose() => RequestCloseEvent?.Invoke(this, EventArgs.Empty);
}
}