Fixed the Notification errors
This commit is contained in:
@@ -93,17 +93,7 @@ try {
|
||||
|
||||
# --- Notify user that the replay was saved ---
|
||||
$notifyScript = Join-Path $PSScriptRoot 'Show-Notification.ps1'
|
||||
Start-Process -FilePath 'powershell.exe' -ArgumentList @(
|
||||
'-STA'
|
||||
'-ExecutionPolicy', 'Bypass'
|
||||
'-NonInteractive'
|
||||
'-WindowStyle', 'Hidden'
|
||||
'-File', $notifyScript
|
||||
'-Type', 'ReplaySaved'
|
||||
'-ContactNumber', $config.ITContactNumber
|
||||
'-FileName', $savedFile.Name
|
||||
'-FileSizeMB', $fileSizeMB
|
||||
) -WindowStyle Hidden
|
||||
Start-Process -FilePath 'powershell.exe' -ArgumentList "-STA -ExecutionPolicy Bypass -NonInteractive -WindowStyle Hidden -File `"$notifyScript`" -Type ReplaySaved -ContactNumber `"$($config.ITContactNumber)`" -FileName `"$($savedFile.Name)`" -FileSizeMB $fileSizeMB" -WindowStyle Hidden
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] User notification launched."
|
||||
|
||||
return $true
|
||||
|
||||
@@ -20,21 +20,40 @@ param(
|
||||
[double]$FileSizeMB = 0
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
Add-Type -AssemblyName PresentationFramework
|
||||
Add-Type -AssemblyName WindowsBase
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
|
||||
Add-Type -TypeDefinition @"
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
public class GdiHelper {
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern bool DeleteObject(IntPtr hObject);
|
||||
}
|
||||
"@
|
||||
|
||||
$hBitmap = [System.Drawing.SystemIcons]::Shield.ToBitmap().GetHbitmap()
|
||||
$wpfImage = [System.Windows.Interop.Imaging]::CreateBitmapSourceFromHBitmap(
|
||||
$wpfShield = [System.Windows.Interop.Imaging]::CreateBitmapSourceFromHBitmap(
|
||||
$hBitmap, [IntPtr]::Zero, [System.Windows.Int32Rect]::Empty,
|
||||
[System.Windows.Media.Imaging.BitmapSizeOptions]::FromEmptyOptions()
|
||||
)
|
||||
[System.Runtime.InteropServices.Marshal]::DeleteObject($hBitmap)
|
||||
[GdiHelper]::DeleteObject($hBitmap) | Out-Null
|
||||
|
||||
$hBitmap = [System.Drawing.SystemIcons]::Warning.ToBitmap().GetHbitmap()
|
||||
$wpfWarning = [System.Windows.Interop.Imaging]::CreateBitmapSourceFromHBitmap(
|
||||
$hBitmap, [IntPtr]::Zero, [System.Windows.Int32Rect]::Empty,
|
||||
[System.Windows.Media.Imaging.BitmapSizeOptions]::FromEmptyOptions()
|
||||
)
|
||||
[GdiHelper]::DeleteObject($hBitmap) | Out-Null
|
||||
|
||||
if ($Type -eq 'BufferStarted') {
|
||||
[xml]$xaml = @"
|
||||
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
Title="IT Screen Recorder" Height="320" Width="440"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="IT Screen Recorder" SizeToContent="Height" Width="440"
|
||||
WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
|
||||
Topmost="True" ShowInTaskbar="False">
|
||||
<Grid Margin="20">
|
||||
@@ -69,8 +88,8 @@ if ($Type -eq 'BufferStarted') {
|
||||
$txtContact = $window.FindName('TxtContact')
|
||||
$btnOK = $window.FindName('BtnOK')
|
||||
|
||||
$imgHeader.Source = $wpfImage
|
||||
$imgTray.Source = $wpfImage
|
||||
$imgHeader.Source = $wpfWarning
|
||||
$imgTray.Source = $wpfShield
|
||||
$txtContact.Text = "Questions? Contact IT at $ContactNumber"
|
||||
|
||||
$txtBody.Inlines.Add("Your screen is being recorded into a rolling $BufferMinutes-minute replay buffer. Nothing is saved until you request it.`n`nTo save a clip, ")
|
||||
@@ -86,7 +105,8 @@ if ($Type -eq 'BufferStarted') {
|
||||
} else {
|
||||
[xml]$xaml = @"
|
||||
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
Title="IT Screen Recorder" Height="260" Width="440"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="IT Screen Recorder" SizeToContent="Height" Width="440"
|
||||
WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
|
||||
Topmost="True" ShowInTaskbar="False">
|
||||
<Grid Margin="20">
|
||||
@@ -113,7 +133,7 @@ if ($Type -eq 'BufferStarted') {
|
||||
$txtContact = $window.FindName('TxtContact')
|
||||
$btnOK = $window.FindName('BtnOK')
|
||||
|
||||
$imgHeader.Source = $wpfImage
|
||||
$imgHeader.Source = $wpfShield
|
||||
$txtContact.Text = "Questions? Contact IT at $ContactNumber"
|
||||
|
||||
$txtBody.Inlines.Add("Your replay has been saved ($FileSizeMB MB):`n")
|
||||
@@ -124,18 +144,19 @@ if ($Type -eq 'BufferStarted') {
|
||||
}
|
||||
|
||||
# Countdown timer — auto-dismisses after 30 seconds
|
||||
$script:tick = 30
|
||||
$btnOK.Content = "OK (30)"
|
||||
# Use a hashtable for shared state so the closure captures it by reference correctly
|
||||
$state = @{ Tick = 30 }
|
||||
$btnOK.Content = 'OK (30)'
|
||||
$timer = New-Object System.Windows.Threading.DispatcherTimer
|
||||
$timer.Interval = [TimeSpan]::FromSeconds(1)
|
||||
$timer.Add_Tick({
|
||||
$script:tick--
|
||||
$btnOK.Content = "OK ($script:tick)"
|
||||
if ($script:tick -le 0) {
|
||||
$state.Tick--
|
||||
$btnOK.Content = "OK ($($state.Tick))"
|
||||
if ($state.Tick -le 0) {
|
||||
$timer.Stop()
|
||||
$window.Close()
|
||||
}
|
||||
})
|
||||
}.GetNewClosure())
|
||||
$timer.Start()
|
||||
$btnOK.Add_Click({ $timer.Stop(); $window.Close() })
|
||||
$btnOK.Add_Click({ $timer.Stop(); $window.Close() }.GetNewClosure())
|
||||
$window.ShowDialog() | Out-Null
|
||||
|
||||
@@ -241,16 +241,7 @@ Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Replay Buffer confi
|
||||
# --- Notify user that the replay buffer is active ---
|
||||
$notifyScript = Join-Path $PSScriptRoot 'Show-Notification.ps1'
|
||||
$bufferMinutes = [math]::Round($config.BufferSeconds / 60)
|
||||
Start-Process -FilePath 'powershell.exe' -ArgumentList @(
|
||||
'-STA'
|
||||
'-ExecutionPolicy', 'Bypass'
|
||||
'-NonInteractive'
|
||||
'-WindowStyle', 'Hidden'
|
||||
'-File', $notifyScript
|
||||
'-Type', 'BufferStarted'
|
||||
'-ContactNumber', $config.ITContactNumber
|
||||
'-BufferMinutes', $bufferMinutes
|
||||
) -WindowStyle Hidden
|
||||
Start-Process -FilePath 'powershell.exe' -ArgumentList "-STA -ExecutionPolicy Bypass -NonInteractive -WindowStyle Hidden -File `"$notifyScript`" -Type BufferStarted -ContactNumber `"$($config.ITContactNumber)`" -BufferMinutes $bufferMinutes" -WindowStyle Hidden
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] User notification launched."
|
||||
|
||||
# --- Launch tray icon as a separate background process ---
|
||||
|
||||
Reference in New Issue
Block a user