diff --git a/.gitignore b/.gitignore index 64c9069c..6e973342 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ crowdin.yml # Kotlin 2.0 .kotlin/ .idea +/build_and_sign_apk.sh +/simpmusic.jks diff --git a/app/src/main/java/com/maxrave/simpmusic/data/dataStore/DataStoreManager.kt b/app/src/main/java/com/maxrave/simpmusic/data/dataStore/DataStoreManager.kt index d96908a2..ad9241f5 100644 --- a/app/src/main/java/com/maxrave/simpmusic/data/dataStore/DataStoreManager.kt +++ b/app/src/main/java/com/maxrave/simpmusic/data/dataStore/DataStoreManager.kt @@ -618,20 +618,25 @@ class DataStoreManager( } } - fun getProxy(): Proxy? = + fun getJVMProxy(): Proxy? = runBlocking { - if (usingProxy.first() == TRUE) { - val proxyType = proxyType.first() - val proxyHost = proxyHost.first() - val proxyPort = proxyPort.first() - return@runBlocking Proxy( - when (proxyType) { - ProxyType.PROXY_TYPE_HTTP -> Proxy.Type.HTTP - ProxyType.PROXY_TYPE_SOCKS -> Proxy.Type.SOCKS - }, - java.net.InetSocketAddress(proxyHost, proxyPort) - ) - } else { + try { + if (usingProxy.first() == TRUE) { + val proxyType = proxyType.first() + val proxyHost = proxyHost.first() + val proxyPort = proxyPort.first() + return@runBlocking Proxy( + when (proxyType) { + ProxyType.PROXY_TYPE_HTTP -> Proxy.Type.HTTP + ProxyType.PROXY_TYPE_SOCKS -> Proxy.Type.SOCKS + }, + java.net.InetSocketAddress(proxyHost, proxyPort) + ) + } else { + return@runBlocking null + } + } catch (e: Exception) { + e.printStackTrace() return@runBlocking null } } diff --git a/app/src/main/java/com/maxrave/simpmusic/di/MediaServiceModule.kt b/app/src/main/java/com/maxrave/simpmusic/di/MediaServiceModule.kt index 006bd328..c41c9a3a 100644 --- a/app/src/main/java/com/maxrave/simpmusic/di/MediaServiceModule.kt +++ b/app/src/main/java/com/maxrave/simpmusic/di/MediaServiceModule.kt @@ -276,7 +276,7 @@ private fun provideMediaSourceFactory( downloadCache, playerCache, context, - dataStoreManager.getProxy() + dataStoreManager.getJVMProxy() ), downloadCache, playerCache, diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt index fba20078..a714dbd5 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt @@ -85,6 +85,7 @@ import coil3.compose.AsyncImage import coil3.request.ImageRequest import coil3.request.crossfade import com.maxrave.kotlinytmusicscraper.extension.isTwoLetterCode +import com.maxrave.kotlinytmusicscraper.extension.isValidProxyHost import com.maxrave.simpmusic.R import com.maxrave.simpmusic.common.LIMIT_CACHE_SIZE import com.maxrave.simpmusic.common.QUALITY @@ -486,7 +487,7 @@ fun SettingScreen( label = context.getString(R.string.proxy_host), value = proxyHost, verifyCodeBlock = { - (it.toHttpUrlOrNull() != null) to context.getString(R.string.invalid_host) + isValidProxyHost(it) to context.getString(R.string.invalid_host) }, ), confirm = diff --git a/kotlinYtmusicScraper/src/main/java/com/maxrave/kotlinytmusicscraper/extension/StringExt.kt b/kotlinYtmusicScraper/src/main/java/com/maxrave/kotlinytmusicscraper/extension/StringExt.kt index b883d570..aae4b2f2 100644 --- a/kotlinYtmusicScraper/src/main/java/com/maxrave/kotlinytmusicscraper/extension/StringExt.kt +++ b/kotlinYtmusicScraper/src/main/java/com/maxrave/kotlinytmusicscraper/extension/StringExt.kt @@ -21,4 +21,31 @@ fun String.verifyYouTubePlaylistId(): String = if (startsWith("VL")) this else " fun String.isTwoLetterCode(): Boolean { val regex = "^[A-Za-z]{2}$".toRegex() return regex.matches(this) +} + +fun isValidProxyHost(host: String): Boolean { + // Regular expression to validate proxy host (without port) + val proxyHostRegex = Regex( + pattern = "^(?!-)[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(?