一键连需求:

1.一键连新增模式选择
This commit is contained in:
level 2025-11-03 11:09:57 +08:00
parent da5031bbe7
commit 9ad04af12b
5 changed files with 59 additions and 46 deletions

View File

@ -489,6 +489,7 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
isGlo = false
tvProA.setBackgroundResource(R.drawable.yil_node_proxy_choose_bg)
tvProj.setBackgroundResource(0)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
sendMode(false)
}
@ -496,7 +497,9 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
isGlo = true
tvProA.setBackgroundResource(0)
tvProj.setBackgroundResource(R.drawable.yil_node_proxy_choose_bg)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
sendMode(true)
}
}
}

View File

@ -185,7 +185,6 @@ class MainActivity : BaseActivity() {
mainAtyVM = ViewModelProvider(this)[MainAtyVM::class.java]
observe(this, mainAtyVM)
mainAtyVM.startHeartBeat()
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
mainAtyVM.getAirNodes()
val isGlobal = MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
newMainActGlo = isGlobal

View File

@ -235,7 +235,6 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
}
setProxyModeView(ProxyMode.PAC)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
checkGlo()
}
tvGlobalMode.setOnClickListener {
if(clashRunning){
@ -244,7 +243,6 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
}
setProxyModeView(ProxyMode.GLOBAL)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
checkGlo()
}
clLinks.setOnClickListener {
if (clashRunning) {
@ -333,6 +331,14 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
stateChanged(CLASH_STOP, false)
}
}
val isGlobal = MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
newMainActGlo = isGlobal
val px: ProxyMode = if (isGlobal) {
ProxyMode.GLOBAL
} else {
ProxyMode.PAC
}
setProxyModeView(px)
}
@ -396,6 +402,7 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
tvClick.text=resources.getString(R.string.Accelerating)
ivAccelerate.setImageResource(R.mipmap.yjl_home_clink_select_bg)
hideLoading()
checkGlo()
}
}
@ -477,12 +484,14 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
RxToast.success(resources.getString(R.string.AccelerateSuccess))
}
}
ivAccelerate.setImageResource(R.mipmap.yjl_home_clink_select_bg)
}
CLASH_STOP -> {
if (::rxDialogShapeLoading.isInitialized) {
rxDialogShapeLoading.cancel()
}
ivAccelerate.setImageResource(R.mipmap.yjl_home_clink_bg)
}
CLASH_STARTING -> {
@ -622,51 +631,36 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
private fun checkGlo() {
val isGlobal = isGlo
val isGlobal2 = MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.i("checkGlo isGlobal==>${isGlobal}, isGlobal2==>${isGlobal2}")
val px: ProxyMode = if (isGlobal2) {
ProxyMode.GLOBAL
} else {
ProxyMode.PAC
}
setProxyModeView(px)
val isGlobal =isGlo
Log.i("checkGlo isGlobal==>${isGlobal} clashRunning==>${clashRunning}")
launch(Dispatchers.IO) {
if (isGlobal) {
if (clashRunning) {
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]
//全局模式下 names[0]会自动添加一个 "GLOBAL" 组
if (names.size >= 2) {
if ("GLOBAL" == gName) {
//names[0] 为 "GLOBAL" //names[1]才是规则模式下的组名,所以需要手动赋值
gName = names[1]
}
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()
}
}
}
@ -985,4 +979,5 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
}
}
}

View File

@ -75,7 +75,7 @@
android:layout_height="wrap_content"
android:background="@drawable/yil_node_proxy_choose_bg"
android:layout_weight="1"
android:text="@string/anqpro"
android:text="@string/IntelligentMode"
android:gravity="center"
android:textColor="#FF2D2D2D"
android:paddingTop="10dp"
@ -86,7 +86,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/jsmpri"
android:text="@string/GlobalMode"
android:gravity="center"
android:textColor="#FF2D2D2D"
android:paddingTop="10dp"

View File

@ -93,7 +93,7 @@ subprojects {
}
productFlavors {
flavorDimensions("feature")
create("3333") {
create("2210") {
isDefault = true
dimension = flavorDimensionList[0]
buildConfigField("boolean", "PREMIUM", "Boolean.parseBoolean(\"false\")")
@ -101,7 +101,23 @@ subprojects {
buildConfigField("boolean", "is_back_cn", "false")
buildConfigField("String", "applicationId", "\"com.jsq.wufu\"")
buildConfigField("String", "service_url", "\"https://api.yijianlianjsq.com/\"")
buildConfigField("String", "productId", "\"3333\"")
buildConfigField("String", "productId", "\"2210\"")
manifestPlaceholders(
mapOf(
"APP_NAME" to "@string/wf",
"APP_ICON" to "@mipmap/oneclickconnection"
)
)
}
create("2211") {
isDefault = true
dimension = flavorDimensionList[0]
buildConfigField("boolean", "PREMIUM", "Boolean.parseBoolean(\"false\")")
buildConfigField("boolean", "is_free", "false")
buildConfigField("boolean", "is_back_cn", "false")
buildConfigField("String", "applicationId", "\"com.jsq.wufu\"")
buildConfigField("String", "service_url", "\"https://api.yijianlianjsq.com/\"")
buildConfigField("String", "productId", "\"2211\"")
manifestPlaceholders(
mapOf(
"APP_NAME" to "@string/wf",
@ -111,7 +127,7 @@ subprojects {
}
}
sourceSets {
getByName("3333") {
getByName("2210") {
java.srcDirs("src/foss/java")
}
}