mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-18 16:41:36 -07:00
Make activity tracking an independent option
also moved server location info logic to the activity handler itself as i plan to also use it in an informational window accessible from the context menu
This commit is contained in:
parent
5f9f63d18e
commit
ce1c2bc88f
@ -247,7 +247,7 @@ namespace Bloxstrap
|
||||
return;
|
||||
}
|
||||
|
||||
if (App.Settings.Prop.UseDiscordRichPresence || App.Settings.Prop.ShowServerDetails)
|
||||
if (App.Settings.Prop.EnableActivityTracking)
|
||||
{
|
||||
activityWatcher = new();
|
||||
shouldWait = true;
|
||||
|
@ -20,6 +20,7 @@ namespace Bloxstrap.Models
|
||||
public ChannelChangeMode ChannelChangeMode { get; set; } = ChannelChangeMode.Automatic;
|
||||
|
||||
// integration configuration
|
||||
public bool EnableActivityTracking { get; set; } = true;
|
||||
public bool UseDiscordRichPresence { get; set; } = true;
|
||||
public bool HideRPCButtons { get; set; } = true;
|
||||
public bool ShowServerDetails { get; set; } = false;
|
||||
|
@ -21,6 +21,8 @@
|
||||
public event EventHandler? OnGameLeave;
|
||||
public event EventHandler<GameMessage>? OnGameMessage;
|
||||
|
||||
private Dictionary<string, string> GeolcationCache = new();
|
||||
|
||||
// these are values to use assuming the player isn't currently in a game
|
||||
// keep in mind ActivityIsTeleport is only reset by DiscordRichPresence when it's done accessing it
|
||||
// because of the weird chronology of where the teleporting entry is outputted, there's no way to reset it in here
|
||||
@ -213,9 +215,37 @@
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> GetServerLocation()
|
||||
{
|
||||
if (GeolcationCache.ContainsKey(ActivityMachineAddress))
|
||||
return GeolcationCache[ActivityMachineAddress];
|
||||
|
||||
string location = "";
|
||||
|
||||
string locationCity = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/city");
|
||||
string locationRegion = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/region");
|
||||
string locationCountry = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/country");
|
||||
|
||||
locationCity = locationCity.ReplaceLineEndings("");
|
||||
locationRegion = locationRegion.ReplaceLineEndings("");
|
||||
locationCountry = locationCountry.ReplaceLineEndings("");
|
||||
|
||||
if (String.IsNullOrEmpty(locationCountry))
|
||||
location = "N/A";
|
||||
else if (locationCity == locationRegion)
|
||||
location = $"{locationRegion}, {locationCountry}";
|
||||
else
|
||||
location = $"{locationCity}, {locationRegion}, {locationCountry}";
|
||||
|
||||
GeolcationCache[ActivityMachineAddress] = location;
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
IsDisposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,33 @@
|
||||
<StackPanel Margin="0,0,14,14">
|
||||
<TextBlock Text="Configure quick and easy ways to improve the Roblox gameplay experience." FontSize="14" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
|
||||
|
||||
<TextBlock Text="Discord Rich Presence" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
|
||||
<TextBlock Text="Roblox activity tracking" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
|
||||
<ui:CardControl Margin="0,8,0,0">
|
||||
<ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
<TextBlock FontSize="14" Text="Enable activity tracking" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Allows for Bloxstrap to detect what Roblox game you're playing. Certain features may require this." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch x:Name="ActivityTrackingEnabledToggle" IsChecked="{Binding ActivityTrackingEnabled, Mode=TwoWay}" />
|
||||
</ui:CardControl>
|
||||
<ui:CardControl Margin="0,8,0,0" IsEnabled="{Binding IsChecked, ElementName=ActivityTrackingEnabledToggle, Mode=OneWay}">
|
||||
<ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
<TextBlock FontSize="14" Text="Know where your server's located" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="When you join a game, you'll be notified of the server's location. Won't show in fullscreen." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch IsChecked="{Binding ShowServerDetailsEnabled, Mode=TwoWay}" />
|
||||
</ui:CardControl>
|
||||
|
||||
<TextBlock Text="Discord Rich Presence" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
|
||||
<TextBlock Margin="0,4,0,0" Text="This feature requires activity tracking to be enabled." TextWrapping="Wrap" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
|
||||
<ui:CardControl Margin="0,8,0,0" IsEnabled="{Binding IsChecked, ElementName=ActivityTrackingEnabledToggle, Mode=OneWay}">
|
||||
<ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
<TextBlock FontSize="14" Text="Show game activity" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="The game you're playing on Roblox will show on your Discord activity." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="When playing a Roblox game, the game you're playing will show on your Discord profile activity." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch x:Name="DiscordActivityEnabledToggle" IsChecked="{Binding DiscordActivityEnabled, Mode=TwoWay}" />
|
||||
@ -26,7 +47,7 @@
|
||||
<ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
<TextBlock FontSize="14" Text="Allow activity joining" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="When enabled, anyone can join your game through your Discord activity." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Allows for anybody to join the game you're currently in through your Discord profile." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch IsChecked="{Binding DiscordActivityJoinEnabled, Mode=TwoWay}" />
|
||||
@ -36,17 +57,8 @@
|
||||
<ui:CardControl Margin="0,8,0,0">
|
||||
<ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
<TextBlock FontSize="14" Text="Be notified of server details on game join" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Lets you see location and Job ID of current server. These will not show when in fullscreen." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch IsChecked="{Binding ShowServerDetailsEnabled, Mode=TwoWay}" />
|
||||
</ui:CardControl>
|
||||
<ui:CardControl Margin="0,8,0,0">
|
||||
<ui:CardControl.Header>
|
||||
<StackPanel>
|
||||
<TextBlock FontSize="14" Text="Allow multi-game instance launching" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Roblox will allow having more than one game instance open simultaneously." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
<TextBlock FontSize="14" Text="Allow multi-instance launching" />
|
||||
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Allows for having more than one Roblox game client instance open simultaneously." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch IsChecked="{Binding MultiInstanceLaunchingEnabled, Mode=TwoWay}" />
|
||||
|
@ -46,35 +46,12 @@ namespace Bloxstrap.UI
|
||||
|
||||
public async void OnGameJoin()
|
||||
{
|
||||
if (!App.Settings.Prop.ShowServerDetails)
|
||||
return;
|
||||
|
||||
App.Logger.WriteLine($"[NotifyIconWrapper::OnActivityGameJoin] Getting game/server information");
|
||||
|
||||
string machineAddress = _activityWatcher!.ActivityMachineAddress;
|
||||
string machineLocation = "";
|
||||
|
||||
// basically nobody has a free public access geolocation api that's accurate,
|
||||
// the ones that do require an api key which isn't suitable for a client-side application like this
|
||||
// so, hopefully this is reliable enough?
|
||||
string locationCity = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{machineAddress}/city");
|
||||
string locationRegion = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{machineAddress}/region");
|
||||
string locationCountry = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{machineAddress}/country");
|
||||
|
||||
locationCity = locationCity.ReplaceLineEndings("");
|
||||
locationRegion = locationRegion.ReplaceLineEndings("");
|
||||
locationCountry = locationCountry.ReplaceLineEndings("");
|
||||
|
||||
if (String.IsNullOrEmpty(locationCountry))
|
||||
machineLocation = "N/A";
|
||||
else if (locationCity == locationRegion)
|
||||
machineLocation = $"{locationRegion}, {locationCountry}";
|
||||
else
|
||||
machineLocation = $"{locationCity}, {locationRegion}, {locationCountry}";
|
||||
|
||||
string serverLocation = await _activityWatcher!.GetServerLocation();
|
||||
|
||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.ServerDetailsMenuItem.Visibility = Visibility.Visible);
|
||||
|
||||
ShowAlert("Connnected to server", $"Location: {machineLocation}\nClick to copy Instance ID", 10, (_, _) => System.Windows.Clipboard.SetText(_activityWatcher.ActivityJobId));
|
||||
if (App.Settings.Prop.ShowServerDetails)
|
||||
ShowAlert("Connnected to server", $"Location: {serverLocation}", 10, (_, _) => Clipboard.SetText(_activityWatcher.ActivityJobId));
|
||||
}
|
||||
|
||||
public void OnGameLeave(object? sender, EventArgs e)
|
||||
|
@ -39,6 +39,32 @@ namespace Bloxstrap.UI.ViewModels.Menu
|
||||
OnPropertyChanged(nameof(IsCustomIntegrationSelected));
|
||||
}
|
||||
|
||||
public bool ActivityTrackingEnabled
|
||||
{
|
||||
get => App.Settings.Prop.EnableActivityTracking;
|
||||
set
|
||||
{
|
||||
App.Settings.Prop.EnableActivityTracking = value;
|
||||
|
||||
if (!value)
|
||||
{
|
||||
ShowServerDetailsEnabled = value;
|
||||
DiscordActivityEnabled = value;
|
||||
DiscordActivityJoinEnabled = value;
|
||||
|
||||
OnPropertyChanged(nameof(ShowServerDetailsEnabled));
|
||||
OnPropertyChanged(nameof(DiscordActivityEnabled));
|
||||
OnPropertyChanged(nameof(DiscordActivityJoinEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowServerDetailsEnabled
|
||||
{
|
||||
get => App.Settings.Prop.ShowServerDetails;
|
||||
set => App.Settings.Prop.ShowServerDetails = value;
|
||||
}
|
||||
|
||||
public bool DiscordActivityEnabled
|
||||
{
|
||||
get => App.Settings.Prop.UseDiscordRichPresence;
|
||||
@ -60,12 +86,6 @@ namespace Bloxstrap.UI.ViewModels.Menu
|
||||
set => App.Settings.Prop.HideRPCButtons = !value;
|
||||
}
|
||||
|
||||
public bool ShowServerDetailsEnabled
|
||||
{
|
||||
get => App.Settings.Prop.ShowServerDetails;
|
||||
set => App.Settings.Prop.ShowServerDetails = value;
|
||||
}
|
||||
|
||||
public bool MultiInstanceLaunchingEnabled
|
||||
{
|
||||
get => App.Settings.Prop.MultiInstanceLaunching;
|
||||
|
Loading…
Reference in New Issue
Block a user