Allow user to exit app easily
This commit is contained in:
@@ -21,17 +21,16 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
|
||||
|
||||
private val active = mutableMapOf<String, RoutingManager>()
|
||||
|
||||
fun clean() {
|
||||
fun clean(reinit: Boolean = true) {
|
||||
for (manager in active.values) manager.routing?.stop()
|
||||
val cleaned = try {
|
||||
try {
|
||||
Routing.clean()
|
||||
true
|
||||
} catch (e: RuntimeException) {
|
||||
Timber.d(e)
|
||||
SmartSnackbar.make(e).show()
|
||||
false
|
||||
return
|
||||
}
|
||||
if (cleaned) for (manager in active.values) manager.initRouting()
|
||||
if (reinit) for (manager in active.values) manager.initRouting()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,14 @@ import be.mygod.vpnhotspot.preference.AlwaysAutoCompleteEditTextPreferenceDialog
|
||||
import be.mygod.vpnhotspot.preference.SharedPreferenceDataStore
|
||||
import be.mygod.vpnhotspot.util.RootSession
|
||||
import be.mygod.vpnhotspot.util.launchUrl
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.PrintWriter
|
||||
import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
@@ -44,7 +45,13 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
||||
true
|
||||
}
|
||||
findPreference<Preference>(IpMonitor.KEY)!!.setOnPreferenceChangeListener { _, _ ->
|
||||
SmartSnackbar.make(R.string.settings_restart_required).show()
|
||||
Snackbar.make(requireView(), R.string.settings_restart_required, Snackbar.LENGTH_LONG).apply {
|
||||
setAction(R.string.settings_exit_app) {
|
||||
RoutingManager.clean(false)
|
||||
RootSession.trimMemory()
|
||||
exitProcess(0)
|
||||
}
|
||||
}.show()
|
||||
true
|
||||
}
|
||||
findPreference<Preference>("misc.logcat")!!.setOnPreferenceClickListener {
|
||||
|
||||
@@ -113,6 +113,7 @@
|
||||
<string name="settings_misc_donate_summary">请给我钱</string>
|
||||
<string name="settings_misc_donate_more">PayPal, Flattr 等其他方式…</string>
|
||||
<string name="settings_restart_required">重启应用以应用新的设置。</string>
|
||||
<string name="settings_exit_app">退出</string>
|
||||
|
||||
<string name="notification_tethering_title">VPN 共享已启用</string>
|
||||
<string name="notification_channel_tethering">VPN 共享服务</string>
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
<string name="settings_misc_donate_summary">I love money</string>
|
||||
<string name="settings_misc_donate_more">PayPal, Flattr, more…</string>
|
||||
<string name="settings_restart_required">Restart this app to apply this setting.</string>
|
||||
<string name="settings_exit_app">Exit</string>
|
||||
|
||||
<string name="notification_tethering_title">VPN tethering active</string>
|
||||
<string name="notification_channel_tethering">VPN Tethering Service</string>
|
||||
|
||||
Reference in New Issue
Block a user