#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 $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) { $tray.ShowBalloonTip(4000, 'IT Screen Recorder', 'Replay saved.', [System.Windows.Forms.ToolTipIcon]::Info) } else { $tray.ShowBalloonTip(4000, 'IT Screen Recorder', 'Could not save replay. Please contact the helpdesk.', [System.Windows.Forms.ToolTipIcon]::Error) } $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()