From 07b04f2d8efa2863d0df483cb0ffe69f9d136f08 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sat, 12 Nov 2022 01:31:18 +0100 Subject: [PATCH] filter integration selection with a package name --- revanced.ps1 | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/revanced.ps1 b/revanced.ps1 index e498c8f..83c0399 100644 --- a/revanced.ps1 +++ b/revanced.ps1 @@ -251,6 +251,14 @@ class Integration { if ($compatiblePackage.length -eq 0 ) { return $false } 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#> { @@ -302,6 +310,26 @@ class IntegrationList : System.Collections.ArrayList<#Integration#> { } 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 { @@ -348,10 +376,17 @@ function main { $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 $integrationsToInclude = [System.Collections.ArrayList]::new() - $integrationsForm = $integrations.getForm() + $integrationsForm = $integrations.getForm($packageName) for ($i = 0; $i -lt $integrationsForm.Count; $i++) { if (-not $config.config.included.Contains($integrationsForm[$i].value)) { continue } $integrationsForm[$i].selected = $true