package com.github.kr328.clash import android.content.pm.PackageManager import com.github.kr328.clash.common.util.componentName import com.github.kr328.clash.design.AppSettingsDesign import com.github.kr328.clash.design.model.Behavior import com.github.kr328.clash.service.store.ServiceStore import com.github.kr328.clash.util.ApplicationObserver import kotlinx.coroutines.isActive import kotlinx.coroutines.selects.select class AppSettingsActivity : BaseActivity(), Behavior { override suspend fun main() { val design = AppSettingsDesign( this, uiStore, ServiceStore(this), this, clashRunning, ) setContentDesign(design) while (isActive) { select { events.onReceive { when (it) { Event.ClashStart, Event.ClashStop, Event.ServiceRecreated -> recreate() else -> Unit } } design.requests.onReceive { ApplicationObserver.createdActivities.forEach { it.recreate() } } } } } override var autoRestart: Boolean get() { val status = packageManager.getComponentEnabledSetting( RestartReceiver::class.componentName ) return status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED } set(value) { val status = if (value) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED packageManager.setComponentEnabledSetting( RestartReceiver::class.componentName, status, PackageManager.DONT_KILL_APP, ) } }