Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
farag2 committed Dec 14, 2023
1 parent 2c4df02 commit 10f2cc1
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 119 deletions.
6 changes: 3 additions & 3 deletions Wrapper/Config/config_Windows_11.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions Wrapper/Localizations/de-DE/tooltip_Windows_11.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions Wrapper/Localizations/en-US/tooltip_Windows_11.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions Wrapper/Localizations/ru-RU/tooltip_Windows_11.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 для новых пользователей (значение по умолчанию)."
}
}
Expand Down
81 changes: 32 additions & 49 deletions src/Sophia_Script_for_Windows_11/Module/Sophia.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Sophia_Script_for_Windows_11/Sophia.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Показывать секунды на часах на панели задач
Expand Down
81 changes: 32 additions & 49 deletions src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Показывать секунды на часах на панели задач
Expand Down

0 comments on commit 10f2cc1

Please sign in to comment.