@@ -3,38 +3,59 @@ package app.morphe.engine
33import java.net.HttpURLConnection
44import java.net.URL
55import java.util.Properties
6-
6+ import java.util.logging.Logger
77
88object UpdateChecker {
9- fun check (): String? {
9+ fun check (logger : Logger ): String? {
1010 try {
11- // Try to get the latest version. (TTL IS SET TO 3000)
11+ // Current version of this CLI.
1212 val currentVersion = javaClass.getResourceAsStream(" /app/morphe/cli/version.properties" )
1313 ?.use { stream ->
1414 Properties ().apply { load(stream) }.getProperty(" version" )
15- }
16- ? : return null
15+ } ? : return null
16+
17+ // Check if the user is using dev or stable release.
18+ val isDev = currentVersion.contains(" dev" )
1719
18- val connection = URL (" https://api.github.com/repos/MorpheApp/morphe-cli/releases/latest" )
19- .openConnection() as HttpURLConnection
20+ val url = if (isDev) {
21+ // If on dev and a new stable release is available, then this
22+ // ref still is correct because after a stable release dev branch is same as main.
23+ " https://raw.githubusercontent.com/MorpheApp/morphe-cli/refs/heads/dev/gradle.properties"
24+ } else {
25+ " https://raw.githubusercontent.com/MorpheApp/morphe-cli/refs/heads/main/gradle.properties"
26+ }
2027
28+ val connection = URL (url).openConnection() as HttpURLConnection
2129 connection.connectTimeout = 3000
2230 connection.readTimeout = 3000
23- connection.setRequestProperty(" Accept" , " application/vnd.github.v3+json" )
2431
25- //
2632 val response = connection.getInputStream().bufferedReader().use { it.readText() }
2733
28- val latestVersion = Regex (""" "tag_name"\s*:\s*"v?([^"]+)"""" ).find(response)
29- ?.groupValues?.get(1 ) ? : return null
34+ val latestVersion = Properties ().apply {
35+ load(response.byteInputStream())
36+ }.getProperty(" version" ) ? : return null
3037
3138 if (latestVersion != currentVersion) {
32- return " Update available: v$latestVersion (current: v$currentVersion ). Download from https://github.com/MorpheApp/morphe-cli/releases/latest"
39+ // Warning message for when the user is to about to move from dev -> stable edge case.
40+ val trackChangesMessage = if (isDev && ! latestVersion.contains(" dev" )){
41+ " \n Notice: The latest CLI is a stable release. Updating to that will stop dev " +
42+ " update notifications. To keep receiving dev updates, skip stable update " +
43+ " and wait for the next dev release."
44+ } else " "
45+
46+ val downloadLink = if (isDev) {
47+ " https://github.com/MorpheApp/morphe-cli/releases/"
48+ } else {
49+ " https://github.com/MorpheApp/morphe-cli/releases/latest"
50+ }
51+
52+ return " Update available: v$latestVersion (current: v$currentVersion )" +
53+ " $trackChangesMessage \n Download from $downloadLink "
3354 }
3455 return null
3556
36- }catch (e : Exception ) {
37- // In case we fail anything, we silently return.
57+ } catch (ex : Exception ) {
58+ logger.fine( " Could not check for CLI update: $ex " )
3859 return null
3960 }
4061 }
0 commit comments