File tree Expand file tree Collapse file tree
app/src/main/java/com/github/kr328/clash
design/src/main/java/com/github/kr328/clash/design/store Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,14 +4,14 @@ import android.content.BroadcastReceiver
44import android.content.Context
55import android.content.Intent
66import com.github.kr328.clash.service.StatusProvider
7- import com.github.kr328.clash.util.startClashService
7+ import com.github.kr328.clash.util.restartClashService
88
99class RestartReceiver : BroadcastReceiver () {
1010 override fun onReceive (context : Context , intent : Intent ) {
1111 when (intent.action) {
1212 Intent .ACTION_BOOT_COMPLETED , Intent .ACTION_MY_PACKAGE_REPLACED -> {
1313 if (StatusProvider .shouldStartClashOnBoot)
14- context.startClashService ()
14+ context.restartClashService ()
1515 }
1616 }
1717 }
Original file line number Diff line number Diff line change @@ -11,7 +11,10 @@ import com.github.kr328.clash.service.ClashService
1111import com.github.kr328.clash.service.TunService
1212import com.github.kr328.clash.service.util.sendBroadcastSelf
1313
14- fun Context.startClashService (): Intent ? {
14+ fun Context.runClashService (): Intent ? {
15+ if (! UiStore (this ).enableClashService)
16+ return null ;
17+
1518 val startTun = UiStore (this ).enableVpn
1619
1720 if (startTun) {
@@ -27,6 +30,16 @@ fun Context.startClashService(): Intent? {
2730 return null
2831}
2932
33+ fun Context.startClashService (): Intent ? {
34+ UiStore (this ).enableClashService = true
35+ return runClashService()
36+ }
37+
3038fun Context.stopClashService () {
39+ UiStore (this ).enableClashService = false
3140 sendBroadcastSelf(Intent (Intents .ACTION_CLASH_REQUEST_STOP ))
32- }
41+ }
42+
43+ fun Context.restartClashService (): Intent ? {
44+ return runClashService();
45+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ class UiStore(context: Context) {
1414 .asStoreProvider()
1515 )
1616
17+ var enableClashService: Boolean by store.boolean(
18+ key = " enable_clash_service" ,
19+ defaultValue = false
20+ )
21+
1722 var enableVpn: Boolean by store.boolean(
1823 key = " enable_vpn" ,
1924 defaultValue = true
You can’t perform that action at this time.
0 commit comments