Skip to content

Commit

Permalink
fix: rearrange some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed May 22, 2024
1 parent 143eed8 commit 4ccf6fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 41 deletions.
19 changes: 11 additions & 8 deletions app/src/main/java/ani/dantotsu/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import logcat.AndroidLogcatLogger
import logcat.LogPriority
import logcat.LogcatLogger
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.addSingletonFactory
import uy.kohesive.injekt.api.get
import java.lang.IllegalStateException


@SuppressLint("StaticFieldLeak")
Expand All @@ -64,13 +64,19 @@ class App : MultiDexApplication() {
@OptIn(DelicateCoroutinesApi::class)
override fun onCreate() {
super.onCreate()

PrefManager.init(this)

val crashlytics =
ani.dantotsu.connections.crashlytics.CrashlyticsFactory.createCrashlytics()
Injekt.addSingletonFactory<CrashlyticsInterface> { crashlytics }
crashlytics.initialize(this)
Logger.init(this)
Thread.setDefaultUncaughtExceptionHandler(FinalExceptionHandler())
Logger.log(Log.WARN, "App: Logging started")

Injekt.importModule(AppModule(this))
Injekt.importModule(PreferenceModule(this))

val crashlytics = Injekt.get<CrashlyticsInterface>()
crashlytics.initialize(this)

val useMaterialYou: Boolean = PrefManager.getVal(PrefName.UseMaterialYou)
if (useMaterialYou) {
Expand All @@ -92,10 +98,6 @@ class App : MultiDexApplication() {
}
crashlytics.setCustomKey("device Info", SettingsActivity.getDeviceInfo())

Logger.init(this)
Thread.setDefaultUncaughtExceptionHandler(FinalExceptionHandler())
Logger.log(Log.WARN, "App: Logging started")

initializeNetwork()

setupNotificationChannels()
Expand Down Expand Up @@ -154,6 +156,7 @@ class App : MultiDexApplication() {
override fun onActivityCreated(p0: Activity, p1: Bundle?) {
lastActivity = p0.javaClass.simpleName
}

override fun onActivityStarted(p0: Activity) {
currentActivity = p0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ class AppModule(val app: Application) : InjektModule {

addSingletonFactory { StandaloneDatabaseProvider(app) }

addSingletonFactory<CrashlyticsInterface> {
ani.dantotsu.connections.crashlytics.CrashlyticsFactory.createCrashlytics()
}

addSingletonFactory { MangaCache() }

ContextCompat.getMainExecutor(app).execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.content.pm.PackageInfoCompat
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.media.MediaType
import ani.dantotsu.parsers.NovelInterface
import ani.dantotsu.parsers.novel.NovelExtension
Expand All @@ -26,6 +27,8 @@ import eu.kanade.tachiyomi.util.lang.Hash
import eu.kanade.tachiyomi.util.system.getApplicationIcon
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.util.Locale

Expand Down Expand Up @@ -255,22 +258,6 @@ internal object ExtensionLoader {

val signatureHash = getSignatureHash(pkgInfo)

if (signatureHash == null) {
Logger.log("Package $pkgName isn't signed")
return AnimeLoadResult.Error
} else if (signatureHash !in trustedSignaturesAnime) {
val extension = AnimeExtension.Untrusted(
extName,
pkgName,
versionName,
versionCode,
libVersion,
signatureHash
)
Logger.log("Extension $pkgName isn't trusted")
return AnimeLoadResult.Untrusted(extension)
}

val isNsfw = appInfo.metaData.getInt("$ANIME_PACKAGE$XX_METADATA_NSFW") == 1
if (!loadNsfwSource && isNsfw) {
Logger.log("NSFW extension $pkgName not allowed")
Expand All @@ -281,7 +268,13 @@ internal object ExtensionLoader {
val hasChangelog =
appInfo.metaData.getInt("$ANIME_PACKAGE$XX_METADATA_HAS_CHANGELOG", 0) == 1

val classLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader)
val classLoader = try{
PathClassLoader(appInfo.sourceDir, null, context.classLoader)
} catch (e: Throwable) {
Logger.log("Extension load error: $extName")
Injekt.get<CrashlyticsInterface>().logException(e)
return AnimeLoadResult.Error
}

val sources = appInfo.metaData.getString("$ANIME_PACKAGE$XX_METADATA_SOURCE_CLASS")!!
.split(";")
Expand Down Expand Up @@ -371,17 +364,6 @@ internal object ExtensionLoader {

val signatureHash = getSignatureHash(pkgInfo)

/* temporarily disabling signature check TODO: remove?
if (signatureHash == null) {
Logger.log("Package $pkgName isn't signed")
return MangaLoadResult.Error
} else if (signatureHash !in trustedSignatures) {
val extension = MangaExtension.Untrusted(extName, pkgName, versionName, versionCode, libVersion, signatureHash)
Logger.log("Extension $pkgName isn't trusted")
return MangaLoadResult.Untrusted(extension)
}
*/

val isNsfw = appInfo.metaData.getInt("$MANGA_PACKAGE$XX_METADATA_NSFW") == 1
if (!loadNsfwSource && isNsfw) {
Logger.log("NSFW extension $pkgName not allowed")
Expand All @@ -392,7 +374,13 @@ internal object ExtensionLoader {
val hasChangelog =
appInfo.metaData.getInt("$MANGA_PACKAGE$XX_METADATA_HAS_CHANGELOG", 0) == 1

val classLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader)
val classLoader = try{
PathClassLoader(appInfo.sourceDir, null, context.classLoader)
} catch (e: Throwable) {
Logger.log("Extension load error: $extName")
Injekt.get<CrashlyticsInterface>().logException(e)
return MangaLoadResult.Error
}

val sources = appInfo.metaData.getString("$MANGA_PACKAGE$XX_METADATA_SOURCE_CLASS")!!
.split(";")
Expand Down

0 comments on commit 4ccf6fa

Please sign in to comment.