From 2c5046ca9caa6e37186db7ed8f6976caaa7df364 Mon Sep 17 00:00:00 2001 From: dyhkwong <50692134+dyhkwong@users.noreply.github.com> Date: Sat, 18 Apr 2026 10:38:29 +0800 Subject: [PATCH] Import and export process rules --- .../io/nekohasekai/sagernet/ui/RouteFragment.kt | 16 +++++++++++++++- app/src/main/res/values/license.xml | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/nekohasekai/sagernet/ui/RouteFragment.kt b/app/src/main/java/io/nekohasekai/sagernet/ui/RouteFragment.kt index ffb5292d..8cbfc80e 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/ui/RouteFragment.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/ui/RouteFragment.kt @@ -187,6 +187,7 @@ class RouteFragment : ToolbarFragment(R.layout.layout_route), Toolbar.OnMenuItem domains = Gson().fromJson(it, Array::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::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::class.java).mapNotNull { it.trim().ifBlank { null } }.joinToString("\n") } + rawRule.get("process")?.takeIf { !it.isJsonNull }?.let { + packages = Gson().fromJson(it, Array::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) { diff --git a/app/src/main/res/values/license.xml b/app/src/main/res/values/license.xml index 6f253252..86b986c0 100644 --- a/app/src/main/res/values/license.xml +++ b/app/src/main/res/values/license.xml @@ -1,5 +1,5 @@ - Copyright (C) 2023 dyhkwong\nCopyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu>\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 <https://www.gnu.org/licenses/>. - Copyright (C) 2023 dyhkwong\nCopyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu>\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 <https://www.gnu.org/licenses/>. + Copyright (C) 2023\u0020 dyhkwong\nCopyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu>\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 <https://www.gnu.org/licenses/>. + Copyright (C) 2023\u0020 dyhkwong\nCopyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu>\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 <https://www.gnu.org/licenses/>. \ No newline at end of file