Support hiding app from Recents screen (#663)

This commit is contained in:
Zongle Wang
2026-02-09 15:59:03 +08:00
committed by GitHub
parent bd042125c5
commit 232f318bde
6 changed files with 37 additions and 0 deletions

View File

@@ -1,11 +1,13 @@
package com.github.kr328.clash package com.github.kr328.clash
import android.app.ActivityManager
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.activity.result.contract.ActivityResultContract import androidx.activity.result.contract.ActivityResultContract
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
import com.github.kr328.clash.common.compat.isAllowForceDarkCompat import com.github.kr328.clash.common.compat.isAllowForceDarkCompat
import com.github.kr328.clash.common.compat.isLightNavigationBarCompat import com.github.kr328.clash.common.compat.isLightNavigationBarCompat
import com.github.kr328.clash.common.compat.isLightStatusBarsCompat import com.github.kr328.clash.common.compat.isLightStatusBarsCompat
@@ -88,6 +90,11 @@ abstract class BaseActivity<D : Design<*>> : AppCompatActivity(),
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
applyDayNight() applyDayNight()
// Apply excludeFromRecents setting to all app tasks.
checkNotNull(getSystemService<ActivityManager>()).appTasks.forEach { task ->
task.setExcludeFromRecents(uiStore.hideFromRecents)
}
launch { launch {
main() main()
} }

View File

@@ -77,6 +77,17 @@ class AppSettingsDesign(
} }
} }
switch(
value = uiStore::hideFromRecents,
icon = R.drawable.ic_baseline_stack,
title = R.string.hide_from_recents_title,
summary = R.string.hide_from_recents_desc,
) {
listener = OnChangedListener {
requests.trySend(Request.ReCreateAllActivities)
}
}
category(R.string.service) category(R.string.service)
switch( switch(

View File

@@ -30,6 +30,11 @@ class UiStore(context: Context) {
defaultValue = false defaultValue = false
) )
var hideFromRecents: Boolean by store.boolean(
key = "hide_from_recents",
defaultValue = false,
)
var proxyExcludeNotSelectable by store.boolean( var proxyExcludeNotSelectable by store.boolean(
key = "proxy_exclude_not_selectable", key = "proxy_exclude_not_selectable",
defaultValue = false, defaultValue = false,

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:fillColor="@android:color/white"
android:pathData="M1024,320 L512,64 0,320l512,256L1024,320zM512,149 L854,320 512,491 170,320 512,149zM921.4,460.7 L1024,512 512,768 0,512 102.6,460.7 512,665.4ZM921.4,652.7 L1024,704 512,960 0,704 102.6,652.7 512,857.4Z" />
</vector>

View File

@@ -39,6 +39,8 @@
<string name="global_mode">全局模式</string> <string name="global_mode">全局模式</string>
<string name="hide_app_icon_title">隐藏应用图标</string> <string name="hide_app_icon_title">隐藏应用图标</string>
<string name="hide_app_icon_desc">可以在拨号盘输入 *#*#252746382#*#* 打开应用</string> <string name="hide_app_icon_desc">可以在拨号盘输入 *#*#252746382#*#* 打开应用</string>
<string name="hide_from_recents_title">从最近任务隐藏</string>
<string name="hide_from_recents_desc">在最近任务中隐藏应用</string>
<string name="history">历史</string> <string name="history">历史</string>
<string name="import_from_file">从文件导入</string> <string name="import_from_file">从文件导入</string>
<string name="import_from_url">从 URL 导入</string> <string name="import_from_url">从 URL 导入</string>

View File

@@ -346,6 +346,8 @@
<string name="hide_app_icon_title">Hide App Icon</string> <string name="hide_app_icon_title">Hide App Icon</string>
<string name="hide_app_icon_desc">You can dial *#*#252746382#*#* to open this App</string> <string name="hide_app_icon_desc">You can dial *#*#252746382#*#* to open this App</string>
<string name="hide_from_recents_title">Hide from Recents</string>
<string name="hide_from_recents_desc">Hide app from the Recent apps screen</string>
<string name="import_from_qr_no_permission">Camera access is restricted. Please enable it in Settings.</string> <string name="import_from_qr_no_permission">Camera access is restricted. Please enable it in Settings.</string>
<string name="import_from_qr_exception">An unhandled system exception occurred.</string> <string name="import_from_qr_exception">An unhandled system exception occurred.</string>
</resources> </resources>