From 135cdf78d6b2a77394a7b85d64489d2627bcd8dc Mon Sep 17 00:00:00 2001 From: NoahCode Date: Mon, 25 Nov 2024 23:53:01 +0800 Subject: [PATCH 1/2] feat/ui: add option to exclude app from recent tasks - Add excludeFromRecents boolean preference to UiStore- Implement logic to hide app from recent tasks in MainActivity - Add switch for excludeFromRecents in AppSettingsDesign - Update strings.xml files with new translation for excludeFromRecents - Remove unnecessary translations for launch_name and application_name - Update gradle-wrapper.properties to remove distributionSha256Sum - Add version.h to .gitignore --- .gitignore | 1 + .../com/github/kr328/clash/MainActivity.kt | 18 +++++++++- .../kr328/clash/design/AppSettingsDesign.kt | 7 ++++ .../kr328/clash/design/store/UiStore.kt | 5 +++ design/src/main/res/drawable/eye_off.xml | 34 +++++++++++++++++++ design/src/main/res/values-vi/strings.xml | 4 --- design/src/main/res/values-zh/strings.xml | 2 ++ design/src/main/res/values/strings.xml | 11 +++--- gradle/wrapper/gradle-wrapper.properties | 3 +- 9 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 design/src/main/res/drawable/eye_off.xml diff --git a/.gitignore b/.gitignore index a169a3969..7aeb95144 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ gradle-app.setting !/core/src/foss/golang/.idea/codeStyles /core/src/premium/golang/.idea/* !/core/src/premium/golang/.idea/codeStyles +/core/src/main/cpp/version.h # Ignore builtin geofiles app/src/main/assets diff --git a/app/src/main/java/com/github/kr328/clash/MainActivity.kt b/app/src/main/java/com/github/kr328/clash/MainActivity.kt index dac301763..bfe256c49 100644 --- a/app/src/main/java/com/github/kr328/clash/MainActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/MainActivity.kt @@ -1,22 +1,38 @@ package com.github.kr328.clash +import android.app.ActivityManager +import android.os.Bundle import androidx.activity.result.contract.ActivityResultContracts +import androidx.lifecycle.lifecycleScope import com.github.kr328.clash.common.util.intent import com.github.kr328.clash.common.util.ticker +import com.github.kr328.clash.core.bridge.Bridge import com.github.kr328.clash.design.MainDesign import com.github.kr328.clash.design.ui.ToastDuration import com.github.kr328.clash.util.startClashService import com.github.kr328.clash.util.stopClashService import com.github.kr328.clash.util.withClash import com.github.kr328.clash.util.withProfile -import com.github.kr328.clash.core.bridge.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.isActive +import kotlinx.coroutines.launch import kotlinx.coroutines.selects.select import kotlinx.coroutines.withContext import java.util.concurrent.TimeUnit class MainActivity : BaseActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + lifecycleScope.launch { + (getSystemService(ACTIVITY_SERVICE) as ActivityManager).let { manager -> + manager.appTasks.forEach { task -> + task?.setExcludeFromRecents(uiStore.excludeFromRecents) + } + } + } + } + override suspend fun main() { val design = MainDesign(this) diff --git a/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt b/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt index ad296de55..aa8e597ee 100644 --- a/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt @@ -65,6 +65,13 @@ class AppSettingsDesign( } } + switch( + value = uiStore::excludeFromRecents, + icon = R.drawable.eye_off, + title = R.string.exclude_from_recents, + summary = R.string.exclude_from_recents_summary, + ) + category(R.string.service) switch( diff --git a/design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt b/design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt index f0202a645..87ee7e624 100644 --- a/design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt +++ b/design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt @@ -62,6 +62,11 @@ class UiStore(context: Context) { defaultValue = false, ) + var excludeFromRecents: Boolean by store.boolean( + key = "exclude_from_recents", + defaultValue = false + ) + companion object { private const val PREFERENCE_NAME = "ui" } diff --git a/design/src/main/res/drawable/eye_off.xml b/design/src/main/res/drawable/eye_off.xml new file mode 100644 index 000000000..13f8c6821 --- /dev/null +++ b/design/src/main/res/drawable/eye_off.xml @@ -0,0 +1,34 @@ + + + + + + diff --git a/design/src/main/res/values-vi/strings.xml b/design/src/main/res/values-vi/strings.xml index 2ff4f708c..6c446b5a1 100644 --- a/design/src/main/res/values-vi/strings.xml +++ b/design/src/main/res/values-vi/strings.xml @@ -11,13 +11,9 @@ Mixed Chế độ xếp chồng dữ liệu Hệ thống - Clash Meta - Clash Meta Clash Meta Core Clash Meta Clash Meta Wiki - Clash Meta - Clash Meta Mới Thông tin Chỉ chấp nhận http(s) diff --git a/design/src/main/res/values-zh/strings.xml b/design/src/main/res/values-zh/strings.xml index cf60e1e13..926889ad7 100644 --- a/design/src/main/res/values-zh/strings.xml +++ b/design/src/main/res/values-zh/strings.xml @@ -56,6 +56,8 @@ 参数 代理 近期 + 后台隐藏 + 在[最近任务]中隐藏本应用 自动路由系统流量 通过 VpnService 自动路由所有系统流量 规则模式 diff --git a/design/src/main/res/values/strings.xml b/design/src/main/res/values/strings.xml index 622adbb94..5616ec653 100644 --- a/design/src/main/res/values/strings.xml +++ b/design/src/main/res/values/strings.xml @@ -1,8 +1,8 @@ - Clash Meta - Clash Meta Alpha - Clash Meta for Android - Clash Meta for Android Alpha + Clash Meta + Clash Meta Alpha + Clash Meta for Android + Clash Meta for Android Alpha Stopped Tap to start @@ -112,6 +112,9 @@ Auto Restart Allow clash auto restart + Exclude From Recents + Hide this app in Recent Tasks + Route System Traffic Auto routing all system traffic via VpnService diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 50955b7f0..c5eedd511 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -4,5 +4,4 @@ distributionSha256Sum=fe696c020f241a5f69c30f763c5a7f38eec54b490db19cd2b0962dda42 distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-all.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionSha256Sum=fe696c020f241a5f69c30f763c5a7f38eec54b490db19cd2b0962dda420d7d12 \ No newline at end of file +zipStorePath=wrapper/dists \ No newline at end of file From e18adfc030f9d90220ffbd64da826c67423ec3aa Mon Sep 17 00:00:00 2001 From: NoahCode Date: Tue, 26 Nov 2024 10:38:09 +0800 Subject: [PATCH 2/2] feat(design): implement real-time update for exclude from recents setting - Add OnChangedListener to excludeFromRecents setting item - Update exclude from recents status for all app tasks when setting changes - Use ActivityManager to access and modify app tasks --- .../github/kr328/clash/design/AppSettingsDesign.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt b/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt index aa8e597ee..230f5046b 100644 --- a/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt @@ -1,5 +1,6 @@ package com.github.kr328.clash.design +import android.app.ActivityManager import android.content.Context import android.view.View import com.github.kr328.clash.design.databinding.DesignSettingsCommonBinding @@ -70,7 +71,15 @@ class AppSettingsDesign( icon = R.drawable.eye_off, title = R.string.exclude_from_recents, summary = R.string.exclude_from_recents_summary, - ) + ) { + listener = OnChangedListener { + (context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).let { manager -> + manager.appTasks.forEach { task -> + task?.setExcludeFromRecents(uiStore.excludeFromRecents) + } + } + } + } category(R.string.service)