Skip to content

Commit 44bfc88

Browse files
NoahCodeGGhamjin
authored andcommitted
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 Signed-off-by: hamjin <jinham@qq.com>
1 parent a15f881 commit 44bfc88

8 files changed

Lines changed: 68 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ gradle-app.setting
2626
!/core/src/foss/golang/.idea/codeStyles
2727
/core/src/premium/golang/.idea/*
2828
!/core/src/premium/golang/.idea/codeStyles
29+
/core/src/main/cpp/version.h
2930

3031
# Ignore builtin geofiles
3132
app/src/main/assets

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import android.content.pm.PackageManager
44
import android.os.Build
55
import android.os.Bundle
66
import android.os.PersistableBundle
7+
import android.app.ActivityManager
78
import androidx.activity.result.contract.ActivityResultContracts
89
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
910
import androidx.core.app.ActivityCompat
1011
import androidx.core.content.ContextCompat
12+
import androidx.lifecycle.lifecycleScope
1113
import com.github.kr328.clash.common.util.intent
1214
import com.github.kr328.clash.common.util.ticker
15+
import com.github.kr328.clash.core.bridge.Bridge
1316
import com.github.kr328.clash.design.MainDesign
1417
import com.github.kr328.clash.design.ui.ToastDuration
1518
import com.github.kr328.clash.util.startClashService
@@ -19,6 +22,7 @@ import com.github.kr328.clash.util.withProfile
1922
import com.github.kr328.clash.core.bridge.*
2023
import kotlinx.coroutines.Dispatchers
2124
import kotlinx.coroutines.isActive
25+
import kotlinx.coroutines.launch
2226
import kotlinx.coroutines.selects.select
2327
import kotlinx.coroutines.withContext
2428
import java.util.concurrent.TimeUnit
@@ -157,6 +161,14 @@ class MainActivity : BaseActivity<MainDesign>() {
157161
requestPermissionLauncher.launch(android.Manifest.permission.POST_NOTIFICATIONS)
158162
}
159163
}
164+
165+
lifecycleScope.launch {
166+
(getSystemService(ACTIVITY_SERVICE) as ActivityManager).let { manager ->
167+
manager.appTasks.forEach { task ->
168+
task?.setExcludeFromRecents(uiStore.excludeFromRecents)
169+
}
170+
}
171+
}
160172
}
161173
}
162174

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

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

80+
switch(
81+
value = uiStore::excludeFromRecents,
82+
icon = R.drawable.eye_off,
83+
title = R.string.exclude_from_recents,
84+
summary = R.string.exclude_from_recents_summary,
85+
)
86+
8087
category(R.string.service)
8188

8289
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
@@ -67,6 +67,11 @@ class UiStore(context: Context) {
6767
defaultValue = false,
6868
)
6969

70+
var excludeFromRecents: Boolean by store.boolean(
71+
key = "exclude_from_recents",
72+
defaultValue = false
73+
)
74+
7075
companion object {
7176
private const val PREFERENCE_NAME = "ui"
7277
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:pathData="M10.733,5.076a10.744,10.744 0,0 1,11.205 6.575,1 1,0 0,1 0,0.696 10.747,10.747 0,0 1,-1.444 2.49"
8+
android:strokeLineJoin="round"
9+
android:strokeWidth="2"
10+
android:fillColor="#00000000"
11+
android:strokeColor="#ffffff"
12+
android:strokeLineCap="round"/>
13+
<path
14+
android:pathData="M14.084,14.158a3,3 0,0 1,-4.242 -4.242"
15+
android:strokeLineJoin="round"
16+
android:strokeWidth="2"
17+
android:fillColor="#00000000"
18+
android:strokeColor="#ffffff"
19+
android:strokeLineCap="round"/>
20+
<path
21+
android:pathData="M17.479,17.499a10.75,10.75 0,0 1,-15.417 -5.151,1 1,0 0,1 0,-0.696 10.75,10.75 0,0 1,4.446 -5.143"
22+
android:strokeLineJoin="round"
23+
android:strokeWidth="2"
24+
android:fillColor="#00000000"
25+
android:strokeColor="#ffffff"
26+
android:strokeLineCap="round"/>
27+
<path
28+
android:pathData="m2,2 l20,20"
29+
android:strokeLineJoin="round"
30+
android:strokeWidth="2"
31+
android:fillColor="#00000000"
32+
android:strokeColor="#ffffff"
33+
android:strokeLineCap="round"/>
34+
</vector>

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
<string name="tun_stack_mixed">Mixed</string>
1212
<string name="tun_stack_mode">Chế độ xếp chồng dữ liệu</string>
1313
<string name="tun_stack_system">Hệ thống</string>
14-
<string name="application_name_alpha">Clash Meta</string>
15-
<string name="application_name_meta">Clash Meta</string>
1614
<string name="clash_meta_core">Clash Meta Core</string>
1715
<string name="clash_meta_for_android">Clash Meta</string>
1816
<string name="clash_meta_wiki">Clash Meta Wiki</string>
19-
<string name="launch_name_alpha">Clash Meta</string>
20-
<string name="launch_name_meta">Clash Meta</string>
2117
<string name="_new">Mới</string>
2218
<string name="about">Thông tin</string>
2319
<string name="accept_http_content">Chỉ chấp nhận http(s)</string>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
<string name="properties">参数</string>
5959
<string name="proxy">代理</string>
6060
<string name="recently">近期</string>
61+
<string name="exclude_from_recents">后台隐藏</string>
62+
<string name="exclude_from_recents_summary">在[最近任务]中隐藏本应用</string>
6163
<string name="route_system_traffic">自动路由系统流量</string>
6264
<string name="routing_via_vpn_service">通过 VpnService 自动路由所有系统流量</string>
6365
<string name="rule_mode">规则模式</string>

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="PluralsCandidate">
2-
<string name="launch_name_meta">Clash Meta</string>
3-
<string name="launch_name_alpha">Clash Meta Alpha</string>
4-
<string name="application_name_meta">Clash Meta for Android</string>
5-
<string name="application_name_alpha">Clash Meta for Android Alpha</string>
2+
<string name="launch_name_meta" translatable="false">Clash Meta</string>
3+
<string name="launch_name_alpha" translatable="false">Clash Meta Alpha</string>
4+
<string name="application_name_meta" translatable="false">Clash Meta for Android</string>
5+
<string name="application_name_alpha" translatable="false">Clash Meta for Android Alpha</string>
66

77
<string name="stopped">Stopped</string>
88
<string name="tap_to_start">Tap to start</string>
@@ -112,6 +112,9 @@
112112
<string name="auto_restart">Auto Restart</string>
113113
<string name="allow_clash_auto_restart">Allow clash auto restart</string>
114114

115+
<string name="exclude_from_recents">Exclude From Recents</string>
116+
<string name="exclude_from_recents_summary">Hide this app in Recent Tasks</string>
117+
115118
<string name="route_system_traffic">Route System Traffic</string>
116119
<string name="routing_via_vpn_service">Auto routing all system traffic via VpnService</string>
117120

0 commit comments

Comments
 (0)