1package com.peachpasswords23import android.content.Intent4import android.content.res.Configuration5import android.graphics.Color as AndroidColor6import android.graphics.drawable.ColorDrawable7import android.os.Bundle8import android.view.WindowManager9import androidx.activity.compose.setContent10import androidx.activity.enableEdgeToEdge11import androidx.compose.foundation.isSystemInDarkTheme12import androidx.compose.runtime.SideEffect13import androidx.compose.runtime.collectAsState14import androidx.compose.runtime.getValue15import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen16import androidx.core.view.WindowCompat17import androidx.fragment.app.FragmentActivity18import dagger.hilt.android.AndroidEntryPoint19import javax.inject.Inject20import com.peachpasswords.ui.PeachAppNavHost21import com.peachpasswords.ui.components.QaFlags22import com.peachpasswords.ui.onboarding.ONBOARD_KEY23import com.peachpasswords.ui.onboarding.ONBOARD_PREFS24import com.peachpasswords.ui.onboarding.onboardingStartDestination25import com.peachpasswords.ui.theme.ACCENT_COLORS26import com.peachpasswords.ui.theme.DEFAULT_ACCENT27import com.peachpasswords.ui.theme.PeachTheme28import com.peachpasswords.vault.VaultLockTimer29import com.peachpasswords.vault.VaultRepository303132@AndroidEntryPoint33class MainActivity : FragmentActivity() {34 @Inject lateinit var vault: VaultRepository35 @Inject lateinit var lockTimer: VaultLockTimer3637 38 override fun onUserInteraction() {39 super.onUserInteraction()40 lockTimer.poke()41 }4243 44 45 46 override fun onNewIntent(intent: Intent) {47 super.onNewIntent(intent)48 setIntent(intent)49 if (BuildConfig.DEBUG) {50 QaFlags.disableSecureCaptureForQa = intent.getBooleanExtra("qa_disable_secure_flag", false)51 }52 }5354 override fun onCreate(savedInstanceState: Bundle?) {55 installSplashScreen()56 super.onCreate(savedInstanceState)5758 59 60 61 val initialTheme = vault.settings.value.theme62 val initialDark = when (initialTheme) {63 "light" -> false64 "system" -> (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==65 Configuration.UI_MODE_NIGHT_YES66 else -> true67 }68 window.setBackgroundDrawable(69 ColorDrawable(AndroidColor.parseColor(if (initialDark) "#0C0A06" else "#EFEEE9")),70 )7172 enableEdgeToEdge()7374 75 if (!BuildConfig.DEBUG) {76 window.setFlags(77 WindowManager.LayoutParams.FLAG_SECURE,78 WindowManager.LayoutParams.FLAG_SECURE,79 )80 } else {81 82 83 84 QaFlags.disableSecureCaptureForQa = intent.getBooleanExtra("qa_disable_secure_flag", false)85 }8687 88 val onboarded = getSharedPreferences(ONBOARD_PREFS, MODE_PRIVATE)89 .getBoolean(ONBOARD_KEY, false)90 val start = onboardingStartDestination(hasVault = vault.hasVault(), onboarded = onboarded)9192 setContent {93 val settings by vault.settings.collectAsState()94 val darkTheme = when (settings.theme) {95 "light" -> false96 "system" -> isSystemInDarkTheme()97 else -> true98 }99 100 101 102 103 104 105 106 107 SideEffect {108 WindowCompat.getInsetsController(window, window.decorView).apply {109 isAppearanceLightStatusBars = !darkTheme110 isAppearanceLightNavigationBars = !darkTheme111 }112 }113 val accent = ACCENT_COLORS[settings.accentColor] ?: DEFAULT_ACCENT114 PeachTheme(115 darkTheme = darkTheme,116 accent = accent,117 reduceMotion = settings.reduceMotion,118 ) {119 PeachAppNavHost(startDestination = start, isUnlocked = vault.isUnlocked)120 }121 }122 }123}