SecurityScreen.kt (5245B) - raw


      1 package me.rhunk.snapenhance.ui.setup.screens.impl
      2 
      3 import android.annotation.SuppressLint
      4 import androidx.compose.foundation.layout.*
      5 import androidx.compose.foundation.rememberScrollState
      6 import androidx.compose.foundation.verticalScroll
      7 import androidx.compose.material.icons.Icons
      8 import androidx.compose.material.icons.filled.WarningAmber
      9 import androidx.compose.material3.*
     10 import androidx.compose.runtime.*
     11 import androidx.compose.ui.Alignment
     12 import androidx.compose.ui.Modifier
     13 import androidx.compose.ui.text.font.FontWeight
     14 import androidx.compose.ui.unit.dp
     15 import androidx.compose.ui.unit.sp
     16 import kotlinx.coroutines.Dispatchers
     17 import kotlinx.coroutines.Job
     18 import kotlinx.coroutines.launch
     19 import kotlinx.coroutines.withContext
     20 import me.rhunk.snapenhance.ui.setup.screens.SetupScreen
     21 
     22 class SecurityScreen : SetupScreen() {
     23     @SuppressLint("ApplySharedPref")
     24     @Composable
     25     override fun Content() {
     26         Icon(
     27             imageVector = Icons.Default.WarningAmber,
     28             contentDescription = null,
     29             modifier = Modifier
     30                 .padding(16.dp)
     31                 .size(30.dp),
     32         )
     33 
     34         DialogText(
     35             "Since Snapchat has implemented additional security measures against third-party applications such as SnapEnhance, we offer a non-opensource solution that reduces the risk of banning and prevents Snapchat from detecting SnapEnhance. " +
     36                     "\nPlease note that this solution does not provide a ban bypass or spoofer for anything, and does not take any personal data or communicate with the network." +
     37                     "\nWe also encourage you to use official signed builds to avoid compromising the security of your account." +
     38             "\nIf you're having trouble using the solution, or are experiencing crashes, join the Telegram Group for help: https://t.me/snapenhance_chat"
     39         )
     40 
     41         var denyDialog by remember { mutableStateOf(false) }
     42 
     43         if (denyDialog) {
     44             AlertDialog(
     45                 onDismissRequest = {
     46                     denyDialog = false
     47                 },
     48                 text = {
     49                     Text("Are you sure you don't want to use this solution? You can always change this later in the settings in the SnapEnhance app.")
     50                 },
     51                 dismissButton = {
     52                     Button(onClick = {
     53                         denyDialog = false
     54                     }) {
     55                         Text("Go back")
     56                     }
     57                 },
     58                 confirmButton = {
     59                     Button(onClick = {
     60                         context.sharedPreferences.edit().putString("sif", "false").apply()
     61                         goNext()
     62                     }) {
     63                         Text("Yes, I'm sure")
     64                     }
     65                 }
     66             )
     67         }
     68 
     69         var downloadJob by remember { mutableStateOf(null as Job?) }
     70         var jobError by remember { mutableStateOf(null as Throwable?) }
     71 
     72         if (downloadJob != null) {
     73             AlertDialog(onDismissRequest = {
     74                 downloadJob?.cancel()
     75                 downloadJob = null
     76             }, confirmButton = {}, text = {
     77                 Column(
     78                     modifier = Modifier.verticalScroll(rememberScrollState()).fillMaxWidth(),
     79                     horizontalAlignment = Alignment.CenterHorizontally,
     80                     verticalArrangement = Arrangement.spacedBy(10.dp),
     81                 ) {
     82                     if (jobError != null) {
     83                         Text("Failed to download the required files.\n\n${jobError?.message}")
     84                     } else {
     85                         Text("Downloading the required files...")
     86                         CircularProgressIndicator(modifier = Modifier.padding(16.dp))
     87                     }
     88                 }
     89             })
     90         }
     91 
     92         fun newDownloadJob() {
     93             downloadJob?.cancel()
     94             downloadJob = context.coroutineScope.launch {
     95                 context.sharedPreferences.edit().putString("sif", "").commit()
     96                 runCatching {
     97                     context.remoteSharedLibraryManager.init()
     98                 }.onFailure {
     99                     jobError = it
    100                     context.log.error("Failed to download the required files", it)
    101                 }.onSuccess {
    102                     downloadJob = null
    103                     withContext(Dispatchers.Main) {
    104                         goNext()
    105                     }
    106                 }
    107             }
    108         }
    109 
    110         Column (
    111             modifier = Modifier.padding(16.dp),
    112             horizontalAlignment = Alignment.CenterHorizontally,
    113             verticalArrangement = Arrangement.spacedBy(10.dp)
    114         ) {
    115             Button(
    116                 onClick = {
    117                     newDownloadJob()
    118                 }
    119             ) {
    120                 Text("Accept and continue", fontSize = 18.sp, fontWeight = FontWeight.Bold)
    121             }
    122             Button(
    123                 colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.error),
    124                 onClick = {
    125                     denyDialog = true
    126                 }
    127             ) {
    128                 Text("I don't want to use this solution")
    129             }
    130         }
    131     }
    132 }