From 10f2cc11c101b5a851b745f3cc91d925681dcdf2 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Thu, 14 Dec 2023 17:22:22 +0300 Subject: [PATCH] Code refactoring --- Wrapper/Config/config_Windows_11.json | 6 +- .../de-DE/tooltip_Windows_11.json | 10 +-- .../en-US/tooltip_Windows_11.json | 6 +- .../ru-RU/tooltip_Windows_11.json | 8 +- .../Module/Sophia.psm1 | 81 ++++++++----------- src/Sophia_Script_for_Windows_11/Sophia.ps1 | 4 +- .../Module/Sophia.psm1 | 81 ++++++++----------- .../Sophia.ps1 | 8 +- 8 files changed, 85 insertions(+), 119 deletions(-) diff --git a/Wrapper/Config/config_Windows_11.json b/Wrapper/Config/config_Windows_11.json index 52268079..af06f246 100644 --- a/Wrapper/Config/config_Windows_11.json +++ b/Wrapper/Config/config_Windows_11.json @@ -633,13 +633,13 @@ "Region": "UI & Personalization", "Control": "cmb", "Required": "false", - "Function": "TaskbarChat", + "Function": "TeamsInstallation", "Arg": { "Zero": { - "Tag": "Hide" + "Tag": "Disable" }, "One": { - "Tag": "Show" + "Tag": "Enable" } }, "Preset": "Zero", diff --git a/Wrapper/Localizations/de-DE/tooltip_Windows_11.json b/Wrapper/Localizations/de-DE/tooltip_Windows_11.json index f343e695..a598a51c 100644 --- a/Wrapper/Localizations/de-DE/tooltip_Windows_11.json +++ b/Wrapper/Localizations/de-DE/tooltip_Windows_11.json @@ -557,15 +557,15 @@ { "Id": 318, "Region": "UI & Personalization", - "Function": "TaskbarChat", + "Function": "TeamsInstallation", "Arg": { "Zero": { - "Tag": "Hide", - "ToolTip": "Blendet das Chat-Symbol (Microsoft Teams) in der Taskleiste aus und verhindert die Installation von Microsoft Teams für neue Benutzer." + "Tag": "Disable", + "ToolTip": "Verhindern Sie die Installation von Chat (Microsoft Teams) für neue Benutzer." }, "One": { - "Tag": "Show", - "ToolTip": "Zeigt das Chat-Symbol (Microsoft Teams) in der Taskleiste an und ermöglicht die Installation von Microsoft Teams für neue Benutzer (Standardeinstellung)." + "Tag": "Enable", + "ToolTip": "Verhindern Sie nicht, dass Microsoft Teams für neue Benutzer installiert wird (Standardeinstellung)." } } }, diff --git a/Wrapper/Localizations/en-US/tooltip_Windows_11.json b/Wrapper/Localizations/en-US/tooltip_Windows_11.json index a18b6aef..f0199489 100644 --- a/Wrapper/Localizations/en-US/tooltip_Windows_11.json +++ b/Wrapper/Localizations/en-US/tooltip_Windows_11.json @@ -557,15 +557,15 @@ { "Id": 318, "Region": "UI & Personalization", - "Function": "TaskbarChat", + "Function": "TeamsInstallation", "Arg": { "Zero": { "Tag": "Hide", - "ToolTip": "Hide the Chat icon (Microsoft Teams) on the taskbar and prevent Microsoft Teams from installing for new users." + "ToolTip": "Prevent Chat (Microsoft Teams) from installing for new users." }, "One": { "Tag": "Show", - "ToolTip": "Show the Chat icon (Microsoft Teams) on the taskbar and remove block from installing Microsoft Teams for new users (default value)." + "ToolTip": "Do not prevent Microsoft Teams from installing for new users (default value)." } } }, diff --git a/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json b/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json index 3e3acf9d..dbc64b48 100644 --- a/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json +++ b/Wrapper/Localizations/ru-RU/tooltip_Windows_11.json @@ -557,14 +557,14 @@ { "Id": 318, "Region": "UI & Personalization", - "Function": "TaskbarChat", + "Function": "TeamsInstallation", "Arg": { "Zero": { - "Tag": "Hide", - "ToolTip": "Скрыть кнопку чата (Microsoft Teams) с панели задач и запретить установку Microsoft Teams для новых пользователей." + "Tag": "Disable", + "ToolTip": "Запретить установку Chat (Microsoft Teams) для новых пользователей." }, "One": { - "Tag": "Show", + "Tag": "Enable", "ToolTip": "Отобразить кнопку чата (Microsoft Teams) на панели задач и убрать блокировку на устанвоку Microsoft Teams для новых пользователей (значение по умолчанию)." } } diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 29099a94..672b7282 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -3242,58 +3242,54 @@ function TaskViewButton <# .SYNOPSIS - The Chat icon (Microsoft Teams) on the taskbar + Chat (Microsoft Teams) installation for new users - .PARAMETER Hide - Hide the Chat icon (Microsoft Teams) on the taskbar and prevent Microsoft Teams from installing for new users + .PARAMETER Disable + Prevent Chat (Microsoft Teams) from installing for new users - .PARAMETER Show - Show the Chat icon (Microsoft Teams) on the taskbar and remove block from installing Microsoft Teams for new users + .PARAMETER Enable + Do not prevent Microsoft Teams from installing for new users .EXAMPLE - TaskbarChat -Hide + TeamsInstallation -Disable .EXAMPLE - TaskbarChat -Show + TeamsInstallation -Enable .NOTES Current user #> -function TaskbarChat +function TeamsInstallation { param ( [Parameter( Mandatory = $true, - ParameterSetName = "Hide" + ParameterSetName = "Disable" )] [switch] - $Hide, + $Disable, [Parameter( Mandatory = $true, - ParameterSetName = "Show" + ParameterSetName = "Enable" )] [switch] - $Show + $Enable ) Clear-Variable -Name Task -ErrorAction Ignore switch ($PSCmdlet.ParameterSetName) { - "Hide" + "Disable" { - New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarMn -PropertyType DWord -Value 0 -Force - # Save string to run it as "NT SERVICE\TrustedInstaller" # Prevent Microsoft Teams from installing for new users $Task = "New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications -Name ConfigureChatAutoInstall -Value 0 -Type Dword -Force" } - "Show" + "Enable" { - New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarMn -PropertyType DWord -Value 1 -Force - # Save string to run it as "NT SERVICE\TrustedInstaller" # Remove block from installing Microsoft Teams for new users $Task = "Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications -Name ConfigureChatAutoInstall -Value 1 -Type Dword -Force" @@ -10729,37 +10725,32 @@ function UninstallUWPApps $AppxPackages = @(Get-AppxPackage -PackageTypeFilter Bundle -AllUsers:$AllUsers | Where-Object -FilterScript {$_.Name -notin $ExcludedAppxPackages}) - # The Bundle packages contains no Microsoft Teams - if (Get-AppxPackage -Name MicrosoftTeams -AllUsers:$AllUsers) - { - # Temporarily hack: due to the fact that there are actually two Microsoft Teams packages, we need to choose the first one to display - $AppxPackages += Get-AppxPackage -Name MicrosoftTeams -AllUsers:$AllUsers | Select-Object -Index 0 - } + # The -PackageTypeFilter Bundle doesn't contain these packages, and we need to add manually + $Packages = @( + # Spotify + "SpotifyAB.SpotifyMusic", - # The Bundle packages contains no Spotify - if (Get-AppxPackage -Name SpotifyAB.SpotifyMusic -AllUsers:$AllUsers) - { - $AppxPackages += Get-AppxPackage -Name SpotifyAB.SpotifyMusic -AllUsers:$AllUsers - } - - # The Bundle packages contains no Disney+ - if (Get-AppxPackage -Name Disney.37853FC22B2CE -AllUsers:$AllUsers) - { - $AppxPackages += Get-AppxPackage -Name Disney.37853FC22B2CE -AllUsers:$AllUsers - } + # Disney+ + "Disney.37853FC22B2CE", - # The Bundle packages contains no Outlook - if (Get-AppxPackage -Name Microsoft.OutlookForWindows -AllUsers:$AllUsers) + # Outlook + "Microsoft.OutlookForWindows", + + # Chat (Microsoft Teams) + "MicrosoftTeams" + ) + foreach ($Package in $Packages) { - $AppxPackages += Get-AppxPackage -Name Microsoft.OutlookForWindows -AllUsers:$AllUsers + if (Get-AppxPackage -Name $Package -AllUsers:$AllUsers) + { + $AppxPackages += Get-AppxPackage -Name $Package -AllUsers:$AllUsers + } } $PackagesIds = [Windows.Management.Deployment.PackageManager, Windows.Web, ContentType = WindowsRuntime]::new().FindPackages() | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name, DisplayName - foreach ($AppxPackage in $AppxPackages) { $PackageId = $PackagesIds | Where-Object -FilterScript {$_.Name -eq $AppxPackage.Name} - if (-not $PackageId) { continue @@ -11101,15 +11092,7 @@ function RestoreUWPApps # The Bundle packages contains no Microsoft Teams if (Get-AppxPackage -Name MicrosoftTeams -AllUsers) { - # Temporarily hack: due to the fact that there are actually two Microsoft Teams packages, we need to choose the first one to display - $AppxPackages += Get-AppxPackage -Name MicrosoftTeams -AllUsers | Where-Object -FilterScript {$_.PackageUserInformation -match "Staged"} | Select-Object -Index 0 - } - - # The Bundle packages contains no Spotify - if (Get-AppxPackage -Name SpotifyAB.SpotifyMusic -AllUsers) - { - # Temporarily hack: due to the fact that there are actually two Spotify packages, we need to choose the first one to display - $AppxPackages += Get-AppxPackage -Name SpotifyAB.SpotifyMusic -AllUsers | Where-Object -FilterScript {$_.PackageUserInformation -match "Staged"} | Select-Object -Index 0 + $AppxPackages += Get-AppxPackage -Name MicrosoftTeams -AllUsers | Where-Object -FilterScript {$_.PackageUserInformation -match "Staged"} } $PackagesIds = [Windows.Management.Deployment.PackageManager, Windows.Web, ContentType = WindowsRuntime]::new().FindPackages() | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name, DisplayName diff --git a/src/Sophia_Script_for_Windows_11/Sophia.ps1 b/src/Sophia_Script_for_Windows_11/Sophia.ps1 index 6a59514e..9b932277 100644 --- a/src/Sophia_Script_for_Windows_11/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11/Sophia.ps1 @@ -407,11 +407,11 @@ TaskViewButton -Hide # Hide the Chat icon (Microsoft Teams) on the taskbar and prevent Microsoft Teams from installing for new users # Скрыть кнопку чата (Microsoft Teams) с панели задач и запретить установку Microsoft Teams для новых пользователей -TaskbarChat -Hide +PreventTeamsInstallation -Hide # Show the Chat icon (Microsoft Teams) on the taskbar and remove block from installing Microsoft Teams for new users (default value) # Отобразить кнопку чата (Microsoft Teams) на панели задач и убрать блокировку на устанвоку Microsoft Teams для новых пользователей (значение по умолчанию) -# TaskbarChat -Show +# PreventTeamsInstallation -Show # Show seconds on the taskbar clock # Показывать секунды на часах на панели задач diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index 47e3a354..c8f32781 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -3243,58 +3243,54 @@ function TaskViewButton <# .SYNOPSIS - The Chat icon (Microsoft Teams) on the taskbar + Chat (Microsoft Teams) installation for new users - .PARAMETER Hide - Hide the Chat icon (Microsoft Teams) on the taskbar and prevent Microsoft Teams from installing for new users + .PARAMETER Disable + Prevent Chat (Microsoft Teams) from installing for new users - .PARAMETER Show - Show the Chat icon (Microsoft Teams) on the taskbar and remove block from installing Microsoft Teams for new users + .PARAMETER Enable + Do not prevent Microsoft Teams from installing for new users .EXAMPLE - TaskbarChat -Hide + TeamsInstallation -Disable .EXAMPLE - TaskbarChat -Show + TeamsInstallation -Enable .NOTES Current user #> -function TaskbarChat +function TeamsInstallation { param ( [Parameter( Mandatory = $true, - ParameterSetName = "Hide" + ParameterSetName = "Disable" )] [switch] - $Hide, + $Disable, [Parameter( Mandatory = $true, - ParameterSetName = "Show" + ParameterSetName = "Enable" )] [switch] - $Show + $Enable ) Clear-Variable -Name Task -ErrorAction Ignore switch ($PSCmdlet.ParameterSetName) { - "Hide" + "Disable" { - New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarMn -PropertyType DWord -Value 0 -Force - # Save string to run it as "NT SERVICE\TrustedInstaller" # Prevent Microsoft Teams from installing for new users $Task = "New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications -Name ConfigureChatAutoInstall -Value 0 -Type Dword -Force" } - "Show" + "Enable" { - New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarMn -PropertyType DWord -Value 1 -Force - # Save string to run it as "NT SERVICE\TrustedInstaller" # Remove block from installing Microsoft Teams for new users $Task = "Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications -Name ConfigureChatAutoInstall -Value 1 -Type Dword -Force" @@ -10740,37 +10736,32 @@ function UninstallUWPApps $AppxPackages = @(Get-AppxPackage -PackageTypeFilter Bundle -AllUsers:$AllUsers | Where-Object -FilterScript {$_.Name -notin $ExcludedAppxPackages}) - # The Bundle packages contains no Microsoft Teams - if (Get-AppxPackage -Name MicrosoftTeams -AllUsers:$AllUsers) - { - # Temporarily hack: due to the fact that there are actually two Microsoft Teams packages, we need to choose the first one to display - $AppxPackages += Get-AppxPackage -Name MicrosoftTeams -AllUsers:$AllUsers | Select-Object -Index 0 - } + # The -PackageTypeFilter Bundle doesn't contain these packages, and we need to add manually + $Packages = @( + # Spotify + "SpotifyAB.SpotifyMusic", - # The Bundle packages contains no Spotify - if (Get-AppxPackage -Name SpotifyAB.SpotifyMusic -AllUsers:$AllUsers) - { - $AppxPackages += Get-AppxPackage -Name SpotifyAB.SpotifyMusic -AllUsers:$AllUsers - } - - # The Bundle packages contains no Disney+ - if (Get-AppxPackage -Name Disney.37853FC22B2CE -AllUsers:$AllUsers) - { - $AppxPackages += Get-AppxPackage -Name Disney.37853FC22B2CE -AllUsers:$AllUsers - } + # Disney+ + "Disney.37853FC22B2CE", - # The Bundle packages contains no Outlook - if (Get-AppxPackage -Name Microsoft.OutlookForWindows -AllUsers:$AllUsers) + # Outlook + "Microsoft.OutlookForWindows", + + # Chat (Microsoft Teams) + "MicrosoftTeams" + ) + foreach ($Package in $Packages) { - $AppxPackages += Get-AppxPackage -Name Microsoft.OutlookForWindows -AllUsers:$AllUsers + if (Get-AppxPackage -Name $Package -AllUsers:$AllUsers) + { + $AppxPackages += Get-AppxPackage -Name $Package -AllUsers:$AllUsers + } } $PackagesIds = [Windows.Management.Deployment.PackageManager]::new().FindPackages() | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name, DisplayName - foreach ($AppxPackage in $AppxPackages) { $PackageId = $PackagesIds | Where-Object -FilterScript {$_.Name -eq $AppxPackage.Name} - if (-not $PackageId) { continue @@ -11122,15 +11113,7 @@ function RestoreUWPApps # The Bundle packages contains no Microsoft Teams if (Get-AppxPackage -Name MicrosoftTeams -AllUsers) { - # Temporarily hack: due to the fact that there are actually two Microsoft Teams packages, we need to choose the first one to display - $AppxPackages += Get-AppxPackage -Name MicrosoftTeams -AllUsers | Where-Object -FilterScript {$_.PackageUserInformation -match "Staged"} | Select-Object -Index 0 - } - - # The Bundle packages contains no Spotify - if (Get-AppxPackage -Name SpotifyAB.SpotifyMusic -AllUsers) - { - # Temporarily hack: due to the fact that there are actually two Spotify packages, we need to choose the first one to display - $AppxPackages += Get-AppxPackage -Name SpotifyAB.SpotifyMusic -AllUsers | Where-Object -FilterScript {$_.PackageUserInformation -match "Staged"} | Select-Object -Index 0 + $AppxPackages += Get-AppxPackage -Name MicrosoftTeams -AllUsers | Where-Object -FilterScript {$_.PackageUserInformation -match "Staged"} } $PackagesIds = [Windows.Management.Deployment.PackageManager]::new().FindPackages() | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name, DisplayName diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 index 539654b6..6c1b9d94 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 @@ -414,13 +414,13 @@ TaskViewButton -Hide # Отобразить кнопку "Представление задач" на панели задач (значение по умолчанию) # TaskViewButton -Show -# Hide the Chat icon (Microsoft Teams) on the taskbar and prevent Microsoft Teams from installing for new users -# Скрыть кнопку чата (Microsoft Teams) с панели задач и запретить установку Microsoft Teams для новых пользователей -TaskbarChat -Hide +# Prevent Chat (Microsoft Teams) from installing for new users +# Запретить установку Chat (Microsoft Teams) для новых пользователей +TeamsInstallation -Hide # Show the Chat icon (Microsoft Teams) on the taskbar and remove block from installing Microsoft Teams for new users (default value) # Отобразить кнопку чата (Microsoft Teams) на панели задач и убрать блокировку на устанвоку Microsoft Teams для новых пользователей (значение по умолчанию) -# TaskbarChat -Show +# TeamsInstallation -Show # Show seconds on the taskbar clock # Показывать секунды на часах на панели задач