mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2025-02-22 09:43:15 +03:00
fix: adapt to format-broken logs (#165)
This commit is contained in:
parent
00b2c816a4
commit
ad471f3837
@ -52,11 +52,11 @@ Feature of [Clash.Meta](https://github.com/MetaCubeX/Clash.Meta)
|
|||||||
APP package name is `com.github.metacubex.clash.meta`
|
APP package name is `com.github.metacubex.clash.meta`
|
||||||
|
|
||||||
- Toggle Clash.Meta service status
|
- Toggle Clash.Meta service status
|
||||||
- Send intent to `com.github.kr328.clash.ExternalControlActivity` with action `com.github.metacubex.clash.meta.action.TOGGLE_CLASH`
|
- Send intent to activity `com.github.kr328.clash.ExternalControlActivity` with action `com.github.metacubex.clash.meta.action.TOGGLE_CLASH`
|
||||||
- Start Clash.Meta service
|
- Start Clash.Meta service
|
||||||
- Send intent to `com.github.kr328.clash.ExternalControlActivity` with action `com.github.metacubex.clash.meta.action.START_CLASH`
|
- Send intent to activity `com.github.kr328.clash.ExternalControlActivity` with action `com.github.metacubex.clash.meta.action.START_CLASH`
|
||||||
- Stop Clash.Meta service
|
- Stop Clash.Meta service
|
||||||
- Send intent to `com.github.kr328.clash.ExternalControlActivity` with action `com.github.metacubex.clash.meta.action.STOP_CLASH`
|
- Send intent to activity `com.github.kr328.clash.ExternalControlActivity` with action `com.github.metacubex.clash.meta.action.STOP_CLASH`
|
||||||
- Import a profile
|
- Import a profile
|
||||||
- URL Scheme `clash://install-config?url=<encoded URI>` or `clashmeta://install-config?url=<encoded URI>`
|
- URL Scheme `clash://install-config?url=<encoded URI>` or `clashmeta://install-config?url=<encoded URI>`
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import android.os.IBinder
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import com.github.kr328.clash.common.compat.startForegroundServiceCompat
|
import com.github.kr328.clash.common.compat.startForegroundServiceCompat
|
||||||
|
import com.github.kr328.clash.common.log.Log
|
||||||
import com.github.kr328.clash.common.util.fileName
|
import com.github.kr328.clash.common.util.fileName
|
||||||
import com.github.kr328.clash.common.util.intent
|
import com.github.kr328.clash.common.util.intent
|
||||||
import com.github.kr328.clash.common.util.ticker
|
import com.github.kr328.clash.common.util.ticker
|
||||||
@ -47,6 +48,7 @@ class LogcatActivity : BaseActivity<LogcatDesign>() {
|
|||||||
val messages = try {
|
val messages = try {
|
||||||
LogcatReader(this, file).readAll()
|
LogcatReader(this, file).readAll()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Log.e("Fail to read log file ${file.fileName}: ${e.message}")
|
||||||
return showInvalid()
|
return showInvalid()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,16 +16,28 @@ class LogcatReader(context: Context, file: LogFile) : AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun readAll(): List<LogMessage> {
|
fun readAll(): List<LogMessage> {
|
||||||
|
var lastTime = Date(0)
|
||||||
return reader.lineSequence()
|
return reader.lineSequence()
|
||||||
.map { it.trim() }
|
.map { it.trim() }
|
||||||
.filter { !it.startsWith("#") }
|
.filter { !it.startsWith("#") }
|
||||||
.map { it.split(":", limit = 3) }
|
.map { it.split(":", limit = 3) }
|
||||||
.map {
|
.map {
|
||||||
|
val time = it[0].toLongOrNull()?.let { Date(it) } ?: lastTime
|
||||||
|
val logMessage = if (it[0].toLongOrNull() != null) {
|
||||||
LogMessage(
|
LogMessage(
|
||||||
time = Date(it[0].toLong()),
|
time = time,
|
||||||
level = LogMessage.Level.valueOf(it[1]),
|
level = LogMessage.Level.valueOf(it[1]),
|
||||||
message = it[2]
|
message = it[2]
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
LogMessage(
|
||||||
|
time = time,
|
||||||
|
level = LogMessage.Level.Warning, // or any default level
|
||||||
|
message = it.joinToString(":")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
lastTime = time
|
||||||
|
logMessage
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user