Add DeployViewModel.ps1
This commit is contained in:
@@ -0,0 +1,122 @@
|
|||||||
|
class DeployViewModel : FirefoxAddinManager.ObservableBase {
|
||||||
|
|
||||||
|
[System.Collections.ObjectModel.ObservableCollection[AddonModel]] $Addons
|
||||||
|
[System.Windows.Input.ICommand] $DeployCommand
|
||||||
|
[System.Windows.Input.ICommand] $ExportScriptCommand
|
||||||
|
[System.Windows.Input.ICommand] $DownloadXpisCommand
|
||||||
|
|
||||||
|
hidden [string] $_statusMessage = ""
|
||||||
|
hidden [bool] $_isDeploying = $false
|
||||||
|
|
||||||
|
[string] $StatusMessage {
|
||||||
|
get { return $this._statusMessage }
|
||||||
|
set { $this._statusMessage = $value; $this.OnPropertyChanged("StatusMessage") }
|
||||||
|
}
|
||||||
|
|
||||||
|
[bool] $IsDeploying {
|
||||||
|
get { return $this._isDeploying }
|
||||||
|
set { $this._isDeploying = $value; $this.OnPropertyChanged("IsDeploying") }
|
||||||
|
}
|
||||||
|
|
||||||
|
DeployViewModel() {
|
||||||
|
$this.Addons = [System.Collections.ObjectModel.ObservableCollection[AddonModel]]::new()
|
||||||
|
$this._LoadDefaultAddons()
|
||||||
|
$this._InitCommands()
|
||||||
|
}
|
||||||
|
|
||||||
|
hidden [void] _LoadDefaultAddons() {
|
||||||
|
@(
|
||||||
|
@("uBlock Origin", "uBlock0@raymondhill.net",
|
||||||
|
"https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi",
|
||||||
|
"https://addons.mozilla.org/firefox/addon/ublock-origin/", "Effizienter Werbeblocker"),
|
||||||
|
@("Dark Reader", "addon@darkreader.org",
|
||||||
|
"https://addons.mozilla.org/firefox/downloads/latest/darkreader/latest.xpi",
|
||||||
|
"https://addons.mozilla.org/firefox/addon/darkreader/", "Dunkles Design"),
|
||||||
|
@("Bitwarden", "{446900e4-71c2-419f-a6a7-df9c091e268b}",
|
||||||
|
"https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi",
|
||||||
|
"https://addons.mozilla.org/firefox/addon/bitwarden-password-manager/", "Passwort-Manager"),
|
||||||
|
@("KeePassXC", "keepassxc-browser@keepassxc.org",
|
||||||
|
"https://addons.mozilla.org/firefox/downloads/latest/keepassxc-browser/latest.xpi",
|
||||||
|
"https://addons.mozilla.org/firefox/addon/keepassxc-browser/", "KeePass-Integration"),
|
||||||
|
@("Acrobat Reader", "acrobat_reader@adobe.com",
|
||||||
|
"https://addons.mozilla.org/firefox/downloads/latest/acrobat-reader/latest.xpi",
|
||||||
|
"https://addons.mozilla.org/firefox/addon/adobe-acrobat-dc-pdf/", "PDF-Viewer"),
|
||||||
|
@("Foxit Reader", "foxitreader@foxitsoftware.com",
|
||||||
|
"https://addons.mozilla.org/firefox/downloads/latest/foxit-reader/latest.xpi",
|
||||||
|
"https://addons.mozilla.org/firefox/addon/foxit-reader/", "Foxit PDF-Viewer")
|
||||||
|
) | ForEach-Object {
|
||||||
|
$this.Addons.Add([AddonModel]::new($_[0], $_[1], $_[2], $_[3], $_[4]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hidden [void] _InitCommands() {
|
||||||
|
$vm = $this
|
||||||
|
|
||||||
|
$this.DeployCommand = [FirefoxAddinManager.RelayCommand]::new(
|
||||||
|
{
|
||||||
|
if (-not [FirefoxService]::IsAdmin()) {
|
||||||
|
[System.Windows.MessageBox]::Show(
|
||||||
|
"Administratorrechte erforderlich.", "Kein Admin",
|
||||||
|
"OK", "Warning"); return
|
||||||
|
}
|
||||||
|
$vm.IsDeploying = $true
|
||||||
|
$vm.StatusMessage = "Deploying..."
|
||||||
|
|
||||||
|
# JSON-String loeschen
|
||||||
|
[RegistryService]::RemoveJsonString()
|
||||||
|
|
||||||
|
# Wildcard setzen
|
||||||
|
[RegistryService]::SetWildcard("blocked")
|
||||||
|
|
||||||
|
# Ausgewaehlte Add-ons deployen
|
||||||
|
$count = 0
|
||||||
|
foreach ($addon in $vm.Addons) {
|
||||||
|
if ($addon.IsSelected) {
|
||||||
|
[RegistryService]::DeployAddon($addon)
|
||||||
|
$count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$vm.IsDeploying = $false
|
||||||
|
$vm.StatusMessage = "$count Add-on(s) deployed. Firefox neu starten."
|
||||||
|
},
|
||||||
|
{ return ($this.Addons | Where-Object { $_.IsSelected }).Count -gt 0 }
|
||||||
|
)
|
||||||
|
|
||||||
|
$this.ExportScriptCommand = [FirefoxAddinManager.RelayCommand]::new(
|
||||||
|
{
|
||||||
|
$selected = $vm.Addons | Where-Object { $_.IsSelected }
|
||||||
|
if (-not $selected) {
|
||||||
|
[System.Windows.MessageBox]::Show("Bitte Add-ons auswaehlen.", "Hinweis", "OK", "Information")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$dlg = New-Object Microsoft.Win32.SaveFileDialog
|
||||||
|
$dlg.Filter = "PowerShell (*.ps1)|*.ps1"
|
||||||
|
$dlg.FileName = "Deploy-FirefoxAddons.ps1"
|
||||||
|
if (-not $dlg.ShowDialog()) { return }
|
||||||
|
|
||||||
|
$lines = @(
|
||||||
|
"#Requires -RunAsAdministrator"
|
||||||
|
'$base = "HKLM:\SOFTWARE\Policies\Mozilla\Firefox\ExtensionSettings"'
|
||||||
|
'Remove-ItemProperty "HKLM:\SOFTWARE\Policies\Mozilla\Firefox" -Name ExtensionSettings -ErrorAction SilentlyContinue'
|
||||||
|
'$wc = "$base\*"; if (-not (Test-Path $wc)) { New-Item $wc -Force | Out-Null }'
|
||||||
|
'Set-ItemProperty $wc -Name installation_mode -Value blocked'
|
||||||
|
)
|
||||||
|
foreach ($a in $selected) {
|
||||||
|
$lines += ""
|
||||||
|
$lines += "# $($a.Name)"
|
||||||
|
$lines += '$k = "' + "HKLM:\SOFTWARE\Policies\Mozilla\Firefox\ExtensionSettings\$($a.Id)" + '"'
|
||||||
|
$lines += 'if (-not (Test-Path $k)) { New-Item $k -Force | Out-Null }'
|
||||||
|
$lines += 'Set-ItemProperty $k -Name installation_mode -Value force_installed'
|
||||||
|
$lines += 'Set-ItemProperty $k -Name install_url -Value "' + $a.InstallUrl + '"'
|
||||||
|
}
|
||||||
|
$lines | Out-File $dlg.FileName -Encoding UTF8
|
||||||
|
$vm.StatusMessage = "Skript exportiert: $($dlg.FileName)"
|
||||||
|
},
|
||||||
|
{ $true }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
[AddonModel[]] GetSelectedAddons() {
|
||||||
|
return @($this.Addons | Where-Object { $_.IsSelected })
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user