mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Stops running build job when UI is closed
Adds cleanup logic to the window's `Closed` event handler to properly terminate any active background build job. This prevents the build process from becoming an orphaned job if the user closes the UI while a build is in progress. The change ensures the job, its polling timer, and log streams are all stopped and disposed of correctly.
This commit is contained in:
@@ -368,6 +368,40 @@ $window.Add_SourceInitialized({
|
|||||||
|
|
||||||
# Register cleanup to reclaim memory and revert LongPathsEnabled setting when the UI window closes
|
# Register cleanup to reclaim memory and revert LongPathsEnabled setting when the UI window closes
|
||||||
$window.Add_Closed({
|
$window.Add_Closed({
|
||||||
|
# Stop any running build job if the window is closed
|
||||||
|
#DEBUG
|
||||||
|
Writelog "DEBUG CurrentBuildJob: $($script:uiState.Data.currentBuildJob)"
|
||||||
|
#END DEBUG
|
||||||
|
if ($null -ne $script:uiState.Data.currentBuildJob) {
|
||||||
|
WriteLog "UI closing, stopping background build job."
|
||||||
|
|
||||||
|
# Stop the timer
|
||||||
|
if ($null -ne $script:uiState.Data.pollTimer) {
|
||||||
|
$script:uiState.Data.pollTimer.Stop()
|
||||||
|
$script:uiState.Data.pollTimer = $null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Close the log stream
|
||||||
|
if ($null -ne $script:uiState.Data.logStreamReader) {
|
||||||
|
$script:uiState.Data.logStreamReader.Close()
|
||||||
|
$script:uiState.Data.logStreamReader.Dispose()
|
||||||
|
$script:uiState.Data.logStreamReader = $null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Stop and remove the job
|
||||||
|
$jobToStop = $script:uiState.Data.currentBuildJob
|
||||||
|
$script:uiState.Data.currentBuildJob = $null # Clear it from state first
|
||||||
|
|
||||||
|
try {
|
||||||
|
Stop-Job -Job $jobToStop
|
||||||
|
Remove-Job -Job $jobToStop
|
||||||
|
WriteLog "Background job stopped and removed."
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
WriteLog "Error stopping or removing background job: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Revert LongPathsEnabled registry setting if it was changed by this script
|
# Revert LongPathsEnabled registry setting if it was changed by this script
|
||||||
if ($script:uiState.Flags.originalLongPathsValue -ne 1) {
|
if ($script:uiState.Flags.originalLongPathsValue -ne 1) {
|
||||||
# Only revert if we changed it from something other than 1
|
# Only revert if we changed it from something other than 1
|
||||||
|
|||||||
Reference in New Issue
Block a user