Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit fae34e0

Browse files
committed
加入仅重启内核
1 parent dc635d1 commit fae34e0

29 files changed

Lines changed: 134 additions & 643 deletions

.idea/misc.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
minSdkVersion 29
1919
targetSdkVersion 32
2020
versionCode gitCommitCount.toInteger()
21-
versionName "4.0"
21+
versionName "4.1"
2222
versionNameSuffix = ".r${gitCommitCount}.${gitCommitHash}"
2323

2424
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

app/src/main/assets/CFM_Restart.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
touch "$2"/../run/cmdRunning
3+
"$2"/clash.service -k
4+
"$2"/clash.service -s
5+
rm -rf "$2"/../run/cmdRunning

app/src/main/assets/CFM_Start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ else
55
MAGISK_PATH="/data/adb/modules"
66
fi
77

8-
if [ "$1" == "" ] ; then
8+
if [ "$1" == "false" ] ; then
99
rm -f ${MAGISK_PATH}/Clash_For_Magisk/disable
1010
else
11-
"$1"/clash.service -s && "$1"/clash.tproxy -s
11+
"$2"/clash.service -s && "$2"/clash.tproxy -s
1212
fi

app/src/main/assets/CFM_Stop.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ else
55
MAGISK_PATH="/data/adb/modules"
66
fi
77

8-
if [ "$1" == "" ] ; then
8+
if [ "$1" == "false" ] ; then
99
touch ${MAGISK_PATH}/Clash_For_Magisk/disable
1010
else
11-
"$1"/clash.service -k && "$1"/clash.tproxy -k
11+
"$2"/clash.service -k && "$2"/clash.tproxy -k
1212
fi

app/src/main/java/com/dashboard/kotlin/MainActivity.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import android.util.Log
55
import android.view.WindowManager
66
import androidx.appcompat.app.AppCompatActivity
77
import androidx.core.content.res.ResourcesCompat
8-
import com.dashboard.kotlin.suihelper.suihelper
8+
import com.dashboard.kotlin.suihelper.SuiHelper
99
import com.tencent.mmkv.MMKV
1010
import kotlinx.android.synthetic.main.toolbar.*
1111
import java.io.DataInputStream
1212
import java.io.File
1313
import java.text.SimpleDateFormat
1414
import java.util.*
15-
import kotlin.concurrent.thread
1615

1716

1817
lateinit var GExternalCacheDir: String
@@ -37,7 +36,7 @@ class MainActivity : AppCompatActivity() {
3736
)
3837

3938
//sui
40-
suihelper.init(packageName)
39+
SuiHelper.init(packageName)
4140

4241
//debug version print logs
4342
if (BuildConfig.DEBUG) {

app/src/main/java/com/dashboard/kotlin/MainPage.kt

Lines changed: 70 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ import android.os.Bundle
77
import android.os.Handler
88
import android.os.Looper
99
import android.util.Log
10-
import android.view.LayoutInflater
11-
import android.view.View
12-
import android.view.ViewGroup
10+
import android.view.*
1311
import android.widget.ScrollView
1412
import androidx.core.content.res.ResourcesCompat
1513
import androidx.fragment.app.Fragment
1614
import androidx.navigation.findNavController
1715
import com.dashboard.kotlin.clashhelper.ClashConfig
1816
import com.dashboard.kotlin.clashhelper.ClashStatus
1917
import com.dashboard.kotlin.clashhelper.commandhelper
20-
import com.dashboard.kotlin.suihelper.suihelper
18+
import com.dashboard.kotlin.suihelper.SuiHelper
2119
import kotlinx.android.synthetic.main.fragment_main_page.*
22-
import kotlinx.android.synthetic.main.toolbar.*
2320
import kotlinx.coroutines.*
2421
import org.json.JSONObject
2522
import java.io.File
@@ -42,14 +39,40 @@ class MainPage : Fragment() {
4239

4340
private val clashStatusClass = ClashStatus()
4441

42+
override fun onCreate(savedInstanceState: Bundle?) {
43+
super.onCreate(savedInstanceState)
44+
setHasOptionsMenu(true)
45+
}
46+
47+
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
48+
Log.e("www1", "onCreateOptionsMenu: ", )
49+
inflater.inflate(R.menu.menu_restart, menu)
50+
}
51+
4552
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
4653
super.onViewCreated(view, savedInstanceState)
4754
Log.d("ViewCreated", "MainPageViewCreated")
4855

49-
toolbar.title = getString(R.string.app_name)
56+
mToolbar.setOnMenuItemClickListener {
57+
when(it.itemId){
58+
R.id.menu_restart -> {
59+
if ((clash_status_text.text == getText(R.string.clash_charging))
60+
|| (clash_status_text.text == getText(R.string.sui_disable)))
61+
return@setOnMenuItemClickListener true
62+
63+
setStatusCmdRunning()
64+
GlobalScope.async {
65+
doAssestsShellFile("CFM_Restart.sh")
66+
}
67+
}
68+
else -> return@setOnMenuItemClickListener false
69+
}
70+
true
71+
}
72+
5073
//TODO 添加 app 图标
5174

52-
if (!suihelper.checkPermission()) {
75+
if (!SuiHelper.checkPermission()) {
5376
clash_status.setCardBackgroundColor(
5477
ResourcesCompat.getColor(resources, R.color.error, context?.theme)
5578
)
@@ -65,7 +88,7 @@ class MainPage : Fragment() {
6588

6689
GlobalScope.async {
6790
while (true) {
68-
if (suihelper.checkPermission(request = false)) {
91+
if (SuiHelper.checkPermission(request = false)) {
6992
restartApp()
7093
break
7194
}
@@ -74,11 +97,40 @@ class MainPage : Fragment() {
7497
}
7598

7699
} else {
77-
if (ClashStatus().runStatus()) {
78-
setStatusRunning()
79-
} else {
80-
setStatusStopped()
81-
}
100+
101+
//这是一段屎一样的代码
102+
clashV = SuiHelper.suCmd("${ClashConfig.corePath} -v")
103+
cmd_result.text = "$clashV${SuiHelper.suCmd("cat ${ClashConfig.clashPath}/run/run.logs 2> /dev/null")}"
104+
timer = Timer()
105+
timer.schedule(object : TimerTask() {
106+
override fun run() {
107+
val log = SuiHelper.suCmd("cat ${ClashConfig.clashPath}/run/run.logs 2> /dev/null")
108+
val cmdRunning = SuiHelper.suCmd(
109+
"if [ -f ${ClashConfig.clashPath}/run/cmdRunning ];then\necho 'true'\nelse\necho 'false'\nfi")
110+
//"cat ${ClashConfig.clashPath}/run/cmdRunning 2>&1")
111+
handler.post{
112+
113+
cmd_result.let {
114+
if (clash_status_text?.text == getString(R.string.clash_charging))
115+
it.text = "$clashV$log"
116+
117+
kotlin.runCatching {
118+
when {
119+
cmdRunning == "true\n" -> {
120+
setStatusCmdRunning()
121+
}
122+
ClashStatus().runStatus() -> {
123+
setStatusRunning()
124+
}
125+
else ->
126+
setStatusStopped()
127+
}
128+
}
129+
}
130+
131+
}
132+
}
133+
},0, 300)
82134
}
83135

84136
clash_status.setOnClickListener {
@@ -125,38 +177,6 @@ class MainPage : Fragment() {
125177
it.findNavController().navigate(R.id.action_manPage_to_settingPage)
126178
}
127179

128-
//这是一段屎一样的代码
129-
clashV = suihelper.suCmd("${ClashConfig.corePath} -v")
130-
cmd_result.text = "$clashV${suihelper.suCmd("cat ${ClashConfig.clashPath}/run/run.logs 2> /dev/null")}"
131-
timer = Timer()
132-
timer.schedule(object : TimerTask() {
133-
override fun run() {
134-
val log = suihelper.suCmd("cat ${ClashConfig.clashPath}/run/run.logs 2> /dev/null")
135-
val cmdRunning = suihelper.suCmd("cat ${ClashConfig.clashPath}/run/cmdRunning 2>&1")
136-
handler.post{
137-
138-
cmd_result.let {
139-
if (clash_status_text?.text == getString(R.string.clash_charging))
140-
it.text = "$clashV$log"
141-
142-
kotlin.runCatching {
143-
when {
144-
cmdRunning == "" -> {
145-
setStatusCmdRunning()
146-
scrollView.fullScroll(ScrollView.FOCUS_DOWN)
147-
}
148-
ClashStatus().runStatus() ->
149-
setStatusRunning()
150-
else ->
151-
setStatusStopped()
152-
}
153-
}
154-
}
155-
156-
}
157-
}
158-
},0, 300)
159-
160180
}
161181

162182
override fun onDestroyView() {
@@ -181,12 +201,11 @@ class MainPage : Fragment() {
181201
fo.outputStream().let { ip ->
182202
op.copyTo(ip)
183203
}
184-
185204
if ((Build.VERSION.SDK_INT == Build.VERSION_CODES.R) and (ClashConfig.scriptsPath == "/data/adb/modules/Clash_For_Magisk/scripts")) {
186-
suihelper.suCmd("sh '${context?.externalCacheDir}/${fileName}' ${ClashConfig.scriptsPath}")
205+
SuiHelper.suCmd("sh '${context?.externalCacheDir}/${fileName}' true ${ClashConfig.scriptsPath}")
187206
}
188207
else {
189-
suihelper.suCmd("sh '${context?.externalCacheDir}/${fileName}'")
208+
SuiHelper.suCmd("sh '${context?.externalCacheDir}/${fileName}' false ${ClashConfig.scriptsPath}")
190209
}
191210

192211
fo.delete()
@@ -210,6 +229,8 @@ class MainPage : Fragment() {
210229

211230
clashStatusClass.getTraffic()
212231

232+
scrollView.fullScroll(ScrollView.FOCUS_DOWN)
233+
213234
GlobalScope.launch(Dispatchers.IO) {
214235
while (clashStatusClass.trafficThreadFlag) {
215236
try {
@@ -234,6 +255,7 @@ class MainPage : Fragment() {
234255
}
235256

236257
private fun setStatusCmdRunning(){
258+
scrollView.fullScroll(ScrollView.FOCUS_DOWN)
237259
if (clash_status_text.text == getString(R.string.clash_charging))
238260
return
239261
clash_status.isClickable = false

app/src/main/java/com/dashboard/kotlin/WebViewPage.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class WebViewPage : Fragment() {
3737
context?.theme
3838
)
3939
toolbar.setNavigationOnClickListener {
40-
val controller = it.findNavController()
41-
controller.popBackStack()
40+
it.findNavController().popBackStack()
4241
}
4342

4443

@@ -55,8 +54,6 @@ class WebViewPage : Fragment() {
5554
@RequiresApi(api = Build.VERSION_CODES.Q)
5655
override fun onResume() {
5756
super.onResume()
58-
Log.e("www1", if ((context?.resources?.configuration?.uiMode
59-
?.and(Configuration.UI_MODE_NIGHT_MASK)) == Configuration.UI_MODE_NIGHT_YES) "true" else "false" )
6057
if ((context?.resources?.configuration?.uiMode
6158
?.and(Configuration.UI_MODE_NIGHT_MASK)) == Configuration.UI_MODE_NIGHT_YES) {
6259
webView.settings.forceDark = WebSettings.FORCE_DARK_ON

app/src/main/java/com/dashboard/kotlin/clashhelper/ClashStatus.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.dashboard.kotlin.GExternalCacheDir
55
import com.dashboard.kotlin.KV
66
import java.net.HttpURLConnection
77
import java.net.URL
8-
import com.dashboard.kotlin.suihelper.suihelper
8+
import com.dashboard.kotlin.suihelper.SuiHelper
99
import kotlinx.coroutines.Dispatchers
1010
import kotlinx.coroutines.GlobalScope
1111
import kotlinx.coroutines.launch
@@ -112,7 +112,7 @@ object ClashConfig {
112112
}
113113
"CPFM" -> {
114114
mergeConfig("${clashPath}/config_new.yaml")
115-
suihelper.suCmd("mv '${clashPath}/config_new.yaml' '${clashPath}/config.yaml'")
115+
SuiHelper.suCmd("mv '${clashPath}/config_new.yaml' '${clashPath}/config.yaml'")
116116
updateConfigNet("${clashPath}/config.yaml")
117117
}
118118
}
@@ -163,7 +163,7 @@ object ClashConfig {
163163
"${GExternalCacheDir}/template",
164164
"${GExternalCacheDir}/config_output.yaml"
165165
)
166-
suihelper.suCmd("mv '${GExternalCacheDir}/config_output.yaml' '$outputFilePath'")
166+
SuiHelper.suCmd("mv '${GExternalCacheDir}/config_output.yaml' '$outputFilePath'")
167167
}
168168
}
169169
}
@@ -199,13 +199,13 @@ object ClashConfig {
199199
private fun setFileNR(dirPath: String, fileName: String, func: () -> Unit) {
200200
copyFile(dirPath, fileName)
201201
func()
202-
suihelper.suCmd("cp '${GExternalCacheDir}/${fileName}' '${dirPath}/${fileName}'")
202+
SuiHelper.suCmd("cp '${GExternalCacheDir}/${fileName}' '${dirPath}/${fileName}'")
203203
deleteFile(GExternalCacheDir, fileName)
204204
}
205205

206206
private fun copyFile(dirPath: String, fileName: String) {
207-
suihelper.suCmd("cp '${dirPath}/${fileName}' '${GExternalCacheDir}/${fileName}'")
208-
suihelper.suCmd("chmod +rw '${GExternalCacheDir}/${fileName}'")
207+
SuiHelper.suCmd("cp '${dirPath}/${fileName}' '${GExternalCacheDir}/${fileName}'")
208+
SuiHelper.suCmd("chmod +rw '${GExternalCacheDir}/${fileName}'")
209209
return
210210
}
211211

app/src/main/java/com/dashboard/kotlin/clashhelper/commandhelper.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.dashboard.kotlin.clashhelper
22

33
import android.util.Log
4-
import com.dashboard.kotlin.suihelper.suihelper
4+
import com.dashboard.kotlin.suihelper.SuiHelper
55
import java.io.File
66
import java.math.BigDecimal
77
import java.math.RoundingMode
@@ -28,14 +28,14 @@ object commandhelper {
2828
fun doInstall(filePath: String, type: String, name: String = "") {
2929
when (type) {
3030
"SUB", "MMDB" -> {
31-
suihelper.suCmd("mv -f '$filePath' '${ClashConfig.clashPath}/${name}'")
32-
suihelper.suCmd("chmod 700 '${ClashConfig.clashPath}/${name}'")
33-
suihelper.suCmd("chown system:system '${ClashConfig.clashPath}/${name}'")
31+
SuiHelper.suCmd("mv -f '$filePath' '${ClashConfig.clashPath}/${name}'")
32+
SuiHelper.suCmd("chmod 700 '${ClashConfig.clashPath}/${name}'")
33+
SuiHelper.suCmd("chown system:system '${ClashConfig.clashPath}/${name}'")
3434
ClashConfig.updateConfig("CFM")
3535
}
3636
"DASHBOARD" -> {
37-
suihelper.suCmd("unzip -o '$filePath' -d '${ClashConfig.clashPath}'")
38-
suihelper.suCmd("chmod 000 '${ClashConfig.clashPath}/${name}/' -R")
37+
SuiHelper.suCmd("unzip -o '$filePath' -d '${ClashConfig.clashPath}'")
38+
SuiHelper.suCmd("chmod 000 '${ClashConfig.clashPath}/${name}/' -R")
3939
ClashConfig.clashDashBoard = name
4040
}
4141
}

0 commit comments

Comments
 (0)