Skip to content

Commit

Permalink
show error on vpn permission denial.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginder-Singh committed Oct 17, 2024
1 parent 988b881 commit c1d996c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
31 changes: 29 additions & 2 deletions base/src/main/java/com/windscribe/vpn/alert/ForegroundAlert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fun showRetryDialog(message: String, retryCallBack: () -> Unit, cancelCallBack:
dialog.dismiss()
if (which == AlertDialog.BUTTON_POSITIVE) {
retryCallBack()
}else if(which == AlertDialog.BUTTON_NEGATIVE){
} else if (which == AlertDialog.BUTTON_NEGATIVE) {
cancelCallBack()
}
}
Expand Down Expand Up @@ -110,12 +110,39 @@ fun showAlertDialog(
positionButtonLabel,
DialogInterface.OnClickListener(function = listener)
)
setNegativeButton(negativeButtonLabel, DialogInterface.OnClickListener(function = listener))
setNegativeButton(
negativeButtonLabel,
DialogInterface.OnClickListener(function = listener)
)
show()
}
}
}

fun showErrorDialog(activity: Activity, message: String, callBack: () -> Unit) {
val builder = createDialogBuilder(activity, message)
activity.let {
it.runOnUiThread {
builder.setOnDismissListener {
callBack()
}
builder.setOnCancelListener {
callBack()
}
val listener = { dialog: DialogInterface, _: Int ->
dialog.dismiss()
}
with(builder) {
setNeutralButton(
appContext.getString(R.string.ok),
DialogInterface.OnClickListener(function = listener)
)
show()
}
}
}
}

fun safeDialog(block: (activity: Activity) -> Unit) {
appContext.activeActivity?.let {
it.runOnUiThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import android.os.Bundle
import com.windscribe.vpn.R.layout
import com.windscribe.vpn.Windscribe
import com.windscribe.vpn.Windscribe.Companion.appContext
import com.windscribe.vpn.alert.showAlertDialog
import com.windscribe.vpn.alert.showErrorDialog
import com.windscribe.vpn.autoconnection.ProtocolInformation
import com.windscribe.vpn.backend.VpnBackendHolder
import com.windscribe.vpn.repository.LocationRepository
Expand Down Expand Up @@ -121,9 +123,19 @@ class VPNPermissionActivity : Activity() {
}
} else if (resultCode == RESULT_CANCELED) {
logger.debug("User denied VPN permission.")
scope.launch {
vpnController.disconnectAsync()
finish()
showErrorDialog(this,
"Windscribe requires VPN permission to configure VPN. " +
"Sometimes you may see this error if another VPN app is configured as 'Always on VPN'. " +
"Please turn off 'Always on' in all profiles.") {
scope.launch {
try {
vpnController.disconnectAsync()
} catch (e: Exception) {
logger.error("Failed to disconnect VPN: ${e.message}")
} finally {
finish()
}
}
}
}
}
Expand Down

0 comments on commit c1d996c

Please sign in to comment.