Skip to content

Commit

Permalink
little changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanitho authored Jan 22, 2022
1 parent fc8953e commit e0608b2
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions winget-update/winget-upgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

#Get locale file for Notification
#Default en-US
$DefaultLocal = "$WorkingDir\locale\en-US.xml"
$DefaultLocale = "$WorkingDir\locale\en-US.xml"
#Get OS locale
$Locale = Get-WinSystemLocale
#Test if OS locale config file exists
$LocalFile = "$WorkingDir\locale\$($locale.Name).xml"
if(Test-Path $LocalFile){
[xml]$Script:NotifLocal = Get-Content $LocalFile -Encoding UTF8 -ErrorAction SilentlyContinue
Write-Log "Local : $($locale.Name)"
$LocaleFile = "$WorkingDir\locale\$($locale.Name).xml"
if(Test-Path $LocaleFile){
[xml]$Script:NotifLocale = Get-Content $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue
Write-Log "Notification Langugage : $($locale.Name)"
}
else{
[xml]$Script:NotifLocal = Get-Content $DefaultLocal -Encoding UTF8 -ErrorAction SilentlyContinue
Write-Log "Local : en-US"
[xml]$Script:NotifLocale = Get-Content $DefaultLocale -Encoding UTF8 -ErrorAction SilentlyContinue
Write-Log "Notification Langugage : en-US"
}
}

Expand Down Expand Up @@ -69,7 +69,7 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
Get-ScheduledTask -TaskName "Winget Update Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
#Wait for notification to display
while ((Get-ScheduledTask -TaskName "Winget Update Notify").State -ne 'Ready') {
Write-Output "Waiting on scheduled task..."
Write-Output "Waiting for scheduled task..."
Start-Sleep 3
}
}
Expand All @@ -81,7 +81,7 @@ function Test-Network {
Write-Log "Checking internet connection..." "Yellow"
while (!$ping -and $timeout -lt 1800){
try{
Invoke-RestMethod -Uri "https://ifconfig.me/"
Invoke-RestMethod -Uri "https://api.github.com/zen"
Write-Log "Coonected !" "Green"
$ping = $true
return
Expand All @@ -94,8 +94,8 @@ function Test-Network {
if ($timeout -eq 300){
#Send Notif if no connection for 5 min
Write-Log "Notify 'No connection'" "Yellow"
$Title = $NotifLocal.local.outputs.output[0].title
$Message = $NotifLocal.local.outputs.output[0].message
$Title = $NotifLocale.local.outputs.output[0].title
$Message = $NotifLocale.local.outputs.output[0].message
$MessageType = "warning"
$Balise = "connection"
Start-NotifTask $Title $Message $MessageType $Balise
Expand Down Expand Up @@ -227,8 +227,8 @@ if ($ping){

#Send available update notification
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
$Title = $NotifLocal.local.outputs.output[2].title -f $($app.Name)
$Message = $NotifLocal.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
$MessageType = "info"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
Expand Down Expand Up @@ -261,8 +261,8 @@ if ($ping){
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"

#Send Notif
$Title = $NotifLocal.local.outputs.output[3].title -f $($app.Name)
$Message = $NotifLocal.local.outputs.output[3].message -f $($app.AvailableVersion)
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
$MessageType = "success"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
Expand All @@ -274,8 +274,8 @@ if ($ping){
Write-Log "$($app.Name) update failed." "Red"

#Send Notif
$Title = $NotifLocal.local.outputs.output[4].title -f $($app.Name)
$Message = $NotifLocal.local.outputs.output[4].message
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[4].message
$MessageType = "error"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
Expand All @@ -296,8 +296,8 @@ if ($ping){
else{
Write-Log "Timeout. No internet connection !" "Red"
#Send Notif
$Title = $NotifLocal.local.outputs.output[1].title
$Message = $NotifLocal.local.outputs.output[1].message
$Title = $NotifLocale.local.outputs.output[1].title
$Message = $NotifLocale.local.outputs.output[1].message
$MessageType = "error"
$Balise = "connection"
Start-NotifTask $Title $Message $MessageType $Balise
Expand Down

0 comments on commit e0608b2

Please sign in to comment.