From ad81bbdcf0b09dc41eb2c7ff66d75031cbacd3c5 Mon Sep 17 00:00:00 2001 From: MohitMali Date: Tue, 15 Aug 2023 15:14:03 +0530 Subject: [PATCH] Fixed server crashing issue when we open it on web browser --- .../org/kiwix/kiwixmobile/webserver/KiwixServer.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt index 4f05c7389..b198a089c 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt @@ -28,7 +28,13 @@ import javax.inject.Inject private const val TAG = "KiwixServer" -class KiwixServer @Inject constructor(private val jniKiwixServer: Server) { +// jniKiwixServer is a server running on a existing library. +// We must keep the library alive (keep a reference to it) to not delete the library the server +// is working on. +class KiwixServer @Inject constructor( + private val library: Library, + private val jniKiwixServer: Server +) { class Factory @Inject constructor() { fun createKiwixServer(selectedBooksPath: ArrayList): KiwixServer { @@ -43,7 +49,7 @@ class KiwixServer @Inject constructor(private val jniKiwixServer: Server) { Log.v(TAG, "Couldn't add book with path:{ $path }") } } - return KiwixServer(Server(kiwixLibrary)) + return KiwixServer(kiwixLibrary, Server(kiwixLibrary)) } }