Skip to content

Commit

Permalink
Fix custom integration autoclosing not working
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Aug 29, 2024
1 parent 9fd4c36 commit 719fbb8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 43 deletions.
11 changes: 1 addition & 10 deletions Bloxstrap/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,6 @@ Selecting 'No' will ignore this warning and continue installation.</value>
<data name="Menu.Integrations.Custom.AppLocation" xml:space="preserve">
<value>Application Location</value>
</data>
<data name="Menu.Integrations.Custom.AppLocation.Placeholder" xml:space="preserve">
<value>e.g. C:\Windows\System32\cmd.exe</value>
</data>
<data name="Menu.Integrations.Custom.AutoClose" xml:space="preserve">
<value>Auto close when Roblox closes</value>
</data>
Expand All @@ -740,7 +737,7 @@ Selecting 'No' will ignore this warning and continue installation.</value>
<value>Launch Arguments</value>
</data>
<data name="Menu.Integrations.Custom.LaunchArgs.Placeholder" xml:space="preserve">
<value>e.g. /k echo Roblox is running!</value>
<value>Roblox is running!</value>
</data>
<data name="Menu.Integrations.Custom.NewIntegration" xml:space="preserve">
<value>New Integration</value>
Expand Down
4 changes: 2 additions & 2 deletions Bloxstrap/UI/Elements/Settings/Pages/IntegrationsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@
<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:TextBox Grid.Column="0" Margin="0,0,0,0" PlaceholderText="C:\Windows\System32\cmd.exe" 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}" TextWrapping="Wrap" AcceptsReturn="True" AcceptsTab="True" />
<ui:TextBox Margin="0,4,0,0" PlaceholderText="{Binding Source='/k echo {0}', Converter={StaticResource StringFormatConverter}, ConverterParameter={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
47 changes: 20 additions & 27 deletions Bloxstrap/Watcher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Bloxstrap.Integrations;
using System.CodeDom;
using System.Security.Permissions;

namespace Bloxstrap
{
Expand Down Expand Up @@ -54,7 +52,7 @@ public Watcher()

if (split.Length >= 2)
{
foreach (string strPid in split[0].Split(';'))
foreach (string strPid in split[1].Split(','))
{
if (int.TryParse(strPid, out int pid) && pid != 0)
_autoclosePids.Add(pid);
Expand Down Expand Up @@ -86,38 +84,33 @@ public Watcher()
_notifyIcon = new(this);
}

public void KillRobloxProcess() => KillProcess(_gameClientPid);
public void KillRobloxProcess() => CloseProcess(_gameClientPid, true);

public void KillProcess(int pid)
public void CloseProcess(int pid, bool force = false)
{
using var process = Process.GetProcessById(pid);

App.Logger.WriteLine("Watcher::KillProcess", $"Killing process '{process.ProcessName}' (PID {process.Id})");

if (process.HasExited)
const string LOG_IDENT = "Watcher::CloseProcess";
try
{
App.Logger.WriteLine("Watcher::KillProcess", $"PID {process.Id} has already exited");
return;
}
using var process = Process.GetProcessById(pid);

process.Kill();
process.Close();
}

public void CloseProcess(int pid)
{
using var process = Process.GetProcessById(pid);
App.Logger.WriteLine(LOG_IDENT, $"Killing process '{process.ProcessName}' (pid={pid}, force={force})");

App.Logger.WriteLine("Watcher::CloseProcess", $"Closing process '{process.ProcessName}' (PID {process.Id})");
if (process.HasExited)
{
App.Logger.WriteLine(LOG_IDENT, $"PID {pid} has already exited");
return;
}

if (process.HasExited)
if (force)
process.Kill();
else
process.CloseMainWindow();
}
catch (Exception ex)
{
App.Logger.WriteLine("Watcher::CloseProcess", $"PID {process.Id} has already exited");
return;
App.Logger.WriteLine(LOG_IDENT, $"PID {pid} could not be closed");
App.Logger.WriteException(LOG_IDENT, ex);
}

process.CloseMainWindow();
process.Close();
}

public async Task Run()
Expand Down

0 comments on commit 719fbb8

Please sign in to comment.