Я пытаюсь создать небольшую программу PowerShell для отображения всплывающего уведомления, которое покажет мне в режиме реального времени, как выполняется задание копирования. На данный момент я не закодировал программу сравнения размера источника/копии, поэтому предполагается, что она увеличивается на 1% каждую секунду.
$image = New-BTImage -Source "D:\Pictures\Profile image.png" -Crop Circle
$binding = @{
text1 = "Downloading your files..."
text2 = "Your files are being downloaded so they can be available offline."
image = $image
value = 0
}
$progress = New-BTProgressBar -Status "Downloading..." -Value $binding['value'] -Title "Download" -Verbose
New-BurntToastNotification -Text $binding['text1'], $binding['text2'] -AppLogo $binding['image'] -ProgressBar $progress -UniqueIdentifier "toast" -Verbose
foreach ($n in 1..100){
$binding['value'] = $binding['value'] + 0.01
$binding['text1'] = "hello"
Write-Output $binding
Update-BTNotification -UniqueIdentifier "toast" -DataBinding $binding -Verbose
Start-Sleep 1
}
Но вроде не обновляется! -Verbose
не показывает никаких ошибок, а Write-Output $binding
явно свидетельствует о том, что $bindings
обновляется каждую секунду...
Я не знаю, что я делаю неправильно...
Спасибо за любой ответ, Силлоки
Вот код, который работает:
$progress = New-BTProgressBar -Title "Copying progress :" -Status "Downloading..." -Value 'value'
$image = New-BTImage -Source "$PSScriptRoot\icons\shell32_16739.ico" -Crop None
$button = New-BTButton -Dismiss -Content "OK"
$binding = @{
value = 0
}
New-BurntToastNotification -Text "Downloading your files...", "Your files are being downloaded so they can be available offline." -DataBinding $binding -UniqueIdentifier "001" -ProgressBar $progress -AppLogo $image
Start-Sleep 3
foreach ($n in 1..100){
Start-Sleep 0.5
$binding['value'] = $binding['value'] + 0.02
$null = Update-BTNotification -UniqueIdentifier "001" -DataBinding $binding
}
Remove-BTNotification -UniqueIdentifier "001"
New-BurntToastNotification -Text "Done !", "Your files are now available offline." -AppLogo $image -Button $button
До свидания !