diff --git a/app/src/main/java/io/nekohasekai/sfa/bg/UpdateProfileWork.kt b/app/src/main/java/io/nekohasekai/sfa/bg/UpdateProfileWork.kt index 2e833b5..440cec6 100644 --- a/app/src/main/java/io/nekohasekai/sfa/bg/UpdateProfileWork.kt +++ b/app/src/main/java/io/nekohasekai/sfa/bg/UpdateProfileWork.kt @@ -74,9 +74,10 @@ class UpdateProfileWork { continue } try { - val content = HTTPClient().use { it.getString(profile.typed.remoteURL) } + val (content, newURL) = HTTPClient().use { it.getConfigWithUpdatedURL(profile.typed.remoteURL) } Libbox.checkConfig(content) File(profile.typed.path).writeText(content) + profile.typed.remoteURL = newURL profile.typed.lastUpdated = Date() ProfileManager.update(profile) } catch (e: Exception) { @@ -94,4 +95,4 @@ class UpdateProfileWork { } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileActivity.kt b/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileActivity.kt index 9935a1d..9f582e0 100644 --- a/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileActivity.kt +++ b/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileActivity.kt @@ -167,9 +167,10 @@ class EditProfileActivity : AbstractActivity() { binding.progressView.isVisible = true lifecycleScope.launch(Dispatchers.IO) { try { - val content = HTTPClient().use { it.getString(profile.typed.remoteURL) } + val (content, newURL) = HTTPClient().use { it.getConfigWithUpdatedURL(profile.typed.remoteURL) } Libbox.checkConfig(content) File(profile.typed.path).writeText(content) + profile.typed.remoteURL = newURL profile.typed.lastUpdated = Date() ProfileManager.update(profile) } catch (e: Exception) { @@ -185,4 +186,4 @@ class EditProfileActivity : AbstractActivity() { } } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/profile/NewProfileActivity.kt b/app/src/main/java/io/nekohasekai/sfa/ui/profile/NewProfileActivity.kt index 847924e..cf37949 100644 --- a/app/src/main/java/io/nekohasekai/sfa/ui/profile/NewProfileActivity.kt +++ b/app/src/main/java/io/nekohasekai/sfa/ui/profile/NewProfileActivity.kt @@ -168,10 +168,10 @@ class NewProfileActivity : AbstractActivity() { TypedProfile.Type.Remote.name -> { typedProfile.type = TypedProfile.Type.Remote val remoteURL = binding.remoteURL.text - val content = HTTPClient().use { it.getString(remoteURL) } + val (content, newURL) = HTTPClient().use { it.getConfigWithUpdatedURL(remoteURL) } Libbox.checkConfig(content) configFile.writeText(content) - typedProfile.remoteURL = remoteURL + typedProfile.remoteURL = newURL typedProfile.lastUpdated = Date() typedProfile.autoUpdate = EnabledType.valueOf(binding.autoUpdate.text).boolValue binding.autoUpdateInterval.text.toIntOrNull()?.also { @@ -206,4 +206,4 @@ class NewProfileActivity : AbstractActivity() { } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/nekohasekai/sfa/utils/HTTPClient.kt b/app/src/main/java/io/nekohasekai/sfa/utils/HTTPClient.kt index 7223472..aac99cd 100644 --- a/app/src/main/java/io/nekohasekai/sfa/utils/HTTPClient.kt +++ b/app/src/main/java/io/nekohasekai/sfa/utils/HTTPClient.kt @@ -10,7 +10,7 @@ class HTTPClient : Closeable { val userAgent by lazy { var userAgent = "SFA/" userAgent += BuildConfig.VERSION_NAME - userAgent += " (" + userAgent += " (Build " userAgent += BuildConfig.VERSION_CODE userAgent += "; sing-box " userAgent += Libbox.version() @@ -25,12 +25,20 @@ class HTTPClient : Closeable { client.modernTLS() } - fun getString(url: String): String { + private fun _getResponse(url: String): HTTPResponse { val request = client.newRequest() request.setUserAgent(userAgent) request.setURL(url) - val response = request.execute() - return response.contentString + return request.execute() + } + + fun getString(url: String): String { + return _getResponse(url).contentString + } + + fun getConfigWithUpdatedURL(url: String): Pair { + val response = _getResponse(url); + return Pair(response.contentString, response.finalURL) } override fun close() { @@ -38,4 +46,4 @@ class HTTPClient : Closeable { } -} \ No newline at end of file +}