RobloxActivity -> Integrations.ActivityWatcher

This commit is contained in:
pizzaboxer 2023-07-25 19:39:31 +01:00
parent 8065e5be98
commit 83856acaec
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
9 changed files with 26 additions and 22 deletions

View File

@ -236,7 +236,7 @@ namespace Bloxstrap
} }
List<Process> autocloseProcesses = new(); List<Process> autocloseProcesses = new();
RobloxActivity? activityWatcher = null; ActivityWatcher? activityWatcher = null;
DiscordRichPresence? richPresence = null; DiscordRichPresence? richPresence = null;
App.Logger.WriteLine(LOG_IDENT, $"Started Roblox (PID {gameClientPid})"); App.Logger.WriteLine(LOG_IDENT, $"Started Roblox (PID {gameClientPid})");

View File

@ -5,7 +5,7 @@ namespace Bloxstrap.Integrations
public class DiscordRichPresence : IDisposable public class DiscordRichPresence : IDisposable
{ {
private readonly DiscordRpcClient _rpcClient = new("1005469189907173486"); private readonly DiscordRpcClient _rpcClient = new("1005469189907173486");
private readonly RobloxActivity _activityWatcher; private readonly ActivityWatcher _activityWatcher;
private RichPresence? _currentPresence; private RichPresence? _currentPresence;
private bool _visible = true; private bool _visible = true;
@ -13,7 +13,7 @@ namespace Bloxstrap.Integrations
private long _currentUniverseId; private long _currentUniverseId;
private DateTime? _timeStartedUniverse; private DateTime? _timeStartedUniverse;
public DiscordRichPresence(RobloxActivity activityWatcher) public DiscordRichPresence(ActivityWatcher activityWatcher)
{ {
const string LOG_IDENT = "DiscordRichPresence::<construct>"; const string LOG_IDENT = "DiscordRichPresence::<construct>";

View File

@ -1,6 +1,6 @@
namespace Bloxstrap namespace Bloxstrap.Integrations
{ {
public class RobloxActivity : IDisposable public class ActivityWatcher : IDisposable
{ {
// i'm thinking the functionality for parsing roblox logs could be broadened for more features than just rich presence, // i'm thinking the functionality for parsing roblox logs could be broadened for more features than just rich presence,
// like checking the ping and region of the current connected server. maybe that's something to add? // like checking the ping and region of the current connected server. maybe that's something to add?
@ -44,7 +44,7 @@
public async void StartWatcher() public async void StartWatcher()
{ {
const string LOG_IDENT = "RobloxActivity::StartWatcher"; const string LOG_IDENT = "ActivityWatcher::StartWatcher";
// okay, here's the process: // okay, here's the process:
// //
@ -118,7 +118,7 @@
private void ExamineLogEntry(string entry) private void ExamineLogEntry(string entry)
{ {
const string LOG_IDENT = "RobloxActivity::ExamineLogEntry"; const string LOG_IDENT = "ActivityWatcher::ExamineLogEntry";
OnLogEntry?.Invoke(this, entry); OnLogEntry?.Invoke(this, entry);
@ -253,7 +253,7 @@
return; return;
} }
if (String.IsNullOrEmpty(message.Command)) if (string.IsNullOrEmpty(message.Command))
{ {
App.Logger.WriteLine(LOG_IDENT, "Failed to parse message! (Command is empty)"); App.Logger.WriteLine(LOG_IDENT, "Failed to parse message! (Command is empty)");
return; return;
@ -266,7 +266,7 @@
public async Task<string> GetServerLocation() public async Task<string> GetServerLocation()
{ {
const string LOG_IDENT = "RobloxActivity::GetServerLocation"; const string LOG_IDENT = "ActivityWatcher::GetServerLocation";
if (GeolcationCache.ContainsKey(ActivityMachineAddress)) if (GeolcationCache.ContainsKey(ActivityMachineAddress))
return GeolcationCache[ActivityMachineAddress]; return GeolcationCache[ActivityMachineAddress];
@ -291,7 +291,7 @@
locationRegion = locationRegion.ReplaceLineEndings(""); locationRegion = locationRegion.ReplaceLineEndings("");
locationCountry = locationCountry.ReplaceLineEndings(""); locationCountry = locationCountry.ReplaceLineEndings("");
if (String.IsNullOrEmpty(locationCountry)) if (string.IsNullOrEmpty(locationCountry))
location = "N/A"; location = "N/A";
else if (locationCity == locationRegion) else if (locationCity == locationRegion)
location = $"{locationRegion}, {locationCountry}"; location = $"{locationRegion}, {locationCountry}";

View File

@ -1,6 +1,7 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Bloxstrap.Integrations;
using Bloxstrap.UI.ViewModels.ContextMenu; using Bloxstrap.UI.ViewModels.ContextMenu;
namespace Bloxstrap.UI.Elements.ContextMenu namespace Bloxstrap.UI.Elements.ContextMenu
@ -12,7 +13,7 @@ namespace Bloxstrap.UI.Elements.ContextMenu
{ {
private bool _autoscroll = true; private bool _autoscroll = true;
public LogTracer(RobloxActivity activityWatcher) public LogTracer(ActivityWatcher activityWatcher)
{ {
DataContext = new LogTracerViewModel(this, activityWatcher); DataContext = new LogTracerViewModel(this, activityWatcher);
InitializeComponent(); InitializeComponent();

View File

@ -24,13 +24,13 @@ namespace Bloxstrap.UI.Elements.ContextMenu
{ {
// i wouldve gladly done this as mvvm but turns out that data binding just does not work with menuitems for some reason so idk this sucks // i wouldve gladly done this as mvvm but turns out that data binding just does not work with menuitems for some reason so idk this sucks
private readonly RobloxActivity? _activityWatcher; private readonly ActivityWatcher? _activityWatcher;
private readonly DiscordRichPresence? _richPresenceHandler; private readonly DiscordRichPresence? _richPresenceHandler;
private LogTracer? _logTracerWindow; private LogTracer? _logTracerWindow;
private ServerInformation? _serverInformationWindow; private ServerInformation? _serverInformationWindow;
public MenuContainer(RobloxActivity? activityWatcher, DiscordRichPresence? richPresenceHandler) public MenuContainer(ActivityWatcher? activityWatcher, DiscordRichPresence? richPresenceHandler)
{ {
InitializeComponent(); InitializeComponent();

View File

@ -12,6 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using Bloxstrap.Integrations;
using Bloxstrap.UI.ViewModels.ContextMenu; using Bloxstrap.UI.ViewModels.ContextMenu;
namespace Bloxstrap.UI.Elements.ContextMenu namespace Bloxstrap.UI.Elements.ContextMenu
@ -21,7 +22,7 @@ namespace Bloxstrap.UI.Elements.ContextMenu
/// </summary> /// </summary>
public partial class ServerInformation public partial class ServerInformation
{ {
public ServerInformation(RobloxActivity activityWatcher) public ServerInformation(ActivityWatcher activityWatcher)
{ {
DataContext = new ServerInformationViewModel(this, activityWatcher); DataContext = new ServerInformationViewModel(this, activityWatcher);
InitializeComponent(); InitializeComponent();

View File

@ -14,7 +14,7 @@ namespace Bloxstrap.UI
private readonly System.Windows.Forms.NotifyIcon _notifyIcon; private readonly System.Windows.Forms.NotifyIcon _notifyIcon;
private MenuContainer? _menuContainer; private MenuContainer? _menuContainer;
private RobloxActivity? _activityWatcher; private ActivityWatcher? _activityWatcher;
private DiscordRichPresence? _richPresenceHandler; private DiscordRichPresence? _richPresenceHandler;
EventHandler? _alertClickHandler; EventHandler? _alertClickHandler;
@ -42,7 +42,7 @@ namespace Bloxstrap.UI
_richPresenceHandler = richPresenceHandler; _richPresenceHandler = richPresenceHandler;
} }
public void SetActivityWatcher(RobloxActivity activityWatcher) public void SetActivityWatcher(ActivityWatcher activityWatcher)
{ {
if (_activityWatcher is not null) if (_activityWatcher is not null)
return; return;

View File

@ -3,12 +3,14 @@ using System.Windows.Input;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using Bloxstrap.Integrations;
namespace Bloxstrap.UI.ViewModels.ContextMenu namespace Bloxstrap.UI.ViewModels.ContextMenu
{ {
internal class LogTracerViewModel : NotifyPropertyChangedViewModel internal class LogTracerViewModel : NotifyPropertyChangedViewModel
{ {
private readonly Window _window; private readonly Window _window;
private readonly RobloxActivity _activityWatcher; private readonly ActivityWatcher _activityWatcher;
private int _lineNumber = 1; private int _lineNumber = 1;
public ICommand CloseWindowCommand => new RelayCommand(_window.Close); public ICommand CloseWindowCommand => new RelayCommand(_window.Close);
@ -17,7 +19,7 @@ namespace Bloxstrap.UI.ViewModels.ContextMenu
public string LogFilename => Path.GetFileName(_activityWatcher.LogLocation); public string LogFilename => Path.GetFileName(_activityWatcher.LogLocation);
public string LogContents { get; private set; } = ""; public string LogContents { get; private set; } = "";
public LogTracerViewModel(Window window, RobloxActivity activityWatcher) public LogTracerViewModel(Window window, ActivityWatcher activityWatcher)
{ {
_window = window; _window = window;
_activityWatcher = activityWatcher; _activityWatcher = activityWatcher;

View File

@ -1,6 +1,6 @@
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using Bloxstrap.Integrations;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
namespace Bloxstrap.UI.ViewModels.ContextMenu namespace Bloxstrap.UI.ViewModels.ContextMenu
@ -8,7 +8,7 @@ namespace Bloxstrap.UI.ViewModels.ContextMenu
internal class ServerInformationViewModel : NotifyPropertyChangedViewModel internal class ServerInformationViewModel : NotifyPropertyChangedViewModel
{ {
private readonly Window _window; private readonly Window _window;
private readonly RobloxActivity _activityWatcher; private readonly ActivityWatcher _activityWatcher;
public string InstanceId => _activityWatcher.ActivityJobId; public string InstanceId => _activityWatcher.ActivityJobId;
public string ServerType => $"{_activityWatcher.ActivityServerType} server"; public string ServerType => $"{_activityWatcher.ActivityServerType} server";
@ -18,7 +18,7 @@ namespace Bloxstrap.UI.ViewModels.ContextMenu
public ICommand CopyInstanceIdCommand => new RelayCommand(CopyInstanceId); public ICommand CopyInstanceIdCommand => new RelayCommand(CopyInstanceId);
public ICommand CloseWindowCommand => new RelayCommand(_window.Close); public ICommand CloseWindowCommand => new RelayCommand(_window.Close);
public ServerInformationViewModel(Window window, RobloxActivity activityWatcher) public ServerInformationViewModel(Window window, ActivityWatcher activityWatcher)
{ {
_window = window; _window = window;
_activityWatcher = activityWatcher; _activityWatcher = activityWatcher;