Fixed the Notification errors
This commit is contained in:
@@ -93,17 +93,7 @@ try {
|
|||||||
|
|
||||||
# --- Notify user that the replay was saved ---
|
# --- Notify user that the replay was saved ---
|
||||||
$notifyScript = Join-Path $PSScriptRoot 'Show-Notification.ps1'
|
$notifyScript = Join-Path $PSScriptRoot 'Show-Notification.ps1'
|
||||||
Start-Process -FilePath 'powershell.exe' -ArgumentList @(
|
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
|
||||||
'-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."
|
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] User notification launched."
|
||||||
|
|
||||||
return $true
|
return $true
|
||||||
|
|||||||
@@ -20,21 +20,40 @@ param(
|
|||||||
[double]$FileSizeMB = 0
|
[double]$FileSizeMB = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
Add-Type -AssemblyName PresentationFramework
|
Add-Type -AssemblyName PresentationFramework
|
||||||
Add-Type -AssemblyName WindowsBase
|
Add-Type -AssemblyName WindowsBase
|
||||||
Add-Type -AssemblyName System.Drawing
|
Add-Type -AssemblyName System.Drawing
|
||||||
|
|
||||||
$hBitmap = [System.Drawing.SystemIcons]::Shield.ToBitmap().GetHbitmap()
|
Add-Type -TypeDefinition @"
|
||||||
$wpfImage = [System.Windows.Interop.Imaging]::CreateBitmapSourceFromHBitmap(
|
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()
|
||||||
|
$wpfShield = [System.Windows.Interop.Imaging]::CreateBitmapSourceFromHBitmap(
|
||||||
$hBitmap, [IntPtr]::Zero, [System.Windows.Int32Rect]::Empty,
|
$hBitmap, [IntPtr]::Zero, [System.Windows.Int32Rect]::Empty,
|
||||||
[System.Windows.Media.Imaging.BitmapSizeOptions]::FromEmptyOptions()
|
[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') {
|
if ($Type -eq 'BufferStarted') {
|
||||||
[xml]$xaml = @"
|
[xml]$xaml = @"
|
||||||
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<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"
|
WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
|
||||||
Topmost="True" ShowInTaskbar="False">
|
Topmost="True" ShowInTaskbar="False">
|
||||||
<Grid Margin="20">
|
<Grid Margin="20">
|
||||||
@@ -69,8 +88,8 @@ if ($Type -eq 'BufferStarted') {
|
|||||||
$txtContact = $window.FindName('TxtContact')
|
$txtContact = $window.FindName('TxtContact')
|
||||||
$btnOK = $window.FindName('BtnOK')
|
$btnOK = $window.FindName('BtnOK')
|
||||||
|
|
||||||
$imgHeader.Source = $wpfImage
|
$imgHeader.Source = $wpfWarning
|
||||||
$imgTray.Source = $wpfImage
|
$imgTray.Source = $wpfShield
|
||||||
$txtContact.Text = "Questions? Contact IT at $ContactNumber"
|
$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, ")
|
$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 {
|
} else {
|
||||||
[xml]$xaml = @"
|
[xml]$xaml = @"
|
||||||
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<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"
|
WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
|
||||||
Topmost="True" ShowInTaskbar="False">
|
Topmost="True" ShowInTaskbar="False">
|
||||||
<Grid Margin="20">
|
<Grid Margin="20">
|
||||||
@@ -113,7 +133,7 @@ if ($Type -eq 'BufferStarted') {
|
|||||||
$txtContact = $window.FindName('TxtContact')
|
$txtContact = $window.FindName('TxtContact')
|
||||||
$btnOK = $window.FindName('BtnOK')
|
$btnOK = $window.FindName('BtnOK')
|
||||||
|
|
||||||
$imgHeader.Source = $wpfImage
|
$imgHeader.Source = $wpfShield
|
||||||
$txtContact.Text = "Questions? Contact IT at $ContactNumber"
|
$txtContact.Text = "Questions? Contact IT at $ContactNumber"
|
||||||
|
|
||||||
$txtBody.Inlines.Add("Your replay has been saved ($FileSizeMB MB):`n")
|
$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
|
# Countdown timer — auto-dismisses after 30 seconds
|
||||||
$script:tick = 30
|
# Use a hashtable for shared state so the closure captures it by reference correctly
|
||||||
$btnOK.Content = "OK (30)"
|
$state = @{ Tick = 30 }
|
||||||
|
$btnOK.Content = 'OK (30)'
|
||||||
$timer = New-Object System.Windows.Threading.DispatcherTimer
|
$timer = New-Object System.Windows.Threading.DispatcherTimer
|
||||||
$timer.Interval = [TimeSpan]::FromSeconds(1)
|
$timer.Interval = [TimeSpan]::FromSeconds(1)
|
||||||
$timer.Add_Tick({
|
$timer.Add_Tick({
|
||||||
$script:tick--
|
$state.Tick--
|
||||||
$btnOK.Content = "OK ($script:tick)"
|
$btnOK.Content = "OK ($($state.Tick))"
|
||||||
if ($script:tick -le 0) {
|
if ($state.Tick -le 0) {
|
||||||
$timer.Stop()
|
$timer.Stop()
|
||||||
$window.Close()
|
$window.Close()
|
||||||
}
|
}
|
||||||
})
|
}.GetNewClosure())
|
||||||
$timer.Start()
|
$timer.Start()
|
||||||
$btnOK.Add_Click({ $timer.Stop(); $window.Close() })
|
$btnOK.Add_Click({ $timer.Stop(); $window.Close() }.GetNewClosure())
|
||||||
$window.ShowDialog() | Out-Null
|
$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 ---
|
# --- Notify user that the replay buffer is active ---
|
||||||
$notifyScript = Join-Path $PSScriptRoot 'Show-Notification.ps1'
|
$notifyScript = Join-Path $PSScriptRoot 'Show-Notification.ps1'
|
||||||
$bufferMinutes = [math]::Round($config.BufferSeconds / 60)
|
$bufferMinutes = [math]::Round($config.BufferSeconds / 60)
|
||||||
Start-Process -FilePath 'powershell.exe' -ArgumentList @(
|
Start-Process -FilePath 'powershell.exe' -ArgumentList "-STA -ExecutionPolicy Bypass -NonInteractive -WindowStyle Hidden -File `"$notifyScript`" -Type BufferStarted -ContactNumber `"$($config.ITContactNumber)`" -BufferMinutes $bufferMinutes" -WindowStyle Hidden
|
||||||
'-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."
|
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] User notification launched."
|
||||||
|
|
||||||
# --- Launch tray icon as a separate background process ---
|
# --- Launch tray icon as a separate background process ---
|
||||||
|
|||||||
Reference in New Issue
Block a user