Skip to content

Commit

Permalink
Custom integration improvements
Browse files Browse the repository at this point in the history
ShellExecute, working directory setting, file picker, easier command line flag input
  • Loading branch information
pizzaboxer committed Jul 2, 2024
1 parent 48da60d commit 2a7d894
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
14 changes: 10 additions & 4 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private async Task StartRoblox()
gameClientPid = gameClient.Id;
}

List<Process> autocloseProcesses = new();
List<Process?> autocloseProcesses = new();
ActivityWatcher? activityWatcher = null;
DiscordRichPresence? richPresence = null;

Expand Down Expand Up @@ -379,7 +379,13 @@ private async Task StartRoblox()

try
{
Process process = Process.Start(integration.Location, integration.LaunchArgs);
var process = Process.Start(new ProcessStartInfo
{
FileName = integration.Location,
Arguments = integration.LaunchArgs.Replace("\r\n", " "),
WorkingDirectory = Path.GetDirectoryName(integration.Location),
UseShellExecute = true
});

if (integration.AutoClose)
{
Expand Down Expand Up @@ -413,9 +419,9 @@ private async Task StartRoblox()

richPresence?.Dispose();

foreach (Process process in autocloseProcesses)
foreach (var process in autocloseProcesses)
{
if (process.HasExited)
if (process is null || process.HasExited)
continue;

App.Logger.WriteLine(LOG_IDENT, $"Autoclosing process '{process.ProcessName}' (PID {process.Id})");
Expand Down
11 changes: 9 additions & 2 deletions Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,16 @@
<TextBlock Text="{x:Static resources:Strings.Common_Name}" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<ui:TextBox Margin="0,4,0,0" Text="{Binding SelectedCustomIntegration.Name}" />
<TextBlock Margin="0,8,0,0" Text="{x:Static resources:Strings.Menu_Integrations_Custom_AppLocation}" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<ui:TextBox Margin="0,4,0,0" PlaceholderText="{x:Static resources:Strings.Menu_Integrations_Custom_AppLocation_Placeholder}" Text="{Binding SelectedCustomIntegration.Location}" />
<Grid Margin="0,4,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBox Grid.Column="0" Margin="0,0,0,0" PlaceholderText="{x:Static resources:Strings.Menu_Integrations_Custom_AppLocation_Placeholder}" Text="{Binding SelectedCustomIntegration.Location}" />
<ui:Button Grid.Column="1" Margin="8,0,0,0" Height="34" Icon="Folder24" Content="{x:Static resources:Strings.Common_Browse}" Command="{Binding BrowseIntegrationLocationCommand}" />
</Grid>
<TextBlock Margin="0,8,0,0" Text="{x:Static resources:Strings.Menu_Integrations_Custom_LaunchArgs}" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<ui:TextBox Margin="0,4,0,0" PlaceholderText="{x:Static resources:Strings.Menu_Integrations_Custom_LaunchArgs_Placeholder}" Text="{Binding SelectedCustomIntegration.LaunchArgs}" />
<ui:TextBox Margin="0,4,0,0" PlaceholderText="{x:Static resources:Strings.Menu_Integrations_Custom_LaunchArgs_Placeholder}" Text="{Binding SelectedCustomIntegration.LaunchArgs}" TextWrapping="Wrap" AcceptsReturn="True" AcceptsTab="True" />
<CheckBox Margin="0,8,0,0" Content="{x:Static resources:Strings.Menu_Integrations_Custom_AutoClose}" IsChecked="{Binding SelectedCustomIntegration.AutoClose}" />
</StackPanel>
<TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Text="{x:Static resources:Strings.Menu_Integrations_Custom_NoneSelected}" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center">
Expand Down
22 changes: 22 additions & 0 deletions Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Collections.ObjectModel;
using System.Windows.Input;

using Bloxstrap.Resources;

using Microsoft.Win32;

using CommunityToolkit.Mvvm.Input;

namespace Bloxstrap.UI.ViewModels.Menu
Expand All @@ -9,6 +13,7 @@ public class IntegrationsViewModel : NotifyPropertyChangedViewModel
{
public ICommand AddIntegrationCommand => new RelayCommand(AddIntegration);
public ICommand DeleteIntegrationCommand => new RelayCommand(DeleteIntegration);
public ICommand BrowseIntegrationLocationCommand => new RelayCommand(BrowseIntegrationLocation);

private void AddIntegration()
{
Expand Down Expand Up @@ -39,6 +44,23 @@ private void DeleteIntegration()
OnPropertyChanged(nameof(IsCustomIntegrationSelected));
}

private void BrowseIntegrationLocation()
{
if (SelectedCustomIntegration is null)
return;

var dialog = new OpenFileDialog
{
Filter = $"{Strings.Menu_AllFiles}|*.*"
};

if (dialog.ShowDialog() != true)
return;

SelectedCustomIntegration.Location = dialog.FileName;
OnPropertyChanged(nameof(SelectedCustomIntegration));
}

public bool ActivityTrackingEnabled
{
get => App.Settings.Prop.EnableActivityTracking;
Expand Down

0 comments on commit 2a7d894

Please sign in to comment.