Skip to content

Commit

Permalink
VpnService policy
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a authored and purofle committed Oct 31, 2023
1 parent 5dc09ca commit b77d1fc
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/src/main/java/io/nekohasekai/sagernet/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import io.nekohasekai.sagernet.group.GroupUpdater
import io.nekohasekai.sagernet.ktx.*
import io.nekohasekai.sagernet.widget.ListHolderListener
import moe.matsuri.nb4a.utils.Util
import java.io.File
import java.util.*

class MainActivity : ThemedActivity(),
Expand Down Expand Up @@ -97,6 +98,8 @@ class MainActivity : ThemedActivity(),
onNewIntent(intent)
}

refreshNavMenu(DataStore.enableClashAPI)

// sdk 33 notification
if (Build.VERSION.SDK_INT >= 33) {
val checkPermission =
Expand All @@ -109,7 +112,24 @@ class MainActivity : ThemedActivity(),
}
}

refreshNavMenu(DataStore.enableClashAPI)
// consent
try {
val f = File(application.filesDir, "consent")
if (!f.exists()) {
MaterialAlertDialogBuilder(this@MainActivity)
.setTitle("VpnService policy")
.setMessage("Since the main function of this application is VPN, it must use VpnService.")
.setPositiveButton(R.string.yes) { _, _ ->
f.createNewFile()
}
.setNegativeButton(android.R.string.cancel) { _, _ ->
finish()
}
.show()
}
} catch (e: Exception) {
Logs.w(e)
}
}

fun refreshNavMenu(clashApi: Boolean) {
Expand Down

0 comments on commit b77d1fc

Please sign in to comment.