From fa6caaf33eed69f8262d2a46e9379c253c79fd61 Mon Sep 17 00:00:00 2001 From: Marco Wende Date: Wed, 10 Jun 2026 21:57:53 +0200 Subject: [PATCH] Add FirefoxService.ps1 --- MVVM/Services/FirefoxService.ps1 | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 MVVM/Services/FirefoxService.ps1 diff --git a/MVVM/Services/FirefoxService.ps1 b/MVVM/Services/FirefoxService.ps1 new file mode 100644 index 0000000..d438ec2 --- /dev/null +++ b/MVVM/Services/FirefoxService.ps1 @@ -0,0 +1,55 @@ +class FirefoxService { + + static [string] FindInstallDir() { + $candidates = @( + "C:\Program Files\Mozilla Firefox", + "C:\Program Files (x86)\Mozilla Firefox" + ) + foreach ($c in $candidates) { + if (Test-Path (Join-Path $c "firefox.exe")) { return $c } + } + try { + $reg = Get-ItemProperty "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox" -ErrorAction Stop + if ($reg."Install Directory" -and (Test-Path $reg."Install Directory")) { + return $reg."Install Directory" + } + } catch {} + return $null + } + + static [string] FindProfile() { + $profilesPath = Join-Path ([Environment]::GetFolderPath("ApplicationData")) "Mozilla\Firefox\Profiles" + if (-not (Test-Path $profilesPath)) { return $null } + $profiles = Get-ChildItem $profilesPath -Directory | + Where-Object { $_.Name -match '\.default|default-release' } + if ($profiles) { return $profiles[0].FullName } + $all = Get-ChildItem $profilesPath -Directory + if ($all) { return $all[0].FullName } + return $null + } + + static [bool] IsRunning() { + return [bool](Get-Process -Name "firefox" -ErrorAction SilentlyContinue) + } + + static [bool] IsAdmin() { + $id = [System.Security.Principal.WindowsIdentity]::GetCurrent() + return (New-Object System.Security.Principal.WindowsPrincipal($id)).IsInRole( + [System.Security.Principal.WindowsBuiltInRole]::Administrator) + } + + static [bool] IsIntuneManaged() { + $key = "HKLM:\SOFTWARE\Policies\Mozilla\Firefox" + if (Test-Path $key) { + return [bool](Get-ItemProperty $key -ErrorAction SilentlyContinue) + } + return $false + } + + static [object[]] GetInstalledAddons([string]$profilePath) { + $json = Join-Path $profilePath "extensions.json" + if (-not (Test-Path $json)) { return @() } + return (Get-Content $json -Raw | ConvertFrom-Json).addons | + Where-Object { $_.type -eq "extension" } + } +}