Fixed issue where powershell script may stay running even after closing app by making it stop itself if gui app is no longer running.

This commit is contained in:
BubbaGumpShrump 2024-12-08 20:22:01 -05:00
parent 1b3c00d563
commit e52166ccbf
2 changed files with 10 additions and 4 deletions

View file

@ -259,7 +259,7 @@ namespace AutoTrackR2
(Color)ColorConverter.ConvertFromString("#FFFFFF"), // Text
(Color)ColorConverter.ConvertFromString("#CFFF04") // AltText
);
ChangeLogo("/Assets/AVSQN.png", (Color)ColorConverter.ConvertFromString("#3fbcff"));
ChangeLogo("/Assets/HEX.png", (Color)ColorConverter.ConvertFromString("#39FF14"));
break;
}
}

View file

@ -20,6 +20,8 @@ if (Test-Path $configFile) {
exit
}
$parentApp = (Get-Process -Name AutoTrackR2).ID
# Access config values
$logFilePath = $config.Logfile
$apiUrl = $config.ApiUrl
@ -102,7 +104,7 @@ $global:killTally = 0
# Load historic kills from csv
if (Test-Path "$scriptFolder\Kill-Log.csv") {
$historicKills = Import-CSV "$scriptFolder\Kill-log.csv" | Sort-Object Descending
$historicKills = Import-CSV "$scriptFolder\Kill-log.csv" | Sort-Object -Property KillTime
foreach ($kill in $historicKills) {
Write-Output "NewKill=throwaway,$($kill.EnemyPilot),$($kill.EnemyShip),$($kill.OrgAffiliation),$($kill.Enlisted),$($kill.RecordNumber),$($kill.KillTime),$($kill.PFP)"
$global:killTally++
@ -186,7 +188,11 @@ function Read-LogEntry {
}
If ($null -ne $page1){
# Check if the Autotrackr2 process is running
if ($null -eq (Get-Process -ID $parentApp -ErrorAction SilentlyContinue)) {
Stop-Process -Id $PID -Force
}
If ($enemyShip -eq $global:lastKill){
$enemyShip = "Passenger"
} Else {
@ -299,7 +305,7 @@ function Read-LogEntry {
try {
# Send the POST request with JSON data
Invoke-RestMethod -Uri $apiURL -Method Post -Body ($data | ConvertTo-Json -Depth 5) -Headers $headers
$null = Invoke-RestMethod -Uri $apiURL -Method Post -Body ($data | ConvertTo-Json -Depth 5) -Headers $headers
$logMode = "API"
} catch {
# Catch and display errors