package com.InfernalAquatics.deepwave import android.Manifest import android.content.pm.PackageManager import android.os.Build import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.result.contract.ActivityResultContracts import androidx.core.content.ContextCompat import com.InfernalAquatics.deepwave.ui.navigation.DeepwaveNavHost import com.InfernalAquatics.deepwave.ui.theme.DeepwaveTheme import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MainActivity : ComponentActivity() { private val notificationPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { /* playback works either way; only the notification is affected */ } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() requestNotificationPermissionIfNeeded() setContent { DeepwaveTheme { DeepwaveNavHost() } } } /** Without this on API 33+, the playback service still plays but its notification never shows. */ private fun requestNotificationPermissionIfNeeded() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return val granted = ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED if (!granted) { notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) } } }