Skip to content

Commit 0d53343

Browse files
authored
docs: add Windows PowerShell hook examples (#567)
1 parent 3397a01 commit 0d53343

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

docs/content/3.cookbooks/1.command-hook-examples.md

+64
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,67 @@ fi
145145
```
146146
147147
**Error Behavior:** `ON_ERROR_CANCEL`
148+
149+
### Windows PowerShell examples
150+
#### GUI message box on error condition
151+
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.
152+
153+
**Condition** `CONDITION_ANY_ERROR`
154+
155+
**Script**
156+
```powershell
157+
Add-Type -AssemblyName System.Windows.Forms
158+
# This option puts message box on top of all windows.
159+
$options = [System.Windows.Forms.MessageBoxOptions]::ServiceNotification
160+
$defbutton = [System.Windows.Forms.MessageBoxDefaultButton]::Button1
161+
$buttons = [System.Windows.Forms.MessageBoxButtons]::OK
162+
$icon = [System.Windows.Forms.MessageBoxIcon]::Error
163+
$title = "Backrest"
164+
$message = '{{ .Summary }}'
165+
[System.Windows.Forms.MessageBox]::Show($message, $title, $buttons, $icon, $defbutton, $options)
166+
167+
# Include this comment and the line above it. See https://github.com/garethgeorge/backrest/issues/400
168+
```
169+
#### GUI toast warning notification
170+
Toast or app notifications appear for a short time before disappearing without user acknowledgement.
171+
172+
**Condition** `CONDITION_SNAPSHOT_WARNING`
173+
174+
**Script**
175+
```powershell
176+
Add-Type -AssemblyName System.Windows.Forms
177+
$balloon = New-Object System.Windows.Forms.NotifyIcon
178+
$balloon.Icon = [System.Drawing.SystemIcons]::Warning
179+
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
180+
$balloon.BalloonTipText = '{{ .Summary }}'
181+
$balloon.BalloonTipTitle = "Backrest"
182+
$balloon.Visible = $true
183+
$balloon.ShowBalloonTip(5000)
184+
Start-Sleep -Seconds(5)
185+
$balloon.Visible = $false
186+
$balloon.Icon.Dispose()
187+
$balloon.Dispose()
188+
189+
# Include this comment and the line above it. See https://github.com/garethgeorge/backrest/issues/400
190+
```
191+
#### GUI toast information notification
192+
193+
**Condition** `CONDITION_SNAPSHOT_SUCCESS`
194+
195+
**Script**
196+
```powershell
197+
Add-Type -AssemblyName System.Windows.Forms
198+
$balloon = New-Object System.Windows.Forms.NotifyIcon
199+
$balloon.Icon = [System.Drawing.SystemIcons]::Information
200+
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Information
201+
$balloon.BalloonTipText = '{{ .Summary }}'
202+
$balloon.BalloonTipTitle = "Backrest"
203+
$balloon.Visible = $true
204+
$balloon.ShowBalloonTip(5000)
205+
Start-Sleep -Seconds(5)
206+
$balloon.Visible = $false
207+
$balloon.Icon.Dispose()
208+
$balloon.Dispose()
209+
210+
# Include this comment and the line above it. See https://github.com/garethgeorge/backrest/issues/400
211+
```

0 commit comments

Comments
 (0)