docs: add Windows PowerShell hook examples (#567)
Release Please / release-please (push) Waiting to run
Docs / build (push) Has been cancelled
Docs / deploy (push) Has been cancelled

This commit is contained in:
homandr authored and GitHub committed 2024-11-19 00:21:46 -08:00
1 parent 3397a011a3
commit 0d53343db0
1 file changed
+64
@@ -145,3 +145,67 @@ fi
```
**Error Behavior:** `ON_ERROR_CANCEL`
### Windows PowerShell examples
#### GUI message box on error condition
The message box stays on screen until acknowledged by the user. Use the same script for both backup plan and repo settings to catch errors.
**Condition** `CONDITION_ANY_ERROR`
**Script**
```powershell
Add-Type -AssemblyName System.Windows.Forms
# This option puts message box on top of all windows.
$options = [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
$defbutton = [System.Windows.Forms.MessageBoxDefaultButton]::Button1
$buttons = [System.Windows.Forms.MessageBoxButtons]::OK
$icon = [System.Windows.Forms.MessageBoxIcon]::Error
$title = "Backrest"
$message = '{{ .Summary }}'
[System.Windows.Forms.MessageBox]::Show($message, $title, $buttons, $icon, $defbutton, $options)
# Include this comment and the line above it. See https://github.com/garethgeorge/backrest/issues/400
```
#### GUI toast warning notification
Toast or app notifications appear for a short time before disappearing without user acknowledgement.
**Condition** `CONDITION_SNAPSHOT_WARNING`
**Script**
```powershell
Add-Type -AssemblyName System.Windows.Forms
$balloon = New-Object System.Windows.Forms.NotifyIcon
$balloon.Icon = [System.Drawing.SystemIcons]::Warning
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
$balloon.BalloonTipText = '{{ .Summary }}'
$balloon.BalloonTipTitle = "Backrest"
$balloon.Visible = $true
$balloon.ShowBalloonTip(5000)
Start-Sleep -Seconds(5)
$balloon.Visible = $false
$balloon.Icon.Dispose()
$balloon.Dispose()
# Include this comment and the line above it. See https://github.com/garethgeorge/backrest/issues/400
```
#### GUI toast information notification
**Condition** `CONDITION_SNAPSHOT_SUCCESS`
**Script**
```powershell
Add-Type -AssemblyName System.Windows.Forms
$balloon = New-Object System.Windows.Forms.NotifyIcon
$balloon.Icon = [System.Drawing.SystemIcons]::Information
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Information
$balloon.BalloonTipText = '{{ .Summary }}'
$balloon.BalloonTipTitle = "Backrest"
$balloon.Visible = $true
$balloon.ShowBalloonTip(5000)
Start-Sleep -Seconds(5)
$balloon.Visible = $false
$balloon.Icon.Dispose()
$balloon.Dispose()
# Include this comment and the line above it. See https://github.com/garethgeorge/backrest/issues/400
```