From 0d53343db033c5d1a4ade5607d7d2764ca09a10d Mon Sep 17 00:00:00 2001 From: homandr <18056573+homandr@users.noreply.github.com> Date: Tue, 19 Nov 2024 02:21:46 -0600 Subject: [PATCH] docs: add Windows PowerShell hook examples (#567) --- .../3.cookbooks/1.command-hook-examples.md | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docs/content/3.cookbooks/1.command-hook-examples.md b/docs/content/3.cookbooks/1.command-hook-examples.md index 5da9cd77..7b192fd6 100644 --- a/docs/content/3.cookbooks/1.command-hook-examples.md +++ b/docs/content/3.cookbooks/1.command-hook-examples.md @@ -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 +```