From fc01ba1909ca80487be4b21fef233dee8938911e Mon Sep 17 00:00:00 2001 From: tigattack <10629864+tigattack@users.noreply.github.com> Date: Thu, 22 May 2025 19:46:01 +0100 Subject: [PATCH 1/3] chore: gitignore update notification marker --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7a8df41..c69ea4f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ ExampleData /Test-* log/*.log config/conf.json +update-notification.marker From 273eb4e3feeb6c631ce34fac1d891f166f06ca13 Mon Sep 17 00:00:00 2001 From: tigattack <10629864+tigattack@users.noreply.github.com> Date: Thu, 22 May 2025 19:46:55 +0100 Subject: [PATCH 2/3] fix(updateinfo): ensure `Message` always defined in result --- resources/UpdateInfo.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/UpdateInfo.psm1 b/resources/UpdateInfo.psm1 index cb0d32b..1ed7139 100644 --- a/resources/UpdateInfo.psm1 +++ b/resources/UpdateInfo.psm1 @@ -14,6 +14,7 @@ function Get-UpdateShouldNotify { $result = [UpdateShouldNotifyResult]@{ ShouldNotify = $true + Message = '' } # If no update is available, no need to notify From 9cd32b93cb3e20caaa0aab8997ddad2db247ca38 Mon Sep 17 00:00:00 2001 From: tigattack <10629864+tigattack@users.noreply.github.com> Date: Thu, 22 May 2025 19:48:38 +0100 Subject: [PATCH 3/3] feat(updateinfo): ignore time since last update notice if version changes --- resources/UpdateInfo.psm1 | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/resources/UpdateInfo.psm1 b/resources/UpdateInfo.psm1 index 1ed7139..4352007 100644 --- a/resources/UpdateInfo.psm1 +++ b/resources/UpdateInfo.psm1 @@ -27,27 +27,46 @@ function Get-UpdateShouldNotify { # Define marker file path $markerFilePath = "$PSScriptRoot\update-notification.marker" + $currentVersion = $UpdateStatus.CurrentVersion + # Check if marker file exists if (Test-Path $markerFilePath) { + $versionChanged = $false + $markerVersion = Get-Content -Path $markerFilePath -Raw -ErrorAction SilentlyContinue + if ($null -ne $markerVersion) { + # Trim version and compare with current version + $markerVersion = $markerVersion.Trim() + $versionChanged = $markerVersion -ne $currentVersion + } + $markerFile = Get-Item $markerFilePath $timeSinceLastNotification = (Get-Date) - $markerFile.LastWriteTime - # If less than 24 hours have passed since last notification, don't notify + # If version has changed, always notify regardless of time + if ($versionChanged) { + $result.Message = "Version changed from $markerVersion to $currentVersion since last notification. Proceeding to notify." + # Update the marker file with current version + $currentVersion | Out-File -FilePath $markerFilePath -Force -NoNewline + return $result + } + + # If less than 24 hours have passed since last notification for the same version, don't notify if ($timeSinceLastNotification.TotalHours -lt 24) { $result.ShouldNotify = $false $result.Message = "Update notification suppressed. Last notification was $($timeSinceLastNotification.TotalHours.ToString('0.00')) hours ago." - return $result } - } - - # Create or touch the marker file to indicate notification was sent - if (Test-Path $markerFilePath) { - (Get-Item $markerFilePath).LastWriteTime = Get-Date + # If more than 24 hours have passed, proceed to notify and update the marker file contents + else { + $result.Message = "Update notification marker file found. Last notification was $($timeSinceLastNotification.TotalHours.ToString('0.00')) hours ago. Proceeding to notify." + # Update the marker file with current version - Also updates the file's modtime as a side effect. + $currentVersion | Out-File -FilePath $markerFilePath -Force -NoNewline + } } else { - New-Item -Path $markerFilePath -ItemType File -Force | Out-Null - $result.Message = "Created update notification marker file at $markerFilePath" + # Create the marker file to indicate notification was sent and store current version + $currentVersion | Out-File -FilePath $markerFilePath -Force -NoNewline + $result.Message = "Created update notification marker file at $markerFilePath with version $currentVersion" } return $result