parent
054597ea96
commit
56cc572077
|
|
@ -62,6 +62,7 @@ import com.img.rabbit.utils.AppEventBus
|
|||
import com.img.rabbit.utils.UniAppUtils
|
||||
import com.img.rabbit.utils.UniMpUpdate
|
||||
import com.img.rabbit.utils.UniMpWXPayEvent
|
||||
import com.img.rabbit.utils.UpdateUtils
|
||||
import com.img.rabbit.viewmodel.GeneralViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -115,6 +116,12 @@ fun HomeScreen(
|
|||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
UniAppUtils.uniMpFlow.collect { currentMap ->
|
||||
Log.d("UniMP", "Map 变化了,当前数量: ${currentMap.size}")
|
||||
}
|
||||
}
|
||||
|
||||
var homeIconConfig by remember { mutableStateOf(PreferenceUtil.getUserConfig()?.config?.homeIconEntity) }
|
||||
var uniVersionConfig by remember { mutableStateOf(PreferenceUtil.getUserConfig()?.config?.uniVersionEntity) }
|
||||
LaunchedEffect(globalUserConfig) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import io.dcloud.feature.unimp.config.UniMPOpenConfiguration
|
|||
import io.dcloud.feature.unimp.config.UniMPReleaseConfiguration
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import kotlin.jvm.java
|
||||
|
|
@ -28,7 +30,14 @@ object UniAppUtils {
|
|||
/**
|
||||
* 所有运行的UniMp小程序实体
|
||||
*/
|
||||
val uniMpPair = mutableMapOf<String?, IUniMP?>()
|
||||
// val uniMpPair = mutableMapOf<String?, IUniMP?>()
|
||||
private val _uniMpFlow = MutableStateFlow<Map<String?, IUniMP?>>(emptyMap())
|
||||
val uniMpFlow = _uniMpFlow.asStateFlow()
|
||||
fun updateUniMp(id: String?, mp: IUniMP?) {
|
||||
val currentMap = _uniMpFlow.value.toMutableMap()
|
||||
currentMap[id] = mp
|
||||
_uniMpFlow.value = currentMap
|
||||
}
|
||||
|
||||
//当前正在更新的小程序
|
||||
var currentUpdateUniMp: UniVersionEntity? = null
|
||||
|
|
@ -42,7 +51,8 @@ object UniAppUtils {
|
|||
*获取当前前台运行的UniMp小程序实体
|
||||
*/
|
||||
fun getCurrentUniMp(): IUniMP?{
|
||||
return uniMpPair.filter { it.value?.isRunning == true }.values.firstOrNull()
|
||||
return uniMpFlow.value.filter { it.value?.isRunning == true }.values.firstOrNull()
|
||||
//return uniMpPair.filter { it.value?.isRunning == true }.values.firstOrNull()
|
||||
}
|
||||
/**
|
||||
* 是否存在更新
|
||||
|
|
@ -126,7 +136,7 @@ object UniAppUtils {
|
|||
}
|
||||
|
||||
private fun startUniMp(context: Context, uniVersion: UniVersionEntity, onResult:(loading: Boolean) -> Unit){
|
||||
val uniMp = uniMpPair[uniVersion.unimp_id]
|
||||
val uniMp = _uniMpFlow.value[uniVersion.unimp_id]//uniMpPair[uniVersion.unimp_id]
|
||||
if(uniMp?.isRuning == true){
|
||||
Log.i("UniAppUtils", "startUniMp: 运行中...")
|
||||
uniMp.showUniMP()
|
||||
|
|
@ -136,7 +146,8 @@ object UniAppUtils {
|
|||
if(uniVersion.unimp_type == "wx"){
|
||||
configuration.splashClass = UniMPSplashView::class.java
|
||||
}
|
||||
uniMpPair[uniVersion.unimp_id] = DCUniMPSDK.getInstance().openUniMP(context, uniVersion.unimp_id, configuration)
|
||||
updateUniMp(uniVersion.unimp_id, DCUniMPSDK.getInstance().openUniMP(context, uniVersion.unimp_id, configuration))
|
||||
//uniMpPair[uniVersion.unimp_id] = DCUniMPSDK.getInstance().openUniMP(context, uniVersion.unimp_id, configuration)
|
||||
}
|
||||
onResult(false)
|
||||
}
|
||||
|
|
@ -152,9 +163,13 @@ object UniAppUtils {
|
|||
|
||||
}
|
||||
}else{
|
||||
if(uniMpPair[uniMpId]?.isRuning == true){
|
||||
uniMpPair[uniMpId]?.closeUniMP()
|
||||
val uniMp = _uniMpFlow.value[uniMpId]
|
||||
if(uniMp?.isRuning == true){
|
||||
uniMp.showUniMP()
|
||||
}
|
||||
// if(uniMpPair[uniMpId]?.isRuning == true){
|
||||
// uniMpPair[uniMpId]?.closeUniMP()
|
||||
// }
|
||||
// 启动直达页面
|
||||
startUniMpToPage(context, uniMpId, uniMpType, pagePath)
|
||||
}
|
||||
|
|
@ -166,7 +181,8 @@ object UniAppUtils {
|
|||
configuration.splashClass = UniMPSplashView::class.java
|
||||
}
|
||||
configuration.path = pagePath
|
||||
uniMpPair[uniMpId] = DCUniMPSDK.getInstance().openUniMP(context, uniMpId, configuration)
|
||||
updateUniMp(uniMpId, DCUniMPSDK.getInstance().openUniMP(context, uniMpId, configuration))
|
||||
// uniMpPair[uniMpId] = DCUniMPSDK.getInstance().openUniMP(context, uniMpId, configuration)
|
||||
}
|
||||
|
||||
private fun releaseWgt(versionEntity: UniVersionEntity, onReleaseWgt: (isSuccess: Boolean, versionEntity: UniVersionEntity) -> Unit) {
|
||||
|
|
@ -318,6 +334,7 @@ object UniAppUtils {
|
|||
extraData.put("host", "${Constants.RELEASE_BASE_URL}/")
|
||||
extraData.put("decrypt", Constants.AESDecrypt)
|
||||
extraData.put("encrypt", Constants.Signature)
|
||||
extraData.put("isCombo", "ok")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue