Skip to content

Commit 232f318

Browse files
authored
Support hiding app from Recents screen (#663)
1 parent bd04212 commit 232f318

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

app/src/main/java/com/github/kr328/clash/BaseActivity.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.github.kr328.clash
22

3+
import android.app.ActivityManager
34
import android.content.res.Configuration
45
import android.os.Build
56
import android.os.Bundle
67
import android.view.View
78
import androidx.activity.result.contract.ActivityResultContract
89
import androidx.appcompat.app.AppCompatActivity
10+
import androidx.core.content.getSystemService
911
import com.github.kr328.clash.common.compat.isAllowForceDarkCompat
1012
import com.github.kr328.clash.common.compat.isLightNavigationBarCompat
1113
import com.github.kr328.clash.common.compat.isLightStatusBarsCompat
@@ -88,6 +90,11 @@ abstract class BaseActivity<D : Design<*>> : AppCompatActivity(),
8890
super.onCreate(savedInstanceState)
8991
applyDayNight()
9092

93+
// Apply excludeFromRecents setting to all app tasks.
94+
checkNotNull(getSystemService<ActivityManager>()).appTasks.forEach { task ->
95+
task.setExcludeFromRecents(uiStore.hideFromRecents)
96+
}
97+
9198
launch {
9299
main()
93100
}

design/src/main/java/com/github/kr328/clash/design/AppSettingsDesign.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ class AppSettingsDesign(
7777
}
7878
}
7979

80+
switch(
81+
value = uiStore::hideFromRecents,
82+
icon = R.drawable.ic_baseline_stack,
83+
title = R.string.hide_from_recents_title,
84+
summary = R.string.hide_from_recents_desc,
85+
) {
86+
listener = OnChangedListener {
87+
requests.trySend(Request.ReCreateAllActivities)
88+
}
89+
}
90+
8091
category(R.string.service)
8192

8293
switch(

design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class UiStore(context: Context) {
3030
defaultValue = false
3131
)
3232

33+
var hideFromRecents: Boolean by store.boolean(
34+
key = "hide_from_recents",
35+
defaultValue = false,
36+
)
37+
3338
var proxyExcludeNotSelectable by store.boolean(
3439
key = "proxy_exclude_not_selectable",
3540
defaultValue = false,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportWidth="1024"
6+
android:viewportHeight="1024">
7+
<path
8+
android:fillColor="@android:color/white"
9+
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" />
10+
</vector>

design/src/main/res/values-zh/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
<string name="global_mode">全局模式</string>
4040
<string name="hide_app_icon_title">隐藏应用图标</string>
4141
<string name="hide_app_icon_desc">可以在拨号盘输入 *#*#252746382#*#* 打开应用</string>
42+
<string name="hide_from_recents_title">从最近任务隐藏</string>
43+
<string name="hide_from_recents_desc">在最近任务中隐藏应用</string>
4244
<string name="history">历史</string>
4345
<string name="import_from_file">从文件导入</string>
4446
<string name="import_from_url">从 URL 导入</string>

design/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@
346346

347347
<string name="hide_app_icon_title">Hide App Icon</string>
348348
<string name="hide_app_icon_desc">You can dial *#*#252746382#*#* to open this App</string>
349+
<string name="hide_from_recents_title">Hide from Recents</string>
350+
<string name="hide_from_recents_desc">Hide app from the Recent apps screen</string>
349351
<string name="import_from_qr_no_permission">Camera access is restricted. Please enable it in Settings.</string>
350352
<string name="import_from_qr_exception">An unhandled system exception occurred.</string>
351353
</resources>

0 commit comments

Comments
 (0)