Fixed the Notification errors
This commit is contained in:
@@ -20,21 +20,40 @@ param(
|
||||
[double]$FileSizeMB = 0
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
Add-Type -AssemblyName PresentationFramework
|
||||
Add-Type -AssemblyName WindowsBase
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
|
||||
$hBitmap = [System.Drawing.SystemIcons]::Shield.ToBitmap().GetHbitmap()
|
||||
$wpfImage = [System.Windows.Interop.Imaging]::CreateBitmapSourceFromHBitmap(
|
||||
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()
|
||||
$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
|
||||
|
||||
Reference in New Issue
Block a user