Custom integration improvements

ShellExecute, working directory setting, file picker, easier command line flag input
This commit is contained in:
pizzaboxer 2024-07-02 23:27:40 +04:00
parent 48da60d7ab
commit 2a7d894319
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
3 changed files with 41 additions and 6 deletions

View File

@ -336,7 +336,7 @@ namespace Bloxstrap
gameClientPid = gameClient.Id;
}
List<Process> autocloseProcesses = new();
List<Process?> autocloseProcesses = new();
ActivityWatcher? activityWatcher = null;
DiscordRichPresence? richPresence = null;
@ -379,7 +379,13 @@ namespace Bloxstrap
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)
{
@ -413,9 +419,9 @@ namespace Bloxstrap
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})");

View File

@ -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">

View File

@ -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
@ -9,6 +13,7 @@ namespace Bloxstrap.UI.ViewModels.Menu
{
public ICommand AddIntegrationCommand => new RelayCommand(AddIntegration);
public ICommand DeleteIntegrationCommand => new RelayCommand(DeleteIntegration);
public ICommand BrowseIntegrationLocationCommand => new RelayCommand(BrowseIntegrationLocation);
private void AddIntegration()
{
@ -39,6 +44,23 @@ namespace Bloxstrap.UI.ViewModels.Menu
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;