Added Notification Level Feature
parent
bcd9d02ce4
commit
e40d5f441a
|
@ -25,6 +25,9 @@ Use White List instead of Black List. This setting will not create the "exclude_
|
|||
.PARAMETER Uninstall
|
||||
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
|
||||
.\winget-install-and-update.ps1 -Silent -DoNotUpdate
|
||||
|
||||
|
@ -41,6 +44,7 @@ param(
|
|||
[Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false,
|
||||
[Parameter(Mandatory=$False)] [Switch] $Uninstall = $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>
|
||||
<WAUprerelease>False</WAUprerelease>
|
||||
<UseWAUWhiteList>$UseWhiteList</UseWAUWhiteList>
|
||||
<NotificationLevel>$NotificationLevel</NotificationLevel>
|
||||
</app>
|
||||
"@
|
||||
$ConfigXML.Save("$WingetUpdatePath\config\config.xml")
|
||||
|
|
|
@ -20,7 +20,7 @@ Function Get-NotifLocale {
|
|||
}
|
||||
|
||||
#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
|
||||
|
||||
}
|
|
@ -2,16 +2,24 @@
|
|||
|
||||
function Get-WAUConfig{
|
||||
|
||||
#Get config file
|
||||
[xml]$WAUConfig = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||
|
||||
#Check if WAU is configured for Black or White List
|
||||
if ($true -eq [System.Convert]::ToBoolean($WAUConfig.app.UseWAUWhiteList)){
|
||||
Write-Log "WAU uses White List config"
|
||||
$Script:UseWhiteList = $true
|
||||
}
|
||||
else{
|
||||
Write-Log "WAU uses Black List config"
|
||||
$Script:UseWhiteList = $false
|
||||
}
|
||||
|
||||
#Get Notification Level
|
||||
if ($WAUConfig.app.NotificationLevel){
|
||||
$Script:NotificationLevel = $WAUConfig.app.NotificationLevel
|
||||
}
|
||||
else{
|
||||
#Default: Full
|
||||
$Script:NotificationLevel = $full
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
|
||||
|
||||
#Add XML variables
|
||||
[xml]$ToastTemplate = @"
|
||||
if (($NotificationLevel -eq "Full") -or ($NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success")) {
|
||||
|
||||
#Add XML variables
|
||||
[xml]$ToastTemplate = @"
|
||||
<toast launch="ms-get-started://redirect?id=apps_action">
|
||||
<visual>
|
||||
<binding template="ToastImageAndText03">
|
||||
|
@ -16,45 +18,47 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
|
|||
</toast>
|
||||
"@
|
||||
|
||||
#Check if running account is system or interactive logon
|
||||
$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"
|
||||
#Check if running account is system or interactive logon
|
||||
$currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4")
|
||||
|
||||
#Prepare and Create Toast
|
||||
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml)
|
||||
$ToastMessage.Tag = $ToastTemplate.toast.tag
|
||||
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
|
||||
#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
|
||||
$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
|
||||
|
||||
}
|
|
@ -11,6 +11,9 @@ Get-ChildItem "$WorkingDir\functions" | ForEach-Object {. $_.FullName}
|
|||
#Run log initialisation function
|
||||
Start-Init
|
||||
|
||||
#Get WAU Configurations
|
||||
Get-WAUConfig
|
||||
|
||||
#Get Notif Locale function
|
||||
Get-NotifLocale
|
||||
|
||||
|
@ -40,11 +43,12 @@ if (Test-Network){
|
|||
}
|
||||
|
||||
#Get White or Black list
|
||||
Get-WAUConfig
|
||||
if ($UseWhiteList){
|
||||
Write-Log "WAU uses White List config"
|
||||
$toUpdate = Get-IncludedApps
|
||||
}
|
||||
else{
|
||||
Write-Log "WAU uses Black List config"
|
||||
$toSkip = Get-ExcludedApps
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
@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
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
@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
|
Loading…
Reference in New Issue