mirror of
https://github.com/CherretGit/zaprett-app.git
synced 2025-12-16 08:39:38 +05:00
move setupProxy checks to HomeViewModel.kt
This commit is contained in:
@@ -38,9 +38,9 @@ class ByeDpiVpnService : VpnService() {
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
startForeground(NOTIFICATION_ID, createNotification())
|
||||
return when (intent?.action) {
|
||||
"START_VPN" -> {
|
||||
startForeground(NOTIFICATION_ID, createNotification())
|
||||
setupProxy()
|
||||
START_STICKY
|
||||
}
|
||||
@@ -99,22 +99,13 @@ class ByeDpiVpnService : VpnService() {
|
||||
}
|
||||
|
||||
private fun setupProxy() {
|
||||
if (getActiveStrategy(sharedPreferences).isNotEmpty()) {
|
||||
try {
|
||||
startSocksProxy()
|
||||
startByeDpi()
|
||||
status = ServiceStatus.Connected
|
||||
} catch (e: Exception) {
|
||||
Log.e("proxy", "Failed to start")
|
||||
status = ServiceStatus.Failed
|
||||
stopSelf()
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
this@ByeDpiVpnService,
|
||||
getString(R.string.toast_no_strategy_selected),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
try {
|
||||
startSocksProxy()
|
||||
startByeDpi()
|
||||
status = ServiceStatus.Connected
|
||||
} catch (e: Exception) {
|
||||
Log.e("proxy", "Failed to start")
|
||||
status = ServiceStatus.Failed
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.cherret.zaprett.ui.viewmodel
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.widget.Toast
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -12,6 +13,7 @@ import com.cherret.zaprett.byedpi.ByeDpiVpnService
|
||||
import com.cherret.zaprett.R
|
||||
import com.cherret.zaprett.byedpi.ServiceStatus
|
||||
import com.cherret.zaprett.utils.download
|
||||
import com.cherret.zaprett.utils.getActiveStrategy
|
||||
import com.cherret.zaprett.utils.getBinVersion
|
||||
import com.cherret.zaprett.utils.getChangelog
|
||||
import com.cherret.zaprett.utils.getModuleVersion
|
||||
@@ -113,10 +115,19 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
} else {
|
||||
if (ByeDpiVpnService.status == ServiceStatus.Disconnected || ByeDpiVpnService.status == ServiceStatus.Failed) {
|
||||
scope.launch {
|
||||
snackbarHostState.showSnackbar(context.getString(R.string.snack_starting_service))
|
||||
if (getActiveStrategy(prefs).isNotEmpty()) {
|
||||
scope.launch {
|
||||
snackbarHostState.showSnackbar(context.getString(R.string.snack_starting_service))
|
||||
}
|
||||
_requestVpnPermission.value = true
|
||||
}
|
||||
else {
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.toast_no_strategy_selected),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
_requestVpnPermission.value = true
|
||||
}
|
||||
else {
|
||||
scope.launch {
|
||||
|
||||
Reference in New Issue
Block a user