Import and export process rules

This commit is contained in:
dyhkwong
2026-04-18 10:38:29 +08:00
parent b12a4b7ee2
commit 2c5046ca9c
2 changed files with 17 additions and 3 deletions

View File

@@ -187,6 +187,7 @@ class RouteFragment : ToolbarFragment(R.layout.layout_route), Toolbar.OnMenuItem
domains = Gson().fromJson(it, Array<String>::class.java).mapNotNull { it.trim().ifBlank { null } }.joinToString("\n")
}
rawRule.get("ip")?.takeIf { !it.isJsonNull }?.let {
// Fuck https://github.com/XTLS/Xray-core/pull/5951, I don't care about it.
ip = Gson().fromJson(it, Array<String>::class.java).mapNotNull { it.trim().ifBlank { null } }.joinToString("\n")
}
port = rawRule.get("port")?.takeIf { !it.isJsonNull }?.asString?.trim() ?: ""
@@ -199,6 +200,9 @@ class RouteFragment : ToolbarFragment(R.layout.layout_route), Toolbar.OnMenuItem
rawRule.get("protocol")?.takeIf { !it.isJsonNull }?.let {
protocol = Gson().fromJson(it, Array<String>::class.java).mapNotNull { it.trim().ifBlank { null } }.joinToString("\n")
}
rawRule.get("process")?.takeIf { !it.isJsonNull }?.let {
packages = Gson().fromJson(it, Array<String>::class.java).mapNotNull { it.trim().ifBlank { null } }
}
})
}
if (rules.isNotEmpty()) {
@@ -242,7 +246,14 @@ class RouteFragment : ToolbarFragment(R.layout.layout_route), Toolbar.OnMenuItem
}
}
}
if (rule.domains.isEmpty() && rule.ip.isEmpty() && rule.port.isEmpty() && protocols.isEmpty) {
val processes = JsonArray().apply {
if (rule.customPackageNames.isNotEmpty()) {
rule.customPackageNames.forEach { if (it.toIntOrNull() != null) add(it) }
} else if (rule.packages.isNotEmpty()) {
rule.packages.forEach { add(it) }
}
}
if (rule.domains.isEmpty() && rule.ip.isEmpty() && rule.port.isEmpty() && protocols.isEmpty && processes.isEmpty) {
continue
}
jsonArray.add(JsonObject().apply {
@@ -279,6 +290,9 @@ class RouteFragment : ToolbarFragment(R.layout.layout_route), Toolbar.OnMenuItem
if (!protocols.isEmpty) {
add("protocol", protocols)
}
if (!processes.isEmpty) {
add("process", processes)
}
})
}
if (!jsonArray.isEmpty) {

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="license_gpl_v3_only" translatable="false">Copyright (C) 2023 dyhkwong\nCopyright (C) 2021 by nekohasekai &lt;contact-sagernet@sekai.icu&gt;\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</string>
<string name="license_gpl_v3_or_later" translatable="false">Copyright (C) 2023 dyhkwong\nCopyright (C) 2021 by nekohasekai &lt;contact-sagernet@sekai.icu&gt;\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</string>
<string name="license_gpl_v3_only" translatable="false">Copyright (C) 2023\u0020 dyhkwong\nCopyright (C) 2021 by nekohasekai &lt;contact-sagernet@sekai.icu&gt;\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</string>
<string name="license_gpl_v3_or_later" translatable="false">Copyright (C) 2023\u0020 dyhkwong\nCopyright (C) 2021 by nekohasekai &lt;contact-sagernet@sekai.icu&gt;\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</string>
</resources>