diff --git a/android/app/src/main/kotlin/com/hiddify/hiddify/bg/BootReceiver.kt b/android/app/src/main/kotlin/com/hiddify/hiddify/bg/BootReceiver.kt new file mode 100644 index 00000000..028d16a9 --- /dev/null +++ b/android/app/src/main/kotlin/com/hiddify/hiddify/bg/BootReceiver.kt @@ -0,0 +1,30 @@ +package com.hiddify.hiddify.bg + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import com.hiddify.hiddify.Settings +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +class BootReceiver : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + when (intent.action) { + Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED -> { + } + + else -> return + } + GlobalScope.launch(Dispatchers.IO) { + if (Settings.startedByUser) { + withContext(Dispatchers.Main) { + BoxService.start() + } + } + } + } + +} \ No newline at end of file