From a20cdda5b7c59861f26c7293c571324d3b255d05 Mon Sep 17 00:00:00 2001 From: Prateek <129204458+prateek-who@users.noreply.github.com> Date: Sat, 21 Mar 2026 13:03:28 +0530 Subject: [PATCH 1/4] Show better update messaging --- .../kotlin/app/morphe/engine/UpdateChecker.kt | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/app/morphe/engine/UpdateChecker.kt b/src/main/kotlin/app/morphe/engine/UpdateChecker.kt index f7748ca..c2c91c9 100644 --- a/src/main/kotlin/app/morphe/engine/UpdateChecker.kt +++ b/src/main/kotlin/app/morphe/engine/UpdateChecker.kt @@ -15,21 +15,32 @@ object UpdateChecker { } ?: return null - val connection = URL("https://api.github.com/repos/MorpheApp/morphe-cli/releases/latest") - .openConnection() as HttpURLConnection + // Check if the user is using dev or stable release here. Then we use this to check the latest dev or stable release. + val isDev = currentVersion.contains("dev") + + val url = if (isDev) { + "https://raw.githubusercontent.com/MorpheApp/morphe-cli/refs/heads/dev/gradle.properties" + } else { + "https://raw.githubusercontent.com/MorpheApp/morphe-cli/refs/heads/main/gradle.properties" + } + + val connection = URL(url).openConnection() as HttpURLConnection connection.connectTimeout = 3000 connection.readTimeout = 3000 - connection.setRequestProperty("Accept", "application/vnd.github.v3+json") - // val response = connection.getInputStream().bufferedReader().use { it.readText() } - val latestVersion = Regex(""""tag_name"\s*:\s*"v?([^"]+)"""").find(response) - ?.groupValues?.get(1) ?: return null + val latestVersion = Properties().apply { + load(response.byteInputStream()) + }.getProperty("version") ?: return null if (latestVersion != currentVersion) { - return "Update available: v$latestVersion (current: v$currentVersion). Download from https://github.com/MorpheApp/morphe-cli/releases/latest" + return if (isDev){ + "Update available: v$latestVersion (current: v$currentVersion). Download from https://github.com/MorpheApp/morphe-cli/releases/" + } else { + "Update available: v$latestVersion (current: v$currentVersion). Download from https://github.com/MorpheApp/morphe-cli/releases/latest" + } } return null From 50470859b836915f201bdc3228ac4c944efb1d0f Mon Sep 17 00:00:00 2001 From: Prateek <129204458+prateek-who@users.noreply.github.com> Date: Sat, 21 Mar 2026 13:29:43 +0530 Subject: [PATCH 2/4] Messages fixed for edge case --- src/main/kotlin/app/morphe/engine/UpdateChecker.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/app/morphe/engine/UpdateChecker.kt b/src/main/kotlin/app/morphe/engine/UpdateChecker.kt index c2c91c9..3134c5f 100644 --- a/src/main/kotlin/app/morphe/engine/UpdateChecker.kt +++ b/src/main/kotlin/app/morphe/engine/UpdateChecker.kt @@ -36,10 +36,17 @@ object UpdateChecker { }.getProperty("version") ?: return null if (latestVersion != currentVersion) { + val currentTag = if (isDev) "[Dev]" else "[Stable]" + val latestTag = if (latestVersion.contains("dev")) "[Dev]" else "[Stable]" + val trackChangesMessage = if (isDev && !latestVersion.contains("dev")){ + "\nWarning: This is a stable release. Updating will stop dev update notifications. " + + "To keep receiving dev updates, skip this and wait for the next dev release." + } else "" + return if (isDev){ - "Update available: v$latestVersion (current: v$currentVersion). Download from https://github.com/MorpheApp/morphe-cli/releases/" + "Update available: v$latestVersion $latestTag (current: v$currentVersion $currentTag).$trackChangesMessage\nDownload from https://github.com/MorpheApp/morphe-cli/releases/" } else { - "Update available: v$latestVersion (current: v$currentVersion). Download from https://github.com/MorpheApp/morphe-cli/releases/latest" + "Update available: v$latestVersion $latestTag (current: v$currentVersion $currentTag).$trackChangesMessage\nDownload from https://github.com/MorpheApp/morphe-cli/releases/latest" } } return null From f71c4af7c7e4e2e18bec286f2fe515506c4f01fc Mon Sep 17 00:00:00 2001 From: Prateek <129204458+prateek-who@users.noreply.github.com> Date: Sat, 21 Mar 2026 18:18:38 +0530 Subject: [PATCH 3/4] added warning comment --- src/main/kotlin/app/morphe/engine/UpdateChecker.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/app/morphe/engine/UpdateChecker.kt b/src/main/kotlin/app/morphe/engine/UpdateChecker.kt index 3134c5f..45a2ef4 100644 --- a/src/main/kotlin/app/morphe/engine/UpdateChecker.kt +++ b/src/main/kotlin/app/morphe/engine/UpdateChecker.kt @@ -38,6 +38,8 @@ object UpdateChecker { if (latestVersion != currentVersion) { val currentTag = if (isDev) "[Dev]" else "[Stable]" val latestTag = if (latestVersion.contains("dev")) "[Dev]" else "[Stable]" + + // Warning message for when the user is to about to move from dev -> stable edge case. val trackChangesMessage = if (isDev && !latestVersion.contains("dev")){ "\nWarning: This is a stable release. Updating will stop dev update notifications. " + "To keep receiving dev updates, skip this and wait for the next dev release." From 6680513d7468ef19f047757614e02b0a9d6b0270 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 21 Mar 2026 16:56:08 +0100 Subject: [PATCH 4/4] refactor --- .../app/morphe/cli/command/PatchCommand.kt | 2 +- .../kotlin/app/morphe/engine/UpdateChecker.kt | 35 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/app/morphe/cli/command/PatchCommand.kt b/src/main/kotlin/app/morphe/cli/command/PatchCommand.kt index 18dcd96..55a4e82 100644 --- a/src/main/kotlin/app/morphe/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/morphe/cli/command/PatchCommand.kt @@ -320,7 +320,7 @@ internal object PatchCommand : Callable { override fun call(): Int { // Check for any newer version - UpdateChecker.check()?.let { logger.info(it) } + UpdateChecker.check(logger)?.let { logger.info(it) } // region Setup diff --git a/src/main/kotlin/app/morphe/engine/UpdateChecker.kt b/src/main/kotlin/app/morphe/engine/UpdateChecker.kt index 45a2ef4..0cfe170 100644 --- a/src/main/kotlin/app/morphe/engine/UpdateChecker.kt +++ b/src/main/kotlin/app/morphe/engine/UpdateChecker.kt @@ -3,29 +3,29 @@ package app.morphe.engine import java.net.HttpURLConnection import java.net.URL import java.util.Properties - +import java.util.logging.Logger object UpdateChecker { - fun check(): String? { + fun check(logger: Logger): String? { try { - // Try to get the latest version. (TTL IS SET TO 3000) + // Current version of this CLI. val currentVersion = javaClass.getResourceAsStream("/app/morphe/cli/version.properties") ?.use { stream -> Properties().apply { load(stream) }.getProperty("version") - } - ?: return null + } ?: return null - // Check if the user is using dev or stable release here. Then we use this to check the latest dev or stable release. + // Check if the user is using dev or stable release. val isDev = currentVersion.contains("dev") val url = if (isDev) { + // If on dev and a new stable release is available, then this + // ref still is correct because after a stable release dev branch is same as main. "https://raw.githubusercontent.com/MorpheApp/morphe-cli/refs/heads/dev/gradle.properties" } else { "https://raw.githubusercontent.com/MorpheApp/morphe-cli/refs/heads/main/gradle.properties" } val connection = URL(url).openConnection() as HttpURLConnection - connection.connectTimeout = 3000 connection.readTimeout = 3000 @@ -36,25 +36,26 @@ object UpdateChecker { }.getProperty("version") ?: return null if (latestVersion != currentVersion) { - val currentTag = if (isDev) "[Dev]" else "[Stable]" - val latestTag = if (latestVersion.contains("dev")) "[Dev]" else "[Stable]" - // Warning message for when the user is to about to move from dev -> stable edge case. val trackChangesMessage = if (isDev && !latestVersion.contains("dev")){ - "\nWarning: This is a stable release. Updating will stop dev update notifications. " + - "To keep receiving dev updates, skip this and wait for the next dev release." + "\nNotice: The latest CLI is a stable release. Updating to that will stop dev " + + "update notifications. To keep receiving dev updates, skip stable update " + + "and wait for the next dev release." } else "" - return if (isDev){ - "Update available: v$latestVersion $latestTag (current: v$currentVersion $currentTag).$trackChangesMessage\nDownload from https://github.com/MorpheApp/morphe-cli/releases/" + val downloadLink = if (isDev) { + "https://github.com/MorpheApp/morphe-cli/releases/" } else { - "Update available: v$latestVersion $latestTag (current: v$currentVersion $currentTag).$trackChangesMessage\nDownload from https://github.com/MorpheApp/morphe-cli/releases/latest" + "https://github.com/MorpheApp/morphe-cli/releases/latest" } + + return "Update available: v$latestVersion (current: v$currentVersion)" + + "$trackChangesMessage\nDownload from $downloadLink" } return null - }catch (e: Exception) { - // In case we fail anything, we silently return. + } catch (ex: Exception) { + logger.fine("Could not check for CLI update: $ex") return null } }