1.一键连更改模式选择代码
This commit is contained in:
level 2025-12-08 18:56:39 +08:00
parent bd1132f741
commit 3d9c1b4585
3 changed files with 73 additions and 45 deletions

View File

@ -132,27 +132,28 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
tvProA.setOnClickListener {
if(!clashRunning){
val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("clIntelligentMode ==>${getIsGlo}")
if(getIsGlo){
setBackground(ProxyMode.PAC)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
checkGlo()
}else{
RxToast.info(resources.getString(R.string.closeRunningChoose))
}
if(clashRunning){
RxToast.info(resources.getString(R.string.SwitchingSourceModel))
return@setOnClickListener
}
}
tvProj.setOnClickListener {
if(!clashRunning){
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
setBackground(ProxyMode.GLOBAL)
}else{
RxToast.info(resources.getString(R.string.closeRunningChoose))
if (!clashRunning) {
RxToast.info(resources.getString(R.string.SwitchingSourceModel))
return@setOnClickListener
}
val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("clGlobalModel ==>${getIsGlo}")
if (!getIsGlo) {
setBackground(ProxyMode.GLOBAL)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
checkGlo()
}
}
aiBack.setOnClickListener {

View File

@ -229,20 +229,33 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
startActivityForResult(intent, 2)
}
tvIntelligentMode.setOnClickListener {
if(clashRunning){
RxToast.info(resources.getString(R.string.SwitchingSourceModel))
return@setOnClickListener
// if(clashRunning){
// RxToast.info(resources.getString(R.string.SwitchingSourceModel))
// return@setOnClickListener
// }
val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("clIntelligentMode ==>${getIsGlo}")
if(getIsGlo){
setProxyModeView(ProxyMode.PAC)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
checkGlo()
}
setProxyModeView(ProxyMode.PAC)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
}
tvGlobalMode.setOnClickListener {
if(clashRunning){
if (!clashRunning) {
RxToast.info(resources.getString(R.string.SwitchingSourceModel))
return@setOnClickListener
}
setProxyModeView(ProxyMode.GLOBAL)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("clGlobalModel ==>${getIsGlo}")
if (!getIsGlo) {
setProxyModeView(ProxyMode.GLOBAL)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
checkGlo()
}
}
clLinks.setOnClickListener {
if (clashRunning) {
@ -348,12 +361,12 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
private fun startClash(isStart: Boolean) {
launch {
if (isStart) {
delay(2000)
}
MainActivity.profileBinder?.let { pm ->
val active = pm.queryActive()
if (active == null) {
if (isStart) {
delay(2000)
}
Log.d("startClash: 未选择")
val pro = pm.queryAll().find {
it.name == Conf.getClashConfName(this@HomeFragment.context)
@ -512,7 +525,14 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
fun nodeChooseBase(data: Intent?) {
val node = data?.extras?.getString(BZYConstants.MMKV_KEY_SELECT_NODE_NAME)
val isRunning = data?.extras?.getBoolean(BZYConstants.EXTRA_KEY_IS_RUNING)
Log.d("onActivityResult ==>>> Node:${node}")
val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
if(getIsGlo){
setProxyModeView(ProxyMode.GLOBAL)
}else{
setProxyModeView(ProxyMode.PAC)
}
Log.d("onActivityResult ==>>> Node:${node} ::getIsGlo::${getIsGlo}")
node?.let {
setNodeNameAndImg(it)
if (clashRunning) {
@ -635,32 +655,38 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
Log.i("checkGlo isGlobal==>${isGlobal} clashRunning==>${clashRunning}")
launch(Dispatchers.IO) {
if (isGlobal) {
delay(1000)
clashBinder?.let { cm ->
val names = cm.queryProxyGroupNames(false)
Log.i("checkGlo names==>${names}")
if (names.isNotEmpty()) {
val selectedName =
MMKV.defaultMMKV()
.decodeString(BZYConstants.NODE_SELECTED_NAME_KEY, "")
Log.i("selected_name ==>${selectedName}")
if (!TextUtils.isEmpty(selectedName)) {
val o = cm.queryOverride(Clash.OverrideSlot.Session)
o.mode = TunnelState.Mode.Rule
cm.patchOverride(Clash.OverrideSlot.Session, o)
delay(500)
var gName = names[0]
if (names.size >= 2) {
if ("GLOBAL" == gName) {
gName = names[1]
if (clashRunning) {
Log.i("AAAAAAAAAAAAAA innner to==>")
getNodes()
}
}else{
if(clashRunning){
delay(1000)
clashBinder?.let { cm ->
val names = cm.queryProxyGroupNames(false)
Log.i("checkGlo names==>${names}")
if (names.isNotEmpty()) {
val selectedName =
MMKV.defaultMMKV()
.decodeString(BZYConstants.NODE_SELECTED_NAME_KEY, "")
Log.i("selected_name ==>${selectedName}")
if (!TextUtils.isEmpty(selectedName)) {
val o = cm.queryOverride(Clash.OverrideSlot.Session)
o.mode = TunnelState.Mode.Rule
cm.patchOverride(Clash.OverrideSlot.Session, o)
delay(500)
var gName = names[0]
if (names.size >= 2) {
if ("GLOBAL" == gName) {
gName = names[1]
}
}
}
cm.patchSelector(gName, selectedName!!)
cm.patchSelector(gName, selectedName!!)
}
}
}
}
getNodes()
}
}
}

View File

@ -479,4 +479,5 @@
<string name="ShartPagetxt">邀请新朋友通过你的分享链接注册并订购任意会员套餐,\n
您可以获得30天会员仅限新用户订购有效</string>
<string name="LinkSharetxt">点击分享</string>
<string name="OpenSwitchingSourceModel">请开启加速后在进行全局模式切换</string>
</resources>