mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix: Some attempt
This commit is contained in:
parent
cea9da9c6d
commit
5fa5815541
3 changed files with 34 additions and 27 deletions
|
@ -33,6 +33,7 @@ import coil3.request.crossfade
|
||||||
import coil3.util.DebugLogger
|
import coil3.util.DebugLogger
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
|
import com.hippo.unifile.UniFile
|
||||||
import eu.kanade.tachiyomi.appwidget.TachiyomiWidgetManager
|
import eu.kanade.tachiyomi.appwidget.TachiyomiWidgetManager
|
||||||
import eu.kanade.tachiyomi.core.preference.Preference
|
import eu.kanade.tachiyomi.core.preference.Preference
|
||||||
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
||||||
|
@ -55,6 +56,7 @@ import eu.kanade.tachiyomi.util.system.GLUtil
|
||||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||||
import eu.kanade.tachiyomi.util.system.launchIO
|
import eu.kanade.tachiyomi.util.system.launchIO
|
||||||
import eu.kanade.tachiyomi.util.system.localeContext
|
import eu.kanade.tachiyomi.util.system.localeContext
|
||||||
|
import eu.kanade.tachiyomi.util.system.nameWithoutExtension
|
||||||
import eu.kanade.tachiyomi.util.system.notification
|
import eu.kanade.tachiyomi.util.system.notification
|
||||||
import eu.kanade.tachiyomi.util.system.setToDefault
|
import eu.kanade.tachiyomi.util.system.setToDefault
|
||||||
import eu.kanade.tachiyomi.util.system.setupFileLog
|
import eu.kanade.tachiyomi.util.system.setupFileLog
|
||||||
|
@ -88,14 +90,6 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
||||||
|
|
||||||
private val disableIncognitoReceiver = DisableIncognitoReceiver()
|
private val disableIncognitoReceiver = DisableIncognitoReceiver()
|
||||||
|
|
||||||
private fun buildWritersToAdd(
|
|
||||||
logPath: Path?,
|
|
||||||
) = buildList {
|
|
||||||
if (!BuildConfig.DEBUG) add(CrashlyticsLogWriter())
|
|
||||||
|
|
||||||
if (logPath != null) add(Logger.setupFileLog(logPath, BuildConfig.BUILD_TYPE))
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("LaunchActivityFromNotification")
|
@SuppressLint("LaunchActivityFromNotification")
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super<Application>.onCreate()
|
super<Application>.onCreate()
|
||||||
|
@ -119,8 +113,7 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
||||||
|
|
||||||
val scope = ProcessLifecycleOwner.get().lifecycleScope
|
val scope = ProcessLifecycleOwner.get().lifecycleScope
|
||||||
|
|
||||||
val logPath = storageManager.getLogsDirectory()?.filePath?.let { path -> Path(path) }
|
Logger.setToDefault(buildLogWritersToAdd(storageManager.getLogsFile()))
|
||||||
Logger.setToDefault(buildLogWritersToAdd(logPath))
|
|
||||||
|
|
||||||
basePreferences.crashReport().changes()
|
basePreferences.crashReport().changes()
|
||||||
.onEach {
|
.onEach {
|
||||||
|
@ -291,11 +284,18 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildLogWritersToAdd(
|
fun buildLogWritersToAdd(
|
||||||
logPath: Path?,
|
logFile: UniFile?,
|
||||||
) = buildList {
|
) = buildList {
|
||||||
if (!BuildConfig.DEBUG) add(CrashlyticsLogWriter())
|
if (!BuildConfig.DEBUG) add(CrashlyticsLogWriter())
|
||||||
|
|
||||||
// if (logPath != null) add(Logger.setupFileLog(logPath, BuildConfig.BUILD_TYPE))
|
//val fileName = logFile?.nameWithoutExtension
|
||||||
|
//val filePath = logFile?.parentFile?.filePath?.let { path -> Path(path) }
|
||||||
|
//if (filePath != null && fileName != null) add(
|
||||||
|
// Logger.setupFileLog(
|
||||||
|
// logFileName = fileName,
|
||||||
|
// logPath = filePath,
|
||||||
|
// )
|
||||||
|
//)
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val ACTION_DISABLE_INCOGNITO_MODE = "tachi.action.DISABLE_INCOGNITO_MODE"
|
private const val ACTION_DISABLE_INCOGNITO_MODE = "tachi.action.DISABLE_INCOGNITO_MODE"
|
||||||
|
|
|
@ -4,9 +4,13 @@ import android.content.Context
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import co.touchlab.kermit.Logger
|
import co.touchlab.kermit.Logger
|
||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.buildLogWritersToAdd
|
import eu.kanade.tachiyomi.buildLogWritersToAdd
|
||||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||||
import eu.kanade.tachiyomi.util.system.setToDefault
|
import eu.kanade.tachiyomi.util.system.setToDefault
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
@ -46,16 +50,17 @@ class StorageManager(
|
||||||
}
|
}
|
||||||
parent.createDirectory(COVERS_PATH)
|
parent.createDirectory(COVERS_PATH)
|
||||||
parent.createDirectory(PAGES_PATH)
|
parent.createDirectory(PAGES_PATH)
|
||||||
parent.createDirectory(LOGS_PATH)?.also {
|
parent.createDirectory(LOGS_PATH)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Logger.setToDefault(buildLogWritersToAdd(it.filePath?.let { path -> Path(path) }))
|
Logger.setToDefault(buildLogWritersToAdd(getLogsFile()))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Just in case something went horribly wrong
|
// Just in case something went horribly wrong
|
||||||
Logger.setToDefault(buildLogWritersToAdd(null))
|
Logger.setToDefault(buildLogWritersToAdd(null))
|
||||||
Logger.e(e) { "Something went wrong while trying to setup log file" }
|
Logger.e(e) { "Something went wrong while trying to setup log file" }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
_changes.send(Unit)
|
_changes.send(Unit)
|
||||||
}
|
}
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
@ -93,6 +98,11 @@ class StorageManager(
|
||||||
fun getLogsDirectory(): UniFile? {
|
fun getLogsDirectory(): UniFile? {
|
||||||
return baseDir?.createDirectory(LOGS_PATH)
|
return baseDir?.createDirectory(LOGS_PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getLogsFile(): UniFile? {
|
||||||
|
val date = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Date())
|
||||||
|
return getLogsDirectory()?.createFile("${date}-${BuildConfig.BUILD_TYPE}.log")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val BACKUPS_PATH = "backup"
|
private const val BACKUPS_PATH = "backup"
|
||||||
|
|
|
@ -5,9 +5,6 @@ import co.touchlab.kermit.Logger
|
||||||
import co.touchlab.kermit.io.RollingFileLogWriter
|
import co.touchlab.kermit.io.RollingFileLogWriter
|
||||||
import co.touchlab.kermit.io.RollingFileLogWriterConfig
|
import co.touchlab.kermit.io.RollingFileLogWriterConfig
|
||||||
import co.touchlab.kermit.platformLogWriter
|
import co.touchlab.kermit.platformLogWriter
|
||||||
import kotlinx.datetime.Clock
|
|
||||||
import kotlinx.datetime.TimeZone
|
|
||||||
import kotlinx.datetime.todayIn
|
|
||||||
import kotlinx.io.files.Path
|
import kotlinx.io.files.Path
|
||||||
|
|
||||||
fun Logger.w(e: Throwable) = w(e) { "Something is not right..." }
|
fun Logger.w(e: Throwable) = w(e) { "Something is not right..." }
|
||||||
|
@ -20,12 +17,12 @@ fun Logger.setToDefault(
|
||||||
Logger.setTag("Yokai")
|
Logger.setTag("Yokai")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Logger.setupFileLog(logPath: Path, buildType: String? = null): LogWriter {
|
fun Logger.setupFileLog(logFileName: String, logPath: Path): LogWriter {
|
||||||
val date = Clock.System.todayIn(TimeZone.currentSystemDefault())
|
|
||||||
return RollingFileLogWriter(
|
return RollingFileLogWriter(
|
||||||
config = RollingFileLogWriterConfig(
|
config = RollingFileLogWriterConfig(
|
||||||
logFileName = date.toString() + if (buildType != null) "-$buildType" else "" + ".log",
|
logFileName = logFileName,
|
||||||
logFilePath = logPath,
|
logFilePath = logPath,
|
||||||
|
maxLogFiles = 1,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue