File tree Expand file tree Collapse file tree
src/main/kotlin/app/morphe Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import app.morphe.cli.command.model.toPatchBundle
2020import app.morphe.cli.command.model.toSerializablePatch
2121import app.morphe.cli.command.model.withUpdatedBundle
2222import app.morphe.engine.ApkLibraryStripper
23+ import app.morphe.engine.UpdateChecker
2324import app.morphe.patcher.apk.ApkUtils
2425import app.morphe.patcher.apk.ApkUtils.applyTo
2526import app.morphe.library.installation.installer.*
@@ -318,6 +319,9 @@ internal object PatchCommand : Callable<Int> {
318319 private var updateOptions: Boolean = false
319320
320321 override fun call (): Int {
322+ // Check for any newer version
323+ UpdateChecker .check()?.let { logger.info(it) }
324+
321325 // region Setup
322326
323327 val outputFilePath =
Original file line number Diff line number Diff line change 1+ package app.morphe.engine
2+
3+ import java.net.HttpURLConnection
4+ import java.net.URL
5+ import java.util.Properties
6+
7+
8+ object UpdateChecker {
9+ fun check (): String? {
10+ try {
11+ // Try to get the latest version. (TTL IS SET TO 3000)
12+ val currentVersion = javaClass.getResourceAsStream(" /app/morphe/cli/version.properties" )
13+ ?.use { stream ->
14+ Properties ().apply { load(stream) }.getProperty(" version" )
15+ }
16+ ? : return null
17+
18+ val connection = URL (" https://api.github.com/repos/MorpheApp/morphe-cli/releases/latest" )
19+ .openConnection() as HttpURLConnection
20+
21+ connection.connectTimeout = 3000
22+ connection.readTimeout = 3000
23+ connection.setRequestProperty(" Accept" , " application/vnd.github.v3+json" )
24+
25+ //
26+ val response = connection.getInputStream().bufferedReader().use { it.readText() }
27+
28+ val latestVersion = Regex (""" "tag_name"\s*:\s*"v?([^"]+)"""" ).find(response)
29+ ?.groupValues?.get(1 ) ? : return null
30+
31+ if (latestVersion != currentVersion) {
32+ return " Update available: v$latestVersion (current: v$currentVersion ). Download from https://github.com/MorpheApp/morphe-cli/releases/latest"
33+ }
34+ return null
35+
36+ }catch (e: Exception ) {
37+ // In case we fail anything, we silently return.
38+ return null
39+ }
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments