fix: auto tunnel service worker

This commit is contained in:
Zane Schepke
2025-10-16 00:27:02 -04:00
parent b30b0f3cd2
commit 60935c9ff1
7 changed files with 12 additions and 11 deletions
+1
View File
@@ -178,6 +178,7 @@ dependencies {
implementation(libs.bundles.hilt.android) implementation(libs.bundles.hilt.android)
implementation(libs.bundles.androidx.work) implementation(libs.bundles.androidx.work)
ksp(libs.hilt.android.compiler) ksp(libs.hilt.android.compiler)
ksp(libs.androidx.hilt.compiler)
// Networking and serialization // Networking and serialization
implementation(libs.bundles.ktor.client) implementation(libs.bundles.ktor.client)
@@ -121,6 +121,8 @@ constructor(
context.bindService(intent, autoTunnelServiceConnection, Context.BIND_AUTO_CREATE) context.bindService(intent, autoTunnelServiceConnection, Context.BIND_AUTO_CREATE)
} }
suspend fun startAutoTunnelService() = autoTunnelMutex.withLock { startServiceInternal() }
private fun stopServiceInternal() { private fun stopServiceInternal() {
_autoTunnelService.value?.stop() _autoTunnelService.value?.stop()
try { try {
@@ -47,7 +47,6 @@ constructor(
} }
} }
// TODO this needs to be changed
override suspend fun doWork(): Result = override suspend fun doWork(): Result =
withContext(ioDispatcher) { withContext(ioDispatcher) {
Timber.i("Service worker started") Timber.i("Service worker started")
@@ -55,7 +54,7 @@ constructor(
Timber.i("Checking to see if auto-tunnel has been killed by system") Timber.i("Checking to see if auto-tunnel has been killed by system")
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null) { if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null) {
Timber.i("Service has been killed by system, restoring.") Timber.i("Service has been killed by system, restoring.")
autoTunnelSettingsRepository.updateAutoTunnelEnabled(true) serviceManager.startAutoTunnelService()
} }
} }
Result.success() Result.success()
+3 -3
View File
@@ -55,7 +55,7 @@ androidx-lifecycle-core = ["androidx-lifecycle-runtime-ktx", "androidx-lifecycle
# Compose UI essentials # Compose UI essentials
androidx-compose-ui = ["androidx-compose-ui", "androidx-compose-ui-graphics", "androidx-compose-ui-tooling-preview"] androidx-compose-ui = ["androidx-compose-ui", "androidx-compose-ui-graphics", "androidx-compose-ui-tooling-preview"]
androidx-compose-material = ["androidx-material3", "androidx-compose-animation-graphics"] # Merged animation for UI fluidity androidx-compose-material = ["androidx-material3", "androidx-compose-animation-graphics"]
# Material and icons # Material and icons
google-material = ["material"] google-material = ["material"]
@@ -63,7 +63,7 @@ material-icons = ["material-icons-core", "material-icons-extended"]
# Navigation and related # Navigation and related
androidx-navigation3 = ["androidx-navigation3-runtime", "androidx-navigation3-ui"] androidx-navigation3 = ["androidx-navigation3-runtime", "androidx-navigation3-ui"]
navigation-lifecycle = ["androidx-lifecycle-viewmodel-navigation3"] # Kept as-is since it's tightly coupled navigation-lifecycle = ["androidx-lifecycle-viewmodel-navigation3"]
# Accompanist utilities # Accompanist utilities
accompanist = ["accompanist-permissions", "accompanist-drawablepainter"] accompanist = ["accompanist-permissions", "accompanist-drawablepainter"]
@@ -74,7 +74,7 @@ androidx-datastore = ["androidx-datastore-preferences"]
# Hilt DI and work # Hilt DI and work
hilt-android = ["hilt-android"] hilt-android = ["hilt-android"]
androidx-hilt = ["androidx-hilt-compiler", "androidx-hilt-work", "androidx-hilt-hilt-navigation-compose"] androidx-hilt = ["androidx-hilt-work", "androidx-hilt-hilt-navigation-compose"]
androidx-work = ["androidx-work-runtime"] androidx-work = ["androidx-work-runtime"]
# Ktor networking # Ktor networking
@@ -1,12 +1,12 @@
package com.zaneschepke.logcatter package com.zaneschepke.logcatter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.BufferedOutputStream import java.io.BufferedOutputStream
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream import java.util.zip.ZipOutputStream
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
class LogFileManager( class LogFileManager(
private val logDir: String, private val logDir: String,
@@ -1,13 +1,13 @@
package com.zaneschepke.logcatter package com.zaneschepke.logcatter
import com.zaneschepke.logcatter.model.LogMessage import com.zaneschepke.logcatter.model.LogMessage
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.flowOn
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
class LogcatStreamReader(private val pid: Int, private val fileManager: LogFileManager) { class LogcatStreamReader(private val pid: Int, private val fileManager: LogFileManager) {
private val bufferSize = 1024 private val bufferSize = 1024
@@ -26,7 +26,6 @@ data class LogMessage(
logcatLine, logcatLine,
) )
} else { } else {
// TODO improve this
val parts = logcatLine.trim().split(" ").filter { it.isNotEmpty() } val parts = logcatLine.trim().split(" ").filter { it.isNotEmpty() }
val epochParts = parts[0].split(".").map { it.toLong() } val epochParts = parts[0].split(".").map { it.toLong() }
val message = parts.subList(5, parts.size).joinToString(" ") val message = parts.subList(5, parts.size).joinToString(" ")