#Requires -Version 5.1 <# .SYNOPSIS System tray icon that lets users trigger an OBS replay buffer save. Right-click the tray icon to access Save Replay or Exit. .NOTES This script blocks (runs a WinForms message loop) — launch it via Start-Process. Start-OBSReplayBuffer.ps1 handles launching this automatically at logon. #> Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing function Show-Notification { param([string]$Title, [string]$Body) try { [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null $xml = [Windows.Data.Xml.Dom.XmlDocument]::new() $escaped = [System.Security.SecurityElement]::Escape($Body) $xml.LoadXml("$Title$escaped") $toast = [Windows.UI.Notifications.ToastNotification]::new($xml) [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('IT Screen Recorder').Show($toast) } catch { [System.Windows.Forms.MessageBox]::Show($Body, $Title, [System.Windows.Forms.MessageBoxButtons]::OK) | Out-Null } } $saveScript = Join-Path $PSScriptRoot 'Invoke-ReplaySave.ps1' # --- Tray icon --- $tray = New-Object System.Windows.Forms.NotifyIcon $tray.Icon = [System.Drawing.SystemIcons]::Shield $tray.Text = 'IT Screen Recorder' $tray.Visible = $true # --- Context menu --- $menu = New-Object System.Windows.Forms.ContextMenuStrip $saveItem = New-Object System.Windows.Forms.ToolStripMenuItem('Save Replay') $sep = New-Object System.Windows.Forms.ToolStripSeparator $exitItem = New-Object System.Windows.Forms.ToolStripMenuItem('Exit') $saveItem.Add_Click({ $saveItem.Enabled = $false $saveItem.Text = 'Saving...' $result = & powershell.exe -ExecutionPolicy Bypass -NonInteractive -File $saveScript if ($result -eq $true) { Show-Notification -Title 'IT Screen Recorder' -Body 'Replay saved.' } else { Show-Notification -Title 'IT Screen Recorder' -Body 'Could not save replay. Please contact the helpdesk.' } $saveItem.Text = 'Save Replay' $saveItem.Enabled = $true }) $exitItem.Add_Click({ $tray.Visible = $false [System.Windows.Forms.Application]::Exit() }) $menu.Items.Add($saveItem) | Out-Null $menu.Items.Add($sep) | Out-Null $menu.Items.Add($exitItem) | Out-Null $tray.ContextMenuStrip = $menu # --- Message loop (blocks until Exit is chosen) --- [System.Windows.Forms.Application]::Run() $tray.Dispose()