Skip to content

Commit 1ed2c5e

Browse files
committed
Update Dependencies and Minor Bug Fixes
1. Bugfix: Fix App crash if not connected to internet during launch. 2. Update Dependencies.
1 parent 6f73708 commit 1ed2c5e

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId "com.github.capntrips.kernelflasher"
1313
minSdk 29
1414
targetSdk 34
15-
versionCode 10400
16-
versionName "1.4.0"
15+
versionCode 25
16+
versionName "1.4.1"
1717

1818
javaCompileOptions {
1919
annotationProcessorOptions {

app/src/main/java/com/github/capntrips/kernelflasher/AppUpdater.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import retrofit2.Response
1515
import retrofit2.Retrofit
1616
import retrofit2.converter.gson.GsonConverterFactory
1717
import retrofit2.http.GET
18+
import java.io.IOException
19+
import java.net.HttpURLConnection
20+
import java.net.URL
21+
import kotlinx.coroutines.Dispatchers
22+
import kotlinx.coroutines.withContext
1823

1924
interface GitHubApi {
2025
@GET("repos/fatalcoder524/KernelFlasher/releases/latest")
@@ -48,6 +53,18 @@ object AppUpdater {
4853
return latestParts.zip(currentParts).any { (l, c) -> l > c }
4954
}
5055

56+
suspend fun hasActiveInternetConnection(): Boolean = withContext(Dispatchers.IO) {
57+
try {
58+
val url = URL("https://connectivitycheck.gstatic.com/generate_204")
59+
val connection = url.openConnection() as HttpURLConnection
60+
connection.setRequestProperty("User-Agent", "Android")
61+
connection.connectTimeout = 1500
62+
connection.connect()
63+
return@withContext connection.responseCode == 204
64+
} catch (e: IOException) {
65+
return@withContext false
66+
}
67+
}
5168

5269
// Checks if an update is available
5370
suspend fun checkForUpdate(

app/src/main/java/com/github/capntrips/kernelflasher/MainActivity.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,13 @@ class MainActivity : ComponentActivity() {
207207
val context = LocalContext.current
208208
val dialogData = viewModel!!.updateDialogData
209209
LaunchedEffect(Unit) {
210-
AppUpdater.checkForUpdate(
211-
context.applicationContext,
212-
BuildConfig.VERSION_NAME
213-
) { title, lines, confirm ->
214-
viewModel!!.showUpdateDialog(title, lines, confirm)
210+
if(AppUpdater.hasActiveInternetConnection()) {
211+
AppUpdater.checkForUpdate(
212+
context.applicationContext,
213+
BuildConfig.VERSION_NAME
214+
) { title, lines, confirm ->
215+
viewModel!!.showUpdateDialog(title, lines, confirm)
216+
}
215217
}
216218
}
217219

gradle/libs.versions.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ material = "1.12.0"
1717
okhttp = "4.12.0"
1818

1919
android-application = "8.9.2"
20-
devtools-ksp = "2.1.20-2.0.0"
21-
work-runtime-ktx = "2.10.1"
20+
devtools-ksp = "2.1.20-2.0.1"
2221

2322
[libraries]
2423
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidx-activity-compose" }

0 commit comments

Comments
 (0)