Skip to content

Commit

Permalink
prevent potential crash
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 16, 2023
1 parent 10871ee commit 53a79e2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.datlag.burningseries

import androidx.multidex.MultiDexApplication
import dev.datlag.burningseries.module.NetworkModule
import dev.datlag.burningseries.other.StateSaver
import dev.datlag.sekret.NativeLoader
import io.github.aakira.napier.DebugAntilog
import io.github.aakira.napier.Napier
Expand All @@ -27,6 +28,6 @@ class App : MultiDexApplication(), DIAware {
if (BuildConfig.DEBUG) {
Napier.base(DebugAntilog())
}
NativeLoader.loadLibrary("sekret")
StateSaver.sekretLibraryLoaded = NativeLoader.loadLibrary("sekret")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import dev.datlag.burningseries.common.lifecycle.LocalLifecycleOwner
import dev.datlag.burningseries.model.common.systemProperty
import dev.datlag.burningseries.module.NetworkModule
import dev.datlag.burningseries.SharedRes
import dev.datlag.burningseries.other.StateSaver
import dev.datlag.burningseries.ui.navigation.NavHostComponent
import dev.datlag.burningseries.window.disposableSingleWindowApplication
import dev.datlag.sekret.NativeLoader
Expand All @@ -46,7 +47,7 @@ private fun runWindow() {
AppIO.applyTitle(appTitle)
Napier.base(DebugAntilog())

NativeLoader.loadLibrary("sekret", systemProperty("compose.application.resources.dir")?.let { File(it) })
StateSaver.sekretLibraryLoaded = NativeLoader.loadLibrary("sekret", systemProperty("compose.application.resources.dir")?.let { File(it) })

val windowState = WindowState()
val lifecycle = LifecycleRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import dev.datlag.burningseries.network.JsonBase
import dev.datlag.burningseries.network.state.EpisodeStateMachine
import dev.datlag.burningseries.network.state.HomeStateMachine
import dev.datlag.burningseries.network.state.SearchStateMachine
import dev.datlag.burningseries.other.StateSaver
import io.ktor.client.*
import io.realm.kotlin.mongodb.App
import io.realm.kotlin.mongodb.AppConfiguration
import io.realm.kotlin.mongodb.Credentials
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import org.kodein.di.DI
import org.kodein.di.bindEagerSingleton
import org.kodein.di.bindSingleton
import org.kodein.di.instance
import org.kodein.di.*

object NetworkModule {

Expand Down Expand Up @@ -50,11 +48,13 @@ object NetworkModule {
bindSingleton {
SearchStateMachine(instance())
}
bindEagerSingleton {
App.create(Sekret().mongoApplication(getPackageName())!!)
if (StateSaver.sekretLibraryLoaded) {
bindEagerSingleton {
App.create(Sekret().mongoApplication(getPackageName())!!)
}
}
bindEagerSingleton {
EpisodeStateMachine(instance(), instance())
EpisodeStateMachine(instance(), instanceOrNull())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ data object StateSaver {

var seriesListIndex: Int = 0
var seriesListOffset: Int = 0

var sekretLibraryLoaded: Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.mongodb.kbson.BsonDocument
@OptIn(ExperimentalCoroutinesApi::class)
class EpisodeStateMachine(
private val jsonBase: JsonBase,
private val app: App
private val app: App?
) : FlowReduxStateMachine<EpisodeState, EpisodeAction>(initialState = EpisodeState.Waiting) {

private var user: User? = null
Expand All @@ -31,7 +31,7 @@ class EpisodeStateMachine(
onEnterEffect {
if (user == null) {
try {
user = app.login(Credentials.anonymous())
user = app?.login(Credentials.anonymous())
} catch (ignored: Throwable) { }
}
}
Expand Down

0 comments on commit 53a79e2

Please sign in to comment.