Added Notification Level Feature

pull/63/head
Romain 2022-04-24 10:51:51 +02:00 committed by GitHub
parent bcd9d02ce4
commit e40d5f441a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 45 deletions

View File

@ -25,6 +25,9 @@ Use White List instead of Black List. This setting will not create the "exclude_
.PARAMETER Uninstall .PARAMETER Uninstall
Remove scheduled tasks and scripts. Remove scheduled tasks and scripts.
.PARAMETER NotificationLevel
Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup).
.EXAMPLE .EXAMPLE
.\winget-install-and-update.ps1 -Silent -DoNotUpdate .\winget-install-and-update.ps1 -Silent -DoNotUpdate
@ -41,6 +44,7 @@ param(
[Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false,
[Parameter(Mandatory=$False)] [Switch] $Uninstall = $false, [Parameter(Mandatory=$False)] [Switch] $Uninstall = $false,
[Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $false [Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $false
[Parameter(Mandatory=$False)] [ValidateSet("Full","SuccessOnly","None")] [Switch] $NotificationLevel = "Full"
) )
@ -191,6 +195,7 @@ function Install-WingetAutoUpdate{
<WAUautoupdate>$(!($DisableWAUAutoUpdate))</WAUautoupdate> <WAUautoupdate>$(!($DisableWAUAutoUpdate))</WAUautoupdate>
<WAUprerelease>False</WAUprerelease> <WAUprerelease>False</WAUprerelease>
<UseWAUWhiteList>$UseWhiteList</UseWAUWhiteList> <UseWAUWhiteList>$UseWhiteList</UseWAUWhiteList>
<NotificationLevel>$NotificationLevel</NotificationLevel>
</app> </app>
"@ "@
$ConfigXML.Save("$WingetUpdatePath\config\config.xml") $ConfigXML.Save("$WingetUpdatePath\config\config.xml")

View File

@ -20,7 +20,7 @@ Function Get-NotifLocale {
} }
#Get locale XML file content #Get locale XML file content
Write-Log "Notification Langugage : $LocaleDisplayName" "Cyan" Write-Log "Notification Level: $NotificationLevel. Notification Language: $LocaleDisplayName" "Cyan"
[xml]$Script:NotifLocale = Get-Content $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue [xml]$Script:NotifLocale = Get-Content $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue
} }

View File

@ -2,16 +2,24 @@
function Get-WAUConfig{ function Get-WAUConfig{
#Get config file
[xml]$WAUConfig = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue [xml]$WAUConfig = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
#Check if WAU is configured for Black or White List #Check if WAU is configured for Black or White List
if ($true -eq [System.Convert]::ToBoolean($WAUConfig.app.UseWAUWhiteList)){ if ($true -eq [System.Convert]::ToBoolean($WAUConfig.app.UseWAUWhiteList)){
Write-Log "WAU uses White List config"
$Script:UseWhiteList = $true $Script:UseWhiteList = $true
} }
else{ else{
Write-Log "WAU uses Black List config"
$Script:UseWhiteList = $false $Script:UseWhiteList = $false
} }
#Get Notification Level
if ($WAUConfig.app.NotificationLevel){
$Script:NotificationLevel = $WAUConfig.app.NotificationLevel
}
else{
#Default: Full
$Script:NotificationLevel = $full
}
} }

View File

@ -2,8 +2,10 @@
function Start-NotifTask ($Title,$Message,$MessageType,$Balise) { function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
#Add XML variables if (($NotificationLevel -eq "Full") -or ($NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success")) {
[xml]$ToastTemplate = @"
#Add XML variables
[xml]$ToastTemplate = @"
<toast launch="ms-get-started://redirect?id=apps_action"> <toast launch="ms-get-started://redirect?id=apps_action">
<visual> <visual>
<binding template="ToastImageAndText03"> <binding template="ToastImageAndText03">
@ -16,45 +18,47 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
</toast> </toast>
"@ "@
#Check if running account is system or interactive logon #Check if running account is system or interactive logon
$currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4") $currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4")
#if not "Interactive" user, run as system
if ($currentPrincipal -eq $false){
#Save XML to File
$ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\"
if (!(Test-Path $ToastTemplateLocation)){
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
}
$ToastTemplate.Save("$ToastTemplateLocation\config\notif.xml")
#Run Notify scheduled task to notify conneted users
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
}
#else, run as connected user
else{
#Load Assemblies
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
#Prepare XML
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
$ToastXml.LoadXml($ToastTemplate.OuterXml)
#Specify Launcher App ID
$LauncherID = "Windows.SystemToast.Winget.Notification"
#Prepare and Create Toast #if not "Interactive" user, run as system
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml) if ($currentPrincipal -eq $false){
$ToastMessage.Tag = $ToastTemplate.toast.tag
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage) #Save XML to File
$ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\"
if (!(Test-Path $ToastTemplateLocation)){
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
}
$ToastTemplate.Save("$ToastTemplateLocation\config\notif.xml")
#Run Notify scheduled task to notify conneted users
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
}
#else, run as connected user
else{
#Load Assemblies
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
#Prepare XML
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
$ToastXml.LoadXml($ToastTemplate.OuterXml)
#Specify Launcher App ID
$LauncherID = "Windows.SystemToast.Winget.Notification"
#Prepare and Create Toast
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml)
$ToastMessage.Tag = $ToastTemplate.toast.tag
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
}
#Wait for notification to display
Start-Sleep 3
} }
#Wait for notification to display
Start-Sleep 3
} }

View File

@ -11,6 +11,9 @@ Get-ChildItem "$WorkingDir\functions" | ForEach-Object {. $_.FullName}
#Run log initialisation function #Run log initialisation function
Start-Init Start-Init
#Get WAU Configurations
Get-WAUConfig
#Get Notif Locale function #Get Notif Locale function
Get-NotifLocale Get-NotifLocale
@ -40,11 +43,12 @@ if (Test-Network){
} }
#Get White or Black list #Get White or Black list
Get-WAUConfig
if ($UseWhiteList){ if ($UseWhiteList){
Write-Log "WAU uses White List config"
$toUpdate = Get-IncludedApps $toUpdate = Get-IncludedApps
} }
else{ else{
Write-Log "WAU uses Black List config"
$toSkip = Get-ExcludedApps $toSkip = Get-ExcludedApps
} }

View File

@ -1,2 +1,2 @@
@echo off @echo off
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" '" -Verb RunAs powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" '" -Verb RunAs

View File

@ -1,2 +1,2 @@
@echo off @echo off
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Uninstall'" -Verb RunAs powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Uninstall'" -Verb RunAs