Skip to content

Commit e38501d

Browse files
MohitMaliDeveloperkelson42
authored andcommitted
Fixed server crashing issue when we open it on web browser
1 parent c2a962e commit e38501d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/src/main/java/org/kiwix/kiwixmobile/webserver/KiwixServer.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ import javax.inject.Inject
2828

2929
private const val TAG = "KiwixServer"
3030

31-
class KiwixServer @Inject constructor(private val jniKiwixServer: Server) {
31+
// jniKiwixServer is a server running on a existing library.
32+
// We must keep the library alive (keep a reference to it) to not delete the library the server
33+
// is working on.
34+
class KiwixServer @Inject constructor(
35+
private val library: Library,
36+
private val jniKiwixServer: Server
37+
) {
3238

3339
class Factory @Inject constructor() {
3440
fun createKiwixServer(selectedBooksPath: ArrayList<String>): KiwixServer {
@@ -43,7 +49,7 @@ class KiwixServer @Inject constructor(private val jniKiwixServer: Server) {
4349
Log.v(TAG, "Couldn't add book with path:{ $path }")
4450
}
4551
}
46-
return KiwixServer(Server(kiwixLibrary))
52+
return KiwixServer(kiwixLibrary, Server(kiwixLibrary))
4753
}
4854
}
4955

0 commit comments

Comments
 (0)