diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt index c4a7cc2e6..ce2ce61ee 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt @@ -99,12 +99,24 @@ class HomeRootSection : Routes.Route() { } } + private fun openExternalLink(link: String) { + kotlin.runCatching { + context.activity?.startActivity(Intent(Intent.ACTION_VIEW).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK + data = Uri.parse(link) + }) + }.onFailure { + context.log.error("Failed to open external link", it) + context.shortToast("Failed to open external link. Check logs for more details.") + } + } + @Composable fun ExternalLinkIcon( modifier: Modifier = Modifier, size: Dp = 32.dp, imageVector: ImageVector, - dataArray: IntArray + link: String ) { Icon( imageVector = imageVector, @@ -113,14 +125,7 @@ class HomeRootSection : Routes.Route() { modifier = Modifier .size(size) .then(modifier) - .clickable { - context.activity?.startActivity(Intent(Intent.ACTION_VIEW).apply { - data = Uri.parse( - dataArray.reversed().map { (-it xor BuildConfig.APPLICATION_ID.hashCode()).toChar() }.joinToString("") - ) - flags = Intent.FLAG_ACTIVITY_NEW_TASK - }) - } + .clickable { openExternalLink(link) } ) } @@ -182,41 +187,19 @@ class HomeRootSection : Routes.Route() { ) { ExternalLinkIcon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_telegram), - // https://t.me/snapenhance - dataArray = intArrayOf( - 0xe4f8b47, 0xe4f8b41, 0xe4f8b4e, 0xe4f8b43, 0xe4f8b4c, 0xe4f8b4e, 0xe4f8b47, - 0xe4f8b54, 0xe4f8b43, 0xe4f8b4e, 0xe4f8b51, 0xe4f8b0d, 0xe4f8b47, 0xe4f8b4f, - 0xe4f8b0e, 0xe4f8b58, 0xe4f8b0d, 0xe4f8b0d, 0xe4f8b1a, 0xe4f8b51, 0xe4f8b54, - 0xe4f8b58, 0xe4f8b58, 0xe4f8b4c - ) + link = "https://t.me/snapenhance" ) ExternalLinkIcon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_github), - // https://github.com/rhunk/SnapEnhance - dataArray = intArrayOf( - 0xe4f8b47, 0xe4f8b41, 0xe4f8b4e, 0xe4f8b43, 0xe4f8b4c, 0xe4f8b4e, 0xe4f8b67, - 0xe4f8b54, 0xe4f8b43, 0xe4f8b4e, 0xe4f8b71, 0xe4f8b0d, 0xe4f8b49, 0xe4f8b4e, - 0xe4f8b57, 0xe4f8b4c, 0xe4f8b52, 0xe4f8b0d, 0xe4f8b4f, 0xe4f8b4d, 0xe4f8b41, - 0xe4f8b0e, 0xe4f8b42, 0xe4f8b57, 0xe4f8b4c, 0xe4f8b58, 0xe4f8b4b, 0xe4f8b45, - 0xe4f8b0d, 0xe4f8b0d, 0xe4f8b1a, 0xe4f8b51, 0xe4f8b54, 0xe4f8b58, 0xe4f8b58, - 0xe4f8b4c - ) + link = "https://github.com/rhunk/SnapEnhance" ) ExternalLinkIcon( size = 36.dp, modifier = Modifier.offset(y = (-2).dp), imageVector = Icons.AutoMirrored.Default.Help, - // https://github.com/rhunk/SnapEnhance/wiki - dataArray = intArrayOf( - 0xe4f8b4b, 0xe4f8b49, 0xe4f8b4b, 0xe4f8b55, 0xe4f8b0d, 0xe4f8b47, 0xe4f8b41, - 0xe4f8b4e, 0xe4f8b43, 0xe4f8b4c, 0xe4f8b4e, 0xe4f8b67, 0xe4f8b54, 0xe4f8b43, - 0xe4f8b4e, 0xe4f8b71, 0xe4f8b0d, 0xe4f8b49, 0xe4f8b4e, 0xe4f8b57, 0xe4f8b4c, - 0xe4f8b52, 0xe4f8b0d, 0xe4f8b4f, 0xe4f8b4d, 0xe4f8b41, 0xe4f8b0e, 0xe4f8b42, - 0xe4f8b57, 0xe4f8b4c, 0xe4f8b58, 0xe4f8b4b, 0xe4f8b45, 0xe4f8b0d, 0xe4f8b0d, - 0xe4f8b1a, 0xe4f8b51, 0xe4f8b54, 0xe4f8b58, 0xe4f8b58, 0xe4f8b4c - ) + link = "https://github.com/rhunk/SnapEnhance/wiki" ) } @@ -250,9 +233,7 @@ class HomeRootSection : Routes.Route() { ) } Button(onClick = { - context.activity?.startActivity(Intent(Intent.ACTION_VIEW).apply { - data = Uri.parse(latestUpdate?.releaseUrl) - }) + latestUpdate?.releaseUrl?.let { openExternalLink(it) } }, modifier = Modifier.height(40.dp)) { Text(text = translation["update_button"]) } @@ -306,15 +287,9 @@ class HomeRootSection : Routes.Route() { onClick = { offset -> buildSummary.getStringAnnotations( tag = "git_hash", start = offset, end = offset - ) - .firstOrNull()?.let { - context.activity?.startActivity( - Intent(Intent.ACTION_VIEW).apply { - data = Uri.parse( - "https://github.com/rhunk/SnapEnhance/commit/${it.item}" - ) - }) - } + ).firstOrNull()?.let { + openExternalLink("https://github.com/rhunk/SnapEnhance/commit/${it.item}") + } } ) Text(