Android security implementation Phase 3.4
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package studio.daybreak.mail
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
/** Makes native confirmations fail closed and guarantees each plugin call gets one decision. */
|
||||
internal class AndroidPgpConfirmationGate(
|
||||
private val showPrompt: (Prompt) -> Unit,
|
||||
private val dispatch: ((() -> Unit) -> Unit)
|
||||
) {
|
||||
data class Prompt(
|
||||
val title: String,
|
||||
val message: String,
|
||||
val confirmLabel: String,
|
||||
val cancelLabel: String,
|
||||
val confirm: () -> Unit,
|
||||
val cancel: () -> Unit
|
||||
)
|
||||
|
||||
fun request(
|
||||
title: String,
|
||||
message: String,
|
||||
confirmLabel: String,
|
||||
cancelLabel: String = "Cancel",
|
||||
onConfirmed: () -> Unit,
|
||||
onCancelled: () -> Unit
|
||||
) {
|
||||
val decided = AtomicBoolean(false)
|
||||
showPrompt(
|
||||
Prompt(
|
||||
title = title,
|
||||
message = message,
|
||||
confirmLabel = confirmLabel,
|
||||
cancelLabel = cancelLabel,
|
||||
confirm = { if (decided.compareAndSet(false, true)) dispatch(onConfirmed) },
|
||||
cancel = { if (decided.compareAndSet(false, true)) dispatch(onCancelled) }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user