Skip to content

Commit b59caae

Browse files
committed
feat: Implement Mac app version compatibility check and warn users about outdated Mac app versions.
1 parent c586b6f commit b59caae

5 files changed

Lines changed: 38 additions & 3 deletions

File tree

app/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ android {
4040
}
4141
buildFeatures {
4242
compose = true
43+
buildConfig = true
44+
}
45+
46+
defaultConfig {
47+
buildConfigField("String", "MIN_MAC_APP_VERSION", "\"2.6.0\"")
4348
}
4449
}
4550

app/src/main/java/com/sameerasw/airsync/presentation/ui/components/SettingsView.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ fun SettingsView(
299299
viewModel.manualSyncAppIcons(context)
300300
},
301301
modifier = Modifier.fillMaxWidth(),
302-
shape = MaterialTheme.shapes.extraSmall,
303302
enabled = uiState.isConnected && !uiState.isIconSyncLoading
304303
) {
305304
if (uiState.isIconSyncLoading) {

app/src/main/java/com/sameerasw/airsync/presentation/ui/components/cards/DeviceInfoCard.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ fun DeviceInfoCard(
2828
Text("My Android", style = MaterialTheme.typography.titleMedium)
2929
Spacer(modifier = Modifier.height(8.dp))
3030
Text("Local IP: $localIp", style = MaterialTheme.typography.bodyMedium)
31-
Text("Wake-up Ports: HTTP 8888, UDP 8889", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
3231

3332
Spacer(modifier = Modifier.height(8.dp))
3433
OutlinedTextField(

app/src/main/java/com/sameerasw/airsync/presentation/ui/components/cards/ExpandNetworkingCard.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import androidx.compose.material3.MaterialTheme
99
import androidx.compose.material3.Switch
1010
import androidx.compose.material3.Text
1111
import androidx.compose.runtime.*
12+
import androidx.compose.ui.Modifier
1213
import androidx.compose.ui.platform.LocalHapticFeedback
14+
import androidx.compose.ui.unit.dp
1315
import com.sameerasw.airsync.data.local.DataStoreManager
1416
import com.sameerasw.airsync.utils.HapticUtil
1517
import com.sameerasw.airsync.ui.theme.minCornerRadius

app/src/main/java/com/sameerasw/airsync/utils/WebSocketMessageHandler.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import kotlinx.coroutines.Dispatchers
1111
import kotlinx.coroutines.delay
1212
import kotlinx.coroutines.flow.first
1313
import kotlinx.coroutines.launch
14+
import android.widget.Toast
15+
import com.sameerasw.airsync.BuildConfig
1416
import org.json.JSONObject
1517

1618
/**
@@ -513,8 +515,17 @@ object WebSocketMessageHandler {
513515

514516
val macName = data.optString("name", "")
515517
val isPlus = data.optBoolean("isPlusSubscription", false)
518+
val macVersion = data.optString("version", "2.0.0")
516519

517-
Log.d(TAG, "Processing macInfo - name: '$macName', isPlus: $isPlus")
520+
Log.d(TAG, "Processing macInfo - name: '$macName', isPlus: $isPlus, version: '$macVersion'")
521+
522+
// Version compatibility check
523+
val minVersion = BuildConfig.MIN_MAC_APP_VERSION
524+
if (isVersionOutdated(macVersion, minVersion)) {
525+
launch(Dispatchers.Main) {
526+
Toast.makeText(context, "Mac app is outdated ($macVersion < $minVersion). Please update the mac app and reconnect.", Toast.LENGTH_LONG).show()
527+
}
528+
}
518529

519530
val savedAppPackagesJson = data.optJSONArray("savedAppPackages")
520531
val savedPackages = mutableSetOf<String>()
@@ -857,4 +868,23 @@ object WebSocketMessageHandler {
857868
Log.d(TAG, "Request to refresh ADB ports received")
858869
SyncManager.sendDeviceInfoNow(context)
859870
}
871+
872+
private fun isVersionOutdated(current: String, min: String): Boolean {
873+
return try {
874+
val currentParts = current.split(".").map { it.toInt() }
875+
val minParts = min.split(".").map { it.toInt() }
876+
877+
val maxLen = maxOf(currentParts.size, minParts.size)
878+
for (i in 0 until maxLen) {
879+
val currentPart = if (i < currentParts.size) currentParts[i] else 0
880+
val minPart = if (i < minParts.size) minParts[i] else 0
881+
882+
if (currentPart < minPart) return true
883+
if (currentPart > minPart) return false
884+
}
885+
false
886+
} catch (e: Exception) {
887+
false
888+
}
889+
}
860890
}

0 commit comments

Comments
 (0)