handle error when edge has never been opened before #82

This commit is contained in:
zoicware
2025-12-16 22:25:53 -05:00
committed by GitHub
parent fcc67f686e
commit 3d8aab5fa1

View File

@@ -275,29 +275,36 @@ function Disable-Registry-Keys {
#powershell core bug where json that has empty strings will error
$jsonContent = (Get-Content $config).Replace('""', '"_empty"') | ConvertFrom-Json
if (($jsonContent.browser | Get-Member -MemberType NoteProperty enabled_labs_experiments) -eq $null) {
$jsonContent.browser | Add-Member -MemberType NoteProperty -Name enabled_labs_experiments -Value @()
}
$flags = @(
'edge-copilot-mode@2',
'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 }
}
else {
foreach ($flag in $flags) {
if ($jsonContent.browser.enabled_labs_experiments -notcontains $flag) {
$jsonContent.browser.enabled_labs_experiments += $flag
try {
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',
'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 }
}
else {
foreach ($flag in $flags) {
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