filter integration selection with a package name

This commit is contained in:
Wroclaw 2022-11-12 01:31:18 +01:00
parent 816ef0abe0
commit 07b04f2d8e

View file

@ -251,6 +251,14 @@ class Integration {
if ($compatiblePackage.length -eq 0 ) { return $false } if ($compatiblePackage.length -eq 0 ) { return $false }
return $compatiblePackage.Contains($version) return $compatiblePackage.Contains($version)
} }
[System.Collections.ArrayList] compatiblePackageNames() {
$rvalue =[System.Collections.ArrayList]::new($this.compatiblePackages.Count)
foreach ($i in $this.compatiblePackages) {
[void] $rvalue.Add($i.name)
}
return $rvalue
}
} }
class IntegrationList : System.Collections.ArrayList<#Integration#> { class IntegrationList : System.Collections.ArrayList<#Integration#> {
@ -302,6 +310,26 @@ class IntegrationList : System.Collections.ArrayList<#Integration#> {
} }
return $rvalue return $rvalue
} }
[FormItems] getForm([String] $packageName) {
$rvalue = [FormItems]::new()
foreach ($i in $this) {
if (-not $i.compatiblePackageNames().Contains($packageName)) { continue }
[void] $rvalue.Add([FormItem]::new($i.name, "$($i.name) - $($i.description)"))
}
return $rvalue
}
[System.Collections.ArrayList] getAllCompatiblePackagesNames() {
$rvalue = [System.Collections.ArrayList]::new()
foreach ($i in $this) {
foreach ($j in $i.compatiblePackages) {
if ($rvalue.Contains($j.name)) { continue }
[void] $rvalue.Add($j.name)
}
}
return $rvalue
}
} }
function main { function main {
@ -348,10 +376,17 @@ function main {
$integrations = [IntegrationList]::new(".\app\revanced-patches.json") $integrations = [IntegrationList]::new(".\app\revanced-patches.json")
# get package name
# FIXME: How to extract package name from its apk file?
$packageNamesForm = [FormItems]::new($integrations.getAllCompatiblePackagesNames())
$packageName = renderForm -items $packageNamesForm -label "Which package is it?" -title "Installer for ReVanced - package name" -mode One
# integrations selector # integrations selector
$integrationsToInclude = [System.Collections.ArrayList]::new() $integrationsToInclude = [System.Collections.ArrayList]::new()
$integrationsForm = $integrations.getForm() $integrationsForm = $integrations.getForm($packageName)
for ($i = 0; $i -lt $integrationsForm.Count; $i++) { for ($i = 0; $i -lt $integrationsForm.Count; $i++) {
if (-not $config.config.included.Contains($integrationsForm[$i].value)) { continue } if (-not $config.config.included.Contains($integrationsForm[$i].value)) { continue }
$integrationsForm[$i].selected = $true $integrationsForm[$i].selected = $true