diff --git a/Events.ps1 b/Events.ps1 index 1b8dbad..67ec26f 100644 --- a/Events.ps1 +++ b/Events.ps1 @@ -67,36 +67,30 @@ function OnStreamStart() { function OnStreamEnd($kwargs) { Write-Debug "Starting OnStreamEnd function" + try { # Check if the primary monitor is not active - Write-Debug "Checking if the primary monitor is active" - if (-not (IsPrimaryMonitorActive)) { - Write-Debug "Primary monitor is not active, attempting to set primary screen" - # Attempt to set the primary screen if it is not already set. - SetPrimaryScreen - } + Write-Debug "Now attempting to restore the primary monitor" + SetPrimaryScreen - # Check again if the primary monitor is not active after the first attempt to set it. - Write-Debug "Re-checking if the primary monitor is active" - if (-not (IsPrimaryMonitorActive)) { + if ((IsPrimaryMonitorActive)) { + # Primary monitor is active, return true. + Write-Host "Primary monitor(s) have been successfully restored!" + Write-Debug "Primary monitor is active, returning true" + return $true + + } + else { Write-Debug "Primary monitor failed to be restored, this is most likely because the display is currently not available." if (($script:attempts++ -eq 1) -or ($script:attempts % 120 -eq 0)) { # Output a message to the host indicating difficulty in restoring the display. # This message is shown once initially, and then once every 10 minutes. - Write-Host "Failed to restore display(s), some displays require multiple attempts and may not restore until returning back to the computer. Trying again after 5 seconds... (this message will be suppressed to only show up once every 10 minutes)" + Write-Host "Failed to restore display(s), some displays require multiple attempts and may not restore until returning back to the computer. Trying again after 5 seconds... (this message will be suppressed to only show up once every 10-15 minutes)" } # Return false indicating the primary monitor is still not active. - # If we reached here, that indicates the first two attempts had failed. - Write-Debug "Returning false as primary monitor is still not active after two attempts" return $false } - else { - # Primary monitor is active, return true. - Write-Host "Primary monitor(s) have been successfully restored!" - Write-Debug "Primary monitor is active, returning true" - return $true - } } catch { Write-Debug "Caught an exception, expected in cases like when the user has a TV as a primary display" diff --git a/Readme.md b/Readme.md index 73d4906..39b6392 100644 --- a/Readme.md +++ b/Readme.md @@ -113,6 +113,9 @@ This tool automatically switches your main display to a dummy plug (or any virtu ## Change Log +**v2.0.2** +- More bug fixes that prevented primary monitor from restoring after a stream was ended. + **v2.0.1** - Fixed a bug that prevented the primary monitor from restoring after ending a stream. @@ -130,8 +133,4 @@ This tool automatically switches your main display to a dummy plug (or any virtu - Added debug logging. - Fixed monitor flicker issue related to known workarounds. -**v1.1.7 & v1.1.6** -- Various fixes for file handling, profile restoration, and logging. -- Integrated updates from the SunshineScript Installer template. - --- \ No newline at end of file