mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 22:50:05 +08:00
log level option
This commit is contained in:
parent
fafe14b7c6
commit
0413f28ce7
@ -50,7 +50,7 @@ object Key {
|
||||
|
||||
const val TCP_KEEP_ALIVE_INTERVAL = "tcpKeepAliveInterval"
|
||||
const val RULES_PROVIDER = "rulesProvider"
|
||||
const val ENABLE_LOG = "enableLog"
|
||||
const val LOG_LEVEL = "logLevel"
|
||||
const val LOG_BUF_SIZE = "logBufSize"
|
||||
const val MTU = "mtu"
|
||||
const val ALWAYS_SHOW_ADDRESS = "alwaysShowAddress"
|
||||
|
||||
@ -77,7 +77,7 @@ class SagerNet : Application(),
|
||||
filesDir.absolutePath + "/",
|
||||
externalAssets.absolutePath + "/",
|
||||
DataStore.logBufSize,
|
||||
DataStore.enableLog,
|
||||
DataStore.logLevel > 0,
|
||||
this
|
||||
)
|
||||
|
||||
|
||||
@ -185,7 +185,7 @@ abstract class BoxInstance(
|
||||
"--config",
|
||||
configFile.absolutePath,
|
||||
"--log-level",
|
||||
if (DataStore.enableLog) "trace" else "warn",
|
||||
if (DataStore.logLevel > 0) "trace" else "warn",
|
||||
"client"
|
||||
)
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
|
||||
var dnsNetwork by configurationStore.stringSet(Key.DNS_NETWORK)
|
||||
|
||||
var rulesProvider by configurationStore.stringToInt(Key.RULES_PROVIDER)
|
||||
var enableLog by configurationStore.boolean(Key.ENABLE_LOG)
|
||||
var logLevel by configurationStore.stringToInt(Key.LOG_LEVEL)
|
||||
var logBufSize by configurationStore.int(Key.LOG_BUF_SIZE) { 0 }
|
||||
var acquireWakeLock by configurationStore.boolean(Key.ACQUIRE_WAKE_LOCK)
|
||||
|
||||
|
||||
@ -146,6 +146,17 @@ fun buildConfig(
|
||||
}
|
||||
}
|
||||
|
||||
log = LogOptions().apply {
|
||||
level = when (DataStore.logLevel) {
|
||||
0 -> "panic"
|
||||
1 -> "warn"
|
||||
2 -> "info"
|
||||
3 -> "debug"
|
||||
4 -> "trace"
|
||||
else -> "info"
|
||||
}
|
||||
}
|
||||
|
||||
dns = DNSOptions().apply {
|
||||
// TODO nb4a hosts?
|
||||
// hosts = DataStore.hosts.split("\n")
|
||||
|
||||
@ -80,7 +80,7 @@ fun NaiveBean.buildNaiveConfig(port: Int): String {
|
||||
if (extraHeaders.isNotBlank()) {
|
||||
put("extra-headers", extraHeaders.split("\n").joinToString("\r\n"))
|
||||
}
|
||||
if (DataStore.enableLog) {
|
||||
if (DataStore.logLevel > 0) {
|
||||
put("log", "")
|
||||
}
|
||||
if (insecureConcurrency > 0) {
|
||||
|
||||
@ -91,7 +91,7 @@ fun TrojanGoBean.buildTrojanGoConfig(port: Int): String {
|
||||
put("password", JSONArray().apply {
|
||||
put(password)
|
||||
})
|
||||
put("log_level", if (DataStore.enableLog) 0 else 2)
|
||||
put("log_level", if (DataStore.logLevel > 0) 0 else 2)
|
||||
if (Protocols.shouldEnableMux("trojan-go")) put("mux", JSONObject().apply {
|
||||
put("enabled", true)
|
||||
put("concurrency", DataStore.muxConcurrency)
|
||||
|
||||
@ -59,6 +59,6 @@ fun TuicBean.buildTuicConfig(port: Int, cacheFile: (() -> File)?): String {
|
||||
put("ip", LOCALHOST)
|
||||
put("port", port)
|
||||
})
|
||||
put("log_level", if (DataStore.enableLog) "debug" else "info")
|
||||
put("log_level", if (DataStore.logLevel > 0) "debug" else "info")
|
||||
}.toStringPretty()
|
||||
}
|
||||
|
||||
@ -31,10 +31,7 @@ import io.nekohasekai.sagernet.bg.Executable
|
||||
import io.nekohasekai.sagernet.database.DataStore
|
||||
import io.nekohasekai.sagernet.ui.MainActivity
|
||||
import io.nekohasekai.sagernet.ui.ThemedActivity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.*
|
||||
import moe.matsuri.nb4a.utils.NGUtil
|
||||
import java.io.FileDescriptor
|
||||
import java.net.*
|
||||
@ -241,10 +238,13 @@ fun Fragment.needReload() {
|
||||
|
||||
fun Fragment.needRestart() {
|
||||
snackbar("Restart APP to apply changes.").setAction(R.string.apply) {
|
||||
Executable.killAll(true)
|
||||
ProcessPhoenix.triggerRebirth(
|
||||
requireContext(), Intent(requireContext(), MainActivity::class.java)
|
||||
)
|
||||
SagerNet.stopService()
|
||||
val ctx = requireContext()
|
||||
runOnDefaultDispatcher {
|
||||
delay(500)
|
||||
Executable.killAll(true)
|
||||
ProcessPhoenix.triggerRebirth(ctx, Intent(ctx, MainActivity::class.java))
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ import io.nekohasekai.sagernet.utils.Theme
|
||||
import io.nekohasekai.sagernet.widget.AppListPreference
|
||||
import moe.matsuri.nb4a.Protocols
|
||||
import moe.matsuri.nb4a.ui.ColorPickerPreference
|
||||
import moe.matsuri.nb4a.ui.LongClickMenuPreference
|
||||
import moe.matsuri.nb4a.ui.LongClickSwitchPreference
|
||||
import moe.matsuri.nb4a.ui.MTUPreference
|
||||
|
||||
@ -117,14 +118,14 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
||||
val requireTransproxy = findPreference<SwitchPreference>(Key.REQUIRE_TRANSPROXY)!!
|
||||
val transproxyPort = findPreference<EditTextPreference>(Key.TRANSPROXY_PORT)!!
|
||||
val transproxyMode = findPreference<SimpleMenuPreference>(Key.TRANSPROXY_MODE)!!
|
||||
val enableLog = findPreference<LongClickSwitchPreference>(Key.ENABLE_LOG)!!
|
||||
val logLevel = findPreference<LongClickMenuPreference>(Key.LOG_LEVEL)!!
|
||||
val mtu = findPreference<MTUPreference>(Key.MTU)!!
|
||||
|
||||
enableLog.setOnPreferenceChangeListener { _, _ ->
|
||||
logLevel.setOnPreferenceChangeListener { _, _ ->
|
||||
needRestart()
|
||||
true
|
||||
}
|
||||
enableLog.setOnLongClickListener {
|
||||
logLevel.setOnLongClickListener {
|
||||
if (context == null) return@setOnLongClickListener true
|
||||
|
||||
val view = EditText(context).apply {
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package moe.matsuri.nb4a.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import com.takisoft.preferencex.SimpleMenuPreference
|
||||
import io.nekohasekai.sagernet.R
|
||||
|
||||
class LongClickMenuPreference
|
||||
@JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = com.takisoft.preferencex.simplemenu.R.attr.simpleMenuPreferenceStyle,
|
||||
defStyleRes: Int = R.style.Preference_SimpleMenuPreference
|
||||
) : SimpleMenuPreference(
|
||||
context, attrs, defStyleAttr, defStyleRes
|
||||
) {
|
||||
private var mLongClickListener: View.OnLongClickListener? = null
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
val itemView: View = holder.itemView
|
||||
itemView.setOnLongClickListener {
|
||||
mLongClickListener?.onLongClick(it) ?: true
|
||||
}
|
||||
}
|
||||
|
||||
fun setOnLongClickListener(longClickListener: View.OnLongClickListener) {
|
||||
this.mLongClickListener = longClickListener
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string-array name="int_array_2">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="int_array_3">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="int_array_4">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="int_array_5">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="bypass_private_route">
|
||||
<item>1.0.0.0/8</item>
|
||||
<item>2.0.0.0/7</item>
|
||||
@ -294,10 +321,6 @@
|
||||
<item>TPROXY</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="int_array_2">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="naive_proto_entry">
|
||||
<item>HTTPS</item>
|
||||
@ -315,13 +338,6 @@
|
||||
<item>@string/disable</item>
|
||||
<item>@string/auto</item>
|
||||
</string-array>
|
||||
<string-array name="int_array_4">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="ipv6_mode">
|
||||
<item>@string/disable</item>
|
||||
<item>@string/enable</item>
|
||||
@ -348,11 +364,6 @@
|
||||
<item>leastPing</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="int_array_3">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="group_types">
|
||||
<item>@string/group_basic</item>
|
||||
@ -478,4 +489,12 @@
|
||||
<item>v2ray-plugin</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="log_level" translatable="false">
|
||||
<item>none</item>
|
||||
<item>warn</item>
|
||||
<item>info</item>
|
||||
<item>debug</item>
|
||||
<item>trace</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@ -524,5 +524,6 @@ Anyone can write advanced plugins, which can control NekoBox. please download an
|
||||
<string name="enable_clash_api">Enable Clash API</string>
|
||||
<string name="enable_clash_api_summary"><![CDATA[Provide clash api & yacd dashboard at 127.0.0.1:9090]]></string>
|
||||
<string name="xtls_flow">Flow (VLESS Sub-protocol)</string>
|
||||
<string name="log_level">Log Level</string>
|
||||
|
||||
</resources>
|
||||
@ -71,11 +71,14 @@
|
||||
app:summary="@string/show_direct_speed_sum"
|
||||
app:title="@string/show_direct_speed"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<moe.matsuri.nb4a.ui.LongClickSwitchPreference
|
||||
<moe.matsuri.nb4a.ui.LongClickMenuPreference
|
||||
app:defaultValue="0"
|
||||
app:entries="@array/log_level"
|
||||
app:entryValues="@array/int_array_5"
|
||||
app:icon="@drawable/ic_baseline_bug_report_24"
|
||||
app:key="enableLog"
|
||||
app:summary="@string/enable_log_sum"
|
||||
app:title="@string/enable_log" />
|
||||
app:key="logLevel"
|
||||
app:title="@string/log_level"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/cag_route">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user