Merge pull request #16 from archem-team/issue/platform-issue-when-restart-app
Initialize platform on app start and enhance platform handling
This commit is contained in:
commit
b89b1e9415
|
|
@ -75,9 +75,12 @@ import androidx.navigation.compose.rememberNavController
|
|||
import chat.revolt.BuildConfig
|
||||
import chat.revolt.R
|
||||
import chat.revolt.RevoltApplication
|
||||
import chat.revolt.api.ApplicationPlatform
|
||||
import chat.revolt.api.HitRateLimitException
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.RevoltAPI.setPlatform
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.UrlsStorageKeys
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.routes.microservices.geo.queryGeo
|
||||
import chat.revolt.api.routes.microservices.health.healthCheck
|
||||
|
|
@ -192,6 +195,23 @@ class MainActivityViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default platform on application creation.
|
||||
* It retrieves the platform from key-value storage and sets it in the RevoltAPI.
|
||||
* If the platform is not found or invalid, it logs the user out.
|
||||
*/
|
||||
fun setDefaultPlatformOnCreate() {
|
||||
viewModelScope.launch {
|
||||
ApplicationPlatform.fromName(
|
||||
name = kvStorage.get(UrlsStorageKeys.PLATFORM) ?: "---"
|
||||
)?.let { platform ->
|
||||
setPlatform(platform)
|
||||
} ?: run {
|
||||
logOut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun updateGeoState() {
|
||||
try {
|
||||
Log.d("MainActivity", "Querying geo state")
|
||||
|
|
@ -350,6 +370,9 @@ class MainActivity : AppCompatActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Set the default platform for the Platform API.
|
||||
viewModel.setDefaultPlatformOnCreate()
|
||||
|
||||
SentryAndroid.init(this) { options ->
|
||||
options.dsn = BuildConfig.SENTRY_DSN
|
||||
options.release = BuildConfig.VERSION_NAME
|
||||
|
|
|
|||
|
|
@ -59,7 +59,14 @@ import chat.revolt.api.schemas.Channel as ChannelSchema
|
|||
*/
|
||||
enum class ApplicationPlatform(val baseUrl: String) {
|
||||
REVOLT("https://api.revolt.chat"),
|
||||
PEP("https://peptide.chat/api")
|
||||
PEP("https://peptide.chat/api");
|
||||
|
||||
companion object {
|
||||
fun fromName(name: String): ApplicationPlatform? {
|
||||
return ApplicationPlatform.entries.find { it.name == name }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue