diff --git a/README.md b/README.md index c6d0e669..5e27c659 100644 --- a/README.md +++ b/README.md @@ -52,11 +52,11 @@ Feature of [Clash.Meta](https://github.com/MetaCubeX/Clash.Meta) APP package name is `com.github.metacubex.clash.meta` - 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 - - 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 - - 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 - URL Scheme `clash://install-config?url=` or `clashmeta://install-config?url=` diff --git a/app/src/main/java/com/github/kr328/clash/LogcatActivity.kt b/app/src/main/java/com/github/kr328/clash/LogcatActivity.kt index 4bd13c0f..04a24870 100644 --- a/app/src/main/java/com/github/kr328/clash/LogcatActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/LogcatActivity.kt @@ -8,6 +8,7 @@ import android.os.IBinder import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts 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.intent import com.github.kr328.clash.common.util.ticker @@ -47,6 +48,7 @@ class LogcatActivity : BaseActivity() { val messages = try { LogcatReader(this, file).readAll() } catch (e: Exception) { + Log.e("Fail to read log file ${file.fileName}: ${e.message}") return showInvalid() } diff --git a/app/src/main/java/com/github/kr328/clash/log/LogcatReader.kt b/app/src/main/java/com/github/kr328/clash/log/LogcatReader.kt index f26d795d..debb4db9 100644 --- a/app/src/main/java/com/github/kr328/clash/log/LogcatReader.kt +++ b/app/src/main/java/com/github/kr328/clash/log/LogcatReader.kt @@ -16,16 +16,28 @@ class LogcatReader(context: Context, file: LogFile) : AutoCloseable { } fun readAll(): List { + var lastTime = Date(0) return reader.lineSequence() .map { it.trim() } .filter { !it.startsWith("#") } .map { it.split(":", limit = 3) } .map { - LogMessage( - time = Date(it[0].toLong()), - level = LogMessage.Level.valueOf(it[1]), - message = it[2] - ) + val time = it[0].toLongOrNull()?.let { Date(it) } ?: lastTime + val logMessage = if (it[0].toLongOrNull() != null) { + LogMessage( + time = time, + level = LogMessage.Level.valueOf(it[1]), + message = it[2] + ) + } else { + LogMessage( + time = time, + level = LogMessage.Level.Warning, // or any default level + message = it.joinToString(":") + ) + } + lastTime = time + logMessage } .toList() }