mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-08-25 02:16:38 +00:00
docs: add Windows PowerShell hook examples (#567)
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user