mirror of
https://github.com/zoicware/RemoveWindowsAI.git
synced 2025-12-17 15:16:27 +01:00
handle error when edge has never been opened before #82
This commit is contained in:
@@ -275,29 +275,36 @@ function Disable-Registry-Keys {
|
|||||||
#powershell core bug where json that has empty strings will error
|
#powershell core bug where json that has empty strings will error
|
||||||
$jsonContent = (Get-Content $config).Replace('""', '"_empty"') | ConvertFrom-Json
|
$jsonContent = (Get-Content $config).Replace('""', '"_empty"') | ConvertFrom-Json
|
||||||
|
|
||||||
if (($jsonContent.browser | Get-Member -MemberType NoteProperty enabled_labs_experiments) -eq $null) {
|
try {
|
||||||
$jsonContent.browser | Add-Member -MemberType NoteProperty -Name enabled_labs_experiments -Value @()
|
if (($jsonContent.browser | Get-Member -MemberType NoteProperty enabled_labs_experiments -ErrorAction Stop) -eq $null) {
|
||||||
}
|
$jsonContent.browser | Add-Member -MemberType NoteProperty -Name enabled_labs_experiments -Value @()
|
||||||
$flags = @(
|
}
|
||||||
'edge-copilot-mode@2',
|
$flags = @(
|
||||||
'edge-ntp-composer@2', #disables the copilot search in new tab page
|
'edge-copilot-mode@2',
|
||||||
'edge-compose@2' #disables the ai writing help
|
'edge-ntp-composer@2', #disables the copilot search in new tab page
|
||||||
)
|
'edge-compose@2' #disables the ai writing help
|
||||||
if ($revert) {
|
)
|
||||||
$jsonContent.browser.enabled_labs_experiments = $jsonContent.browser.enabled_labs_experiments | Where-Object { $_ -notin $flags }
|
if ($revert) {
|
||||||
}
|
$jsonContent.browser.enabled_labs_experiments = $jsonContent.browser.enabled_labs_experiments | Where-Object { $_ -notin $flags }
|
||||||
else {
|
}
|
||||||
foreach ($flag in $flags) {
|
else {
|
||||||
if ($jsonContent.browser.enabled_labs_experiments -notcontains $flag) {
|
foreach ($flag in $flags) {
|
||||||
$jsonContent.browser.enabled_labs_experiments += $flag
|
if ($jsonContent.browser.enabled_labs_experiments -notcontains $flag) {
|
||||||
|
$jsonContent.browser.enabled_labs_experiments += $flag
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$newContent = $jsonContent | ConvertTo-Json -Compress -Depth 10
|
||||||
|
#add back the empty strings
|
||||||
|
$newContent = $newContent.replace('"_empty"', '""')
|
||||||
|
Set-Content $config -Value $newContent -Encoding UTF8 -Force
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Status -msg 'Edge Browser has never been opened on this machine unable to set flags...' -errorOutput $true
|
||||||
|
Write-Status -msg 'Open Edge once and run this tweak again' -errorOutput $true
|
||||||
}
|
}
|
||||||
|
|
||||||
$newContent = $jsonContent | ConvertTo-Json -Compress -Depth 10
|
|
||||||
#add back the empty strings
|
|
||||||
$newContent = $newContent.replace('"_empty"', '""')
|
|
||||||
Set-Content $config -Value $newContent -Encoding UTF8 -Force
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#disable office ai with group policy
|
#disable office ai with group policy
|
||||||
|
|||||||
Reference in New Issue
Block a user