-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoop-update-notifier.ps1
63 lines (49 loc) · 2.15 KB
/
scoop-update-notifier.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
$ErrorActionPreference = 'Stop'
# Load assemblies.
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
function Notify-Update {
Set-Location $PSScriptRoot
scoop update
$updates = scoop status | Where-Object Info -NotMatch 'Held package'
$message = 'Up to date!'
if ($updates) {
$outdatedAppCount = ($updates | Measure-Object).Count
if ($outdatedAppCount -eq 1) {
# FIXME: End up reaching this context even if only "WARN Scoop bucket(s) out of date. Run 'scoop update' to get the latest changes." .
$message = 'There is an update.'
}
else {
$message = 'There are {0} updates.' -f $outdatedAppCount
}
if (Test-Path '.\previous-updates') {
$updatesPrevious = Import-Clixml '.\previous-updates'
$isSameAsPrevious = $null -eq (Compare-Object $updatesPrevious $updates -Property Name, 'Latest Version')
if ($isSameAsPrevious) {
$toastLineFeed = '
'
$message = $message + $toastLineFeed + 'Should be update!'
}
}
$updates | Export-Clixml '.\previous-updates'
}
# NOTE: This is necessary for testing.
Write-Output $message
$content = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>scoop-update-notifier</text>
<text>$message</text>
</binding>
</visual>
</toast>
"@
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($content)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(5)
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe')
$notifier.Show($toast)
}
Notify-Update