Create a test button to show the TOTP notification on dev builds

This commit is contained in:
Artem Chepurnoy 2024-01-30 10:37:21 +02:00
parent ff496d7a05
commit 234ae97b48
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
6 changed files with 75 additions and 19 deletions

View File

@ -0,0 +1,56 @@
package com.artemchep.keyguard.feature.home.settings.component
import android.app.Application
import android.content.Context
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.icons.Icons
import androidx.compose.runtime.Composable
import arrow.core.getOrElse
import com.artemchep.keyguard.android.clipboard.KeyguardClipboardService
import com.artemchep.keyguard.common.model.TotpToken
import com.artemchep.keyguard.feature.home.vault.component.VaultViewButtonItem
import com.artemchep.keyguard.ui.icons.KeyguardTwoFa
import com.artemchep.keyguard.ui.icons.icon
import kotlinx.coroutines.flow.flowOf
import org.kodein.di.DirectDI
import org.kodein.di.instance
actual fun settingEmitTotpProvider(
directDI: DirectDI,
): SettingComponent = settingEmitTotpProvider(
context = directDI.instance<Application>(),
)
fun settingEmitTotpProvider(
context: Context,
): SettingComponent = kotlin.run {
val totp = TotpToken.parse("keyguard")
.getOrElse { e ->
throw e
}
val item = SettingIi {
SettingEmitTotp(
onClick = {
val intent = KeyguardClipboardService.getIntent(
context = context,
cipherName = "Test cipher",
totpToken = totp,
)
context.startForegroundService(intent)
},
)
}
flowOf(item)
}
@Composable
fun SettingEmitTotp(
onClick: () -> Unit,
) {
VaultViewButtonItem(
leading = icon<RowScope>(Icons.Outlined.KeyguardTwoFa),
text = "Emit TOTP",
onClick = onClick,
)
}

View File

@ -48,6 +48,7 @@ import com.artemchep.keyguard.feature.home.settings.component.settingCrashlytics
import com.artemchep.keyguard.feature.home.settings.component.settingCredentialProviderProvider import com.artemchep.keyguard.feature.home.settings.component.settingCredentialProviderProvider
import com.artemchep.keyguard.feature.home.settings.component.settingDataSafetyProvider import com.artemchep.keyguard.feature.home.settings.component.settingDataSafetyProvider
import com.artemchep.keyguard.feature.home.settings.component.settingEmitMessageProvider import com.artemchep.keyguard.feature.home.settings.component.settingEmitMessageProvider
import com.artemchep.keyguard.feature.home.settings.component.settingEmitTotpProvider
import com.artemchep.keyguard.feature.home.settings.component.settingExperimentalProvider import com.artemchep.keyguard.feature.home.settings.component.settingExperimentalProvider
import com.artemchep.keyguard.feature.home.settings.component.settingFeaturesOverviewProvider import com.artemchep.keyguard.feature.home.settings.component.settingFeaturesOverviewProvider
import com.artemchep.keyguard.feature.home.settings.component.settingFeedbackAppProvider import com.artemchep.keyguard.feature.home.settings.component.settingFeedbackAppProvider
@ -136,6 +137,7 @@ object Setting {
const val CRASHLYTICS = "automatic_crash_reports" const val CRASHLYTICS = "automatic_crash_reports"
const val REQUIRE_MASTER_PASSWORD = "require_master_password" const val REQUIRE_MASTER_PASSWORD = "require_master_password"
const val EMIT_MESSAGE = "emit_message" const val EMIT_MESSAGE = "emit_message"
const val EMIT_TOTP = "emit_totp"
const val FEEDBACK_APP = "feedback_app" const val FEEDBACK_APP = "feedback_app"
const val REDDIT = "reddit" const val REDDIT = "reddit"
const val CROWDIN = "crowdin" const val CROWDIN = "crowdin"
@ -213,6 +215,7 @@ val hub = mapOf<String, (DirectDI) -> SettingComponent>(
Setting.CRASHLYTICS to ::settingCrashlyticsProvider, Setting.CRASHLYTICS to ::settingCrashlyticsProvider,
Setting.REQUIRE_MASTER_PASSWORD to ::settingRequireMasterPasswordProvider, Setting.REQUIRE_MASTER_PASSWORD to ::settingRequireMasterPasswordProvider,
Setting.EMIT_MESSAGE to ::settingEmitMessageProvider, Setting.EMIT_MESSAGE to ::settingEmitMessageProvider,
Setting.EMIT_TOTP to ::settingEmitTotpProvider,
Setting.FEEDBACK_APP to ::settingFeedbackAppProvider, Setting.FEEDBACK_APP to ::settingFeedbackAppProvider,
Setting.ABOUT_APP to ::settingAboutAppProvider, Setting.ABOUT_APP to ::settingAboutAppProvider,
Setting.ABOUT_APP_BUILD_DATE to ::settingAboutAppBuildDateProvider, Setting.ABOUT_APP_BUILD_DATE to ::settingAboutAppBuildDateProvider,

View File

@ -0,0 +1,7 @@
package com.artemchep.keyguard.feature.home.settings.component
import org.kodein.di.DirectDI
expect fun settingEmitTotpProvider(
directDI: DirectDI,
): SettingComponent

View File

@ -17,6 +17,7 @@ fun DebugSettingsScreen() {
title = "UI", title = "UI",
list = listOf( list = listOf(
SettingPaneItem.Item(Setting.EMIT_MESSAGE), SettingPaneItem.Item(Setting.EMIT_MESSAGE),
SettingPaneItem.Item(Setting.EMIT_TOTP),
SettingPaneItem.Item(Setting.CLEAR_CACHE), SettingPaneItem.Item(Setting.CLEAR_CACHE),
SettingPaneItem.Item(Setting.LAUNCH_APP_PICKER), SettingPaneItem.Item(Setting.LAUNCH_APP_PICKER),
SettingPaneItem.Item(Setting.LAUNCH_YUBIKEY), SettingPaneItem.Item(Setting.LAUNCH_YUBIKEY),

View File

@ -1864,25 +1864,6 @@ private fun RememberStateFlowScope.oh(
.orEmpty(), .orEmpty(),
) )
emit(remoteRevDate) emit(remoteRevDate)
// TOTP
// TODO: Fix meeeee!!!
// val totp = cipher.login?.totp
// if (totp != null) {
// val intent = KeyguardClipboardService.Companion.getIntent(
// context = context,
// cipherName = cipher.name,
// totpToken = totp.token,
// )
// val remoteRevDate2 = VaultViewItem.Button(
// id = "adasdadasdasdads",
// text = "Launch TOTP",
// onClick = {
// context.startForegroundService(intent)
// },
// )
// emit(remoteRevDate2)
// }
} }
} }

View File

@ -0,0 +1,8 @@
package com.artemchep.keyguard.feature.home.settings.component
import kotlinx.coroutines.flow.flowOf
import org.kodein.di.DirectDI
actual fun settingEmitTotpProvider(
directDI: DirectDI,
): SettingComponent = flowOf(null)