Small refactoring on the HTTP client
This commit is contained in:
@@ -40,7 +40,7 @@ import com.vitorpamplona.amethyst.model.ThemeType
|
|||||||
import com.vitorpamplona.amethyst.model.parseBooleanType
|
import com.vitorpamplona.amethyst.model.parseBooleanType
|
||||||
import com.vitorpamplona.amethyst.model.parseConnectivityType
|
import com.vitorpamplona.amethyst.model.parseConnectivityType
|
||||||
import com.vitorpamplona.amethyst.model.parseThemeType
|
import com.vitorpamplona.amethyst.model.parseThemeType
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.amethyst.service.Nip96MediaServers
|
import com.vitorpamplona.amethyst.service.Nip96MediaServers
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||||
@@ -570,7 +570,7 @@ object LocalPreferences {
|
|||||||
val hideNIP24WarningDialog = getBoolean(PrefKeys.HIDE_NIP_24_WARNING_DIALOG, false)
|
val hideNIP24WarningDialog = getBoolean(PrefKeys.HIDE_NIP_24_WARNING_DIALOG, false)
|
||||||
val useProxy = getBoolean(PrefKeys.USE_PROXY, false)
|
val useProxy = getBoolean(PrefKeys.USE_PROXY, false)
|
||||||
val proxyPort = getInt(PrefKeys.PROXY_PORT, 9050)
|
val proxyPort = getInt(PrefKeys.PROXY_PORT, 9050)
|
||||||
val proxy = HttpClient.initProxy(useProxy, "127.0.0.1", proxyPort)
|
val proxy = HttpClientManager.initProxy(useProxy, "127.0.0.1", proxyPort)
|
||||||
|
|
||||||
val showSensitiveContent =
|
val showSensitiveContent =
|
||||||
if (contains(PrefKeys.SHOW_SENSITIVE_CONTENT)) {
|
if (contains(PrefKeys.SHOW_SENSITIVE_CONTENT)) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import coil.decode.SvgDecoder
|
|||||||
import coil.size.Precision
|
import coil.size.Precision
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.amethyst.service.NostrAccountDataSource
|
import com.vitorpamplona.amethyst.service.NostrAccountDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrChannelDataSource
|
import com.vitorpamplona.amethyst.service.NostrChannelDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrChatroomDataSource
|
import com.vitorpamplona.amethyst.service.NostrChatroomDataSource
|
||||||
@@ -83,7 +83,7 @@ class ServiceManager {
|
|||||||
val myAccount = account
|
val myAccount = account
|
||||||
|
|
||||||
// Resets Proxy Use
|
// Resets Proxy Use
|
||||||
HttpClient.start(account?.proxy)
|
HttpClientManager.setDefaultProxy(account?.proxy)
|
||||||
LocalCache.antiSpam.active = account?.filterSpamFromStrangers ?: true
|
LocalCache.antiSpam.active = account?.filterSpamFromStrangers ?: true
|
||||||
Coil.setImageLoader {
|
Coil.setImageLoader {
|
||||||
Amethyst.instance
|
Amethyst.instance
|
||||||
@@ -96,7 +96,7 @@ class ServiceManager {
|
|||||||
}
|
}
|
||||||
add(SvgDecoder.Factory())
|
add(SvgDecoder.Factory())
|
||||||
} // .logger(DebugLogger())
|
} // .logger(DebugLogger())
|
||||||
.okHttpClient { HttpClient.getHttpClient() }
|
.okHttpClient { HttpClientManager.getHttpClient() }
|
||||||
.precision(Precision.INEXACT)
|
.precision(Precision.INEXACT)
|
||||||
.respectCacheHeaders(false)
|
.respectCacheHeaders(false)
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ class CashuProcessor {
|
|||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val client = HttpClient.getHttpClient()
|
val client = HttpClientManager.getHttpClient()
|
||||||
val url = "$mintAddress/checkfees" // Melt cashu tokens at Mint
|
val url = "$mintAddress/checkfees" // Melt cashu tokens at Mint
|
||||||
|
|
||||||
val factory = Event.mapper.nodeFactory
|
val factory = Event.mapper.nodeFactory
|
||||||
@@ -170,7 +170,7 @@ class CashuProcessor {
|
|||||||
context: Context,
|
context: Context,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
val client = HttpClient.getHttpClient()
|
val client = HttpClientManager.getHttpClient()
|
||||||
val url = token.mint + "/melt" // Melt cashu tokens at Mint
|
val url = token.mint + "/melt" // Melt cashu tokens at Mint
|
||||||
|
|
||||||
val factory = Event.mapper.nodeFactory
|
val factory = Event.mapper.nodeFactory
|
||||||
|
|||||||
+20
-27
@@ -32,14 +32,13 @@ import java.net.Proxy
|
|||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
object HttpClient {
|
object HttpClientManager {
|
||||||
val DEFAULT_TIMEOUT_ON_WIFI = Duration.ofSeconds(10L)
|
val DEFAULT_TIMEOUT_ON_WIFI: Duration = Duration.ofSeconds(10L)
|
||||||
val DEFAULT_TIMEOUT_ON_MOBILE = Duration.ofSeconds(30L)
|
val DEFAULT_TIMEOUT_ON_MOBILE: Duration = Duration.ofSeconds(30L)
|
||||||
|
|
||||||
var proxyChangeListeners = ArrayList<() -> Unit>()
|
var proxyChangeListeners = ArrayList<() -> Unit>()
|
||||||
var defaultTimeout = DEFAULT_TIMEOUT_ON_WIFI
|
private var defaultTimeout = DEFAULT_TIMEOUT_ON_WIFI
|
||||||
|
private var defaultHttpClient: OkHttpClient? = null
|
||||||
var defaultHttpClient: OkHttpClient? = null
|
|
||||||
|
|
||||||
// fires off every time value of the property changes
|
// fires off every time value of the property changes
|
||||||
private var internalProxy: Proxy? by
|
private var internalProxy: Proxy? by
|
||||||
@@ -49,29 +48,34 @@ object HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun start(proxy: Proxy?) {
|
fun setDefaultProxy(proxy: Proxy?) {
|
||||||
if (internalProxy != proxy) {
|
if (internalProxy != proxy) {
|
||||||
Log.d("HttpClient", "Changing proxy to: ${proxy != null}")
|
Log.d("HttpClient", "Changing proxy to: ${proxy != null}")
|
||||||
this.defaultHttpClient = null
|
|
||||||
this.internalProxy = proxy
|
this.internalProxy = proxy
|
||||||
this.defaultHttpClient = getHttpClient()
|
|
||||||
|
// recreates singleton
|
||||||
|
this.defaultHttpClient = buildHttpClient(internalProxy, defaultTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changeTimeouts(timeout: Duration) {
|
fun setDefaultTimeout(timeout: Duration) {
|
||||||
Log.d("HttpClient", "Changing timeout to: $timeout")
|
Log.d("HttpClient", "Changing timeout to: $timeout")
|
||||||
if (this.defaultTimeout.seconds != timeout.seconds) {
|
if (this.defaultTimeout.seconds != timeout.seconds) {
|
||||||
this.defaultHttpClient = null
|
|
||||||
this.defaultTimeout = timeout
|
this.defaultTimeout = timeout
|
||||||
this.defaultHttpClient = getHttpClient()
|
|
||||||
|
// recreates singleton
|
||||||
|
this.defaultHttpClient = buildHttpClient(internalProxy, defaultTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getHttpClient(timeout: Duration): OkHttpClient {
|
private fun buildHttpClient(
|
||||||
val seconds = if (internalProxy != null) timeout.seconds * 2 else timeout.seconds
|
proxy: Proxy?,
|
||||||
|
timeout: Duration,
|
||||||
|
): OkHttpClient {
|
||||||
|
val seconds = if (proxy != null) timeout.seconds * 2 else timeout.seconds
|
||||||
val duration = Duration.ofSeconds(seconds)
|
val duration = Duration.ofSeconds(seconds)
|
||||||
return OkHttpClient.Builder()
|
return OkHttpClient.Builder()
|
||||||
.proxy(internalProxy)
|
.proxy(proxy)
|
||||||
.readTimeout(duration)
|
.readTimeout(duration)
|
||||||
.connectTimeout(duration)
|
.connectTimeout(duration)
|
||||||
.writeTimeout(duration)
|
.writeTimeout(duration)
|
||||||
@@ -94,24 +98,13 @@ object HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getHttpClientForRelays(): OkHttpClient {
|
|
||||||
if (this.defaultHttpClient == null) {
|
|
||||||
this.defaultHttpClient = getHttpClient(defaultTimeout)
|
|
||||||
}
|
|
||||||
return defaultHttpClient!!
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getHttpClient(): OkHttpClient {
|
fun getHttpClient(): OkHttpClient {
|
||||||
if (this.defaultHttpClient == null) {
|
if (this.defaultHttpClient == null) {
|
||||||
this.defaultHttpClient = getHttpClient(defaultTimeout)
|
this.defaultHttpClient = buildHttpClient(internalProxy, defaultTimeout)
|
||||||
}
|
}
|
||||||
return defaultHttpClient!!
|
return defaultHttpClient!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getProxy(): Proxy? {
|
|
||||||
return internalProxy
|
|
||||||
}
|
|
||||||
|
|
||||||
fun initProxy(
|
fun initProxy(
|
||||||
useProxy: Boolean,
|
useProxy: Boolean,
|
||||||
hostname: String,
|
hostname: String,
|
||||||
@@ -64,7 +64,7 @@ class Nip05NostrAddressVerifier() {
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
HttpClient.getHttpClient()
|
HttpClientManager.getHttpClient()
|
||||||
.newCall(request)
|
.newCall(request)
|
||||||
.enqueue(
|
.enqueue(
|
||||||
object : Callback {
|
object : Callback {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Nip11Retriever {
|
|||||||
val request: Request =
|
val request: Request =
|
||||||
Request.Builder().header("Accept", "application/nostr+json").url(url).build()
|
Request.Builder().header("Accept", "application/nostr+json").url(url).build()
|
||||||
|
|
||||||
HttpClient.getHttpClient()
|
HttpClientManager.getHttpClient()
|
||||||
.newCall(request)
|
.newCall(request)
|
||||||
.enqueue(
|
.enqueue(
|
||||||
object : Callback {
|
object : Callback {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Nip96Retriever {
|
|||||||
.url(baseUrl.removeSuffix("/") + "/.well-known/nostr/nip96.json")
|
.url(baseUrl.removeSuffix("/") + "/.well-known/nostr/nip96.json")
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
HttpClient.getHttpClient().newCall(request).execute().use { response ->
|
HttpClientManager.getHttpClient().newCall(request).execute().use { response ->
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
response.use {
|
response.use {
|
||||||
val body = it.body.string()
|
val body = it.body.string()
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ class Nip96Uploader(val account: Account?) {
|
|||||||
val extension =
|
val extension =
|
||||||
contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
|
contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
|
||||||
|
|
||||||
val client = HttpClient.getHttpClient()
|
val client = HttpClientManager.getHttpClient()
|
||||||
val requestBody: RequestBody
|
val requestBody: RequestBody
|
||||||
val requestBuilder = Request.Builder()
|
val requestBuilder = Request.Builder()
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ class Nip96Uploader(val account: Account?) {
|
|||||||
val extension =
|
val extension =
|
||||||
contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
|
contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
|
||||||
|
|
||||||
val client = HttpClient.getHttpClient()
|
val client = HttpClientManager.getHttpClient()
|
||||||
|
|
||||||
val requestBuilder = Request.Builder()
|
val requestBuilder = Request.Builder()
|
||||||
|
|
||||||
@@ -227,7 +227,7 @@ class Nip96Uploader(val account: Account?) {
|
|||||||
server: Nip96Retriever.ServerInfo,
|
server: Nip96Retriever.ServerInfo,
|
||||||
onProgress: (percentage: Float) -> Unit,
|
onProgress: (percentage: Float) -> Unit,
|
||||||
): PartialEvent {
|
): PartialEvent {
|
||||||
val client = HttpClient.getHttpClient()
|
val client = HttpClientManager.getHttpClient()
|
||||||
var currentResult = result
|
var currentResult = result
|
||||||
|
|
||||||
while (!result.processingUrl.isNullOrBlank() && (currentResult.percentage ?: 100) < 100) {
|
while (!result.processingUrl.isNullOrBlank() && (currentResult.percentage ?: 100) < 100) {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ object OnlineChecker {
|
|||||||
.build()
|
.build()
|
||||||
|
|
||||||
val result =
|
val result =
|
||||||
HttpClient.getHttpClient().newCall(request).execute().use {
|
HttpClientManager.getHttpClient().newCall(request).execute().use {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
it.isSuccessful
|
it.isSuccessful
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -24,7 +24,7 @@ import android.content.Context
|
|||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.quartz.encoders.LnInvoiceUtil
|
import com.vitorpamplona.quartz.encoders.LnInvoiceUtil
|
||||||
import com.vitorpamplona.quartz.encoders.Lud06
|
import com.vitorpamplona.quartz.encoders.Lud06
|
||||||
@@ -35,7 +35,7 @@ import java.math.RoundingMode
|
|||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
|
||||||
class LightningAddressResolver() {
|
class LightningAddressResolver() {
|
||||||
val client = HttpClient.getHttpClient()
|
val client = HttpClientManager.getHttpClient()
|
||||||
|
|
||||||
fun assembleUrl(lnaddress: String): String? {
|
fun assembleUrl(lnaddress: String): String? {
|
||||||
val parts = lnaddress.split("@")
|
val parts = lnaddress.split("@")
|
||||||
|
|||||||
+2
-2
@@ -25,7 +25,7 @@ import com.vitorpamplona.amethyst.AccountInfo
|
|||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
import com.vitorpamplona.amethyst.LocalPreferences
|
import com.vitorpamplona.amethyst.LocalPreferences
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.quartz.events.RelayAuthEvent
|
import com.vitorpamplona.quartz.events.RelayAuthEvent
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -106,7 +106,7 @@ class RegisterAccounts(
|
|||||||
.post(body)
|
.post(body)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val client = HttpClient.getHttpClient()
|
val client = HttpClientManager.getHttpClient()
|
||||||
|
|
||||||
val isSucess = client.newCall(request).execute().use { it.isSuccessful }
|
val isSucess = client.newCall(request).execute().use { it.isSuccessful }
|
||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import androidx.media3.exoplayer.source.ProgressiveMediaSource
|
|||||||
import androidx.media3.session.MediaSession
|
import androidx.media3.session.MediaSession
|
||||||
import androidx.media3.session.MediaSessionService
|
import androidx.media3.session.MediaSessionService
|
||||||
import com.vitorpamplona.amethyst.Amethyst
|
import com.vitorpamplona.amethyst.Amethyst
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
|
|
||||||
@UnstableApi // Extend MediaSessionService
|
@UnstableApi // Extend MediaSessionService
|
||||||
class PlaybackService : MediaSessionService() {
|
class PlaybackService : MediaSessionService() {
|
||||||
@@ -42,12 +42,12 @@ class PlaybackService : MediaSessionService() {
|
|||||||
private var managerLocal: MultiPlayerPlaybackManager? = null
|
private var managerLocal: MultiPlayerPlaybackManager? = null
|
||||||
|
|
||||||
fun newHslDataSource(): MediaSource.Factory {
|
fun newHslDataSource(): MediaSource.Factory {
|
||||||
return HlsMediaSource.Factory(OkHttpDataSource.Factory(HttpClient.getHttpClient()))
|
return HlsMediaSource.Factory(OkHttpDataSource.Factory(HttpClientManager.getHttpClient()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun newProgressiveDataSource(): MediaSource.Factory {
|
fun newProgressiveDataSource(): MediaSource.Factory {
|
||||||
return ProgressiveMediaSource.Factory(
|
return ProgressiveMediaSource.Factory(
|
||||||
(applicationContext as Amethyst).videoCache.get(HttpClient.getHttpClient()),
|
(applicationContext as Amethyst).videoCache.get(HttpClientManager.getHttpClient()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ class PlaybackService : MediaSessionService() {
|
|||||||
Log.d("Lifetime Event", "PlaybackService.onCreate")
|
Log.d("Lifetime Event", "PlaybackService.onCreate")
|
||||||
|
|
||||||
// Stop all videos and recreates all managers when the proxy changes.
|
// Stop all videos and recreates all managers when the proxy changes.
|
||||||
HttpClient.proxyChangeListeners.add(this@PlaybackService::onProxyUpdated)
|
HttpClientManager.proxyChangeListeners.add(this@PlaybackService::onProxyUpdated)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onProxyUpdated() {
|
private fun onProxyUpdated() {
|
||||||
@@ -114,7 +114,7 @@ class PlaybackService : MediaSessionService() {
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
Log.d("Lifetime Event", "PlaybackService.onDestroy")
|
Log.d("Lifetime Event", "PlaybackService.onDestroy")
|
||||||
|
|
||||||
HttpClient.proxyChangeListeners.remove(this@PlaybackService::onProxyUpdated)
|
HttpClientManager.proxyChangeListeners.remove(this@PlaybackService::onProxyUpdated)
|
||||||
|
|
||||||
managerHls?.releaseAppPlayers()
|
managerHls?.releaseAppPlayers()
|
||||||
managerLocal?.releaseAppPlayers()
|
managerLocal?.releaseAppPlayers()
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.service.previews
|
package com.vitorpamplona.amethyst.service.previews
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.MediaType
|
import okhttp3.MediaType
|
||||||
@@ -90,7 +90,7 @@ suspend fun getDocument(
|
|||||||
): UrlInfoItem =
|
): UrlInfoItem =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val request: Request = Request.Builder().url(url).get().build()
|
val request: Request = Request.Builder().url(url).get().build()
|
||||||
HttpClient.getHttpClient().newCall(request).execute().use {
|
HttpClientManager.getHttpClient().newCall(request).execute().use {
|
||||||
if (it.isSuccessful) {
|
if (it.isSuccessful) {
|
||||||
val mimeType =
|
val mimeType =
|
||||||
it.headers.get("Content-Type")?.toMediaType()
|
it.headers.get("Content-Type")?.toMediaType()
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ package com.vitorpamplona.amethyst.service.relays
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
import com.vitorpamplona.amethyst.model.RelayBriefInfoCache
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.events.Event
|
import com.vitorpamplona.quartz.events.Event
|
||||||
@@ -62,7 +62,7 @@ class Relay(
|
|||||||
const val RECONNECTING_IN_SECONDS = 60 * 3
|
const val RECONNECTING_IN_SECONDS = 60 * 3
|
||||||
}
|
}
|
||||||
|
|
||||||
private val httpClient = HttpClient.getHttpClientForRelays()
|
private val httpClient = HttpClientManager.getHttpClient()
|
||||||
|
|
||||||
private var listeners = setOf<Listener>()
|
private var listeners = setOf<Listener>()
|
||||||
private var socket: WebSocket? = null
|
private var socket: WebSocket? = null
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|||||||
import com.google.accompanist.adaptive.calculateDisplayFeatures
|
import com.google.accompanist.adaptive.calculateDisplayFeatures
|
||||||
import com.vitorpamplona.amethyst.LocalPreferences
|
import com.vitorpamplona.amethyst.LocalPreferences
|
||||||
import com.vitorpamplona.amethyst.ServiceManager
|
import com.vitorpamplona.amethyst.ServiceManager
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.amethyst.service.lang.LanguageTranslatorService
|
import com.vitorpamplona.amethyst.service.lang.LanguageTranslatorService
|
||||||
import com.vitorpamplona.amethyst.service.notifications.PushNotificationUtils
|
import com.vitorpamplona.amethyst.service.notifications.PushNotificationUtils
|
||||||
import com.vitorpamplona.amethyst.ui.components.DEFAULT_MUTED_SETTING
|
import com.vitorpamplona.amethyst.ui.components.DEFAULT_MUTED_SETTING
|
||||||
@@ -236,9 +236,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
if (changedNetwork) {
|
if (changedNetwork) {
|
||||||
if (isOnMobileData) {
|
if (isOnMobileData) {
|
||||||
HttpClient.changeTimeouts(HttpClient.DEFAULT_TIMEOUT_ON_MOBILE)
|
HttpClientManager.setDefaultTimeout(HttpClientManager.DEFAULT_TIMEOUT_ON_MOBILE)
|
||||||
} else {
|
} else {
|
||||||
HttpClient.changeTimeouts(HttpClient.DEFAULT_TIMEOUT_ON_WIFI)
|
HttpClientManager.setDefaultTimeout(HttpClientManager.DEFAULT_TIMEOUT_ON_WIFI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import android.provider.MediaStore
|
|||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import okhttp3.Call
|
import okhttp3.Call
|
||||||
import okhttp3.Callback
|
import okhttp3.Callback
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
@@ -55,7 +55,7 @@ object ImageSaver {
|
|||||||
onSuccess: () -> Any?,
|
onSuccess: () -> Any?,
|
||||||
onError: (Throwable) -> Any?,
|
onError: (Throwable) -> Any?,
|
||||||
) {
|
) {
|
||||||
val client = HttpClient.getHttpClient()
|
val client = HttpClientManager.getHttpClient()
|
||||||
|
|
||||||
val request =
|
val request =
|
||||||
Request.Builder()
|
Request.Builder()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import com.vitorpamplona.amethyst.AccountInfo
|
|||||||
import com.vitorpamplona.amethyst.LocalPreferences
|
import com.vitorpamplona.amethyst.LocalPreferences
|
||||||
import com.vitorpamplona.amethyst.ServiceManager
|
import com.vitorpamplona.amethyst.ServiceManager
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||||
import com.vitorpamplona.quartz.encoders.Hex
|
import com.vitorpamplona.quartz.encoders.Hex
|
||||||
@@ -85,7 +85,7 @@ class AccountStateViewModel() : ViewModel() {
|
|||||||
) = withContext(Dispatchers.IO) {
|
) = withContext(Dispatchers.IO) {
|
||||||
val parsed = Nip19.uriToRoute(key)
|
val parsed = Nip19.uriToRoute(key)
|
||||||
val pubKeyParsed = parsed?.hex?.hexToByteArray()
|
val pubKeyParsed = parsed?.hex?.hexToByteArray()
|
||||||
val proxy = HttpClient.initProxy(useProxy, "127.0.0.1", proxyPort)
|
val proxy = HttpClientManager.initProxy(useProxy, "127.0.0.1", proxyPort)
|
||||||
|
|
||||||
if (loginWithExternalSigner && pubKeyParsed == null) {
|
if (loginWithExternalSigner && pubKeyParsed == null) {
|
||||||
throw Exception("Invalid key while trying to login with external signer")
|
throw Exception("Invalid key while trying to login with external signer")
|
||||||
@@ -216,7 +216,7 @@ class AccountStateViewModel() : ViewModel() {
|
|||||||
name: String? = null,
|
name: String? = null,
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val proxy = HttpClient.initProxy(useProxy, "127.0.0.1", proxyPort)
|
val proxy = HttpClientManager.initProxy(useProxy, "127.0.0.1", proxyPort)
|
||||||
val keyPair = KeyPair()
|
val keyPair = KeyPair()
|
||||||
val account =
|
val account =
|
||||||
Account(
|
Account(
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import com.vitorpamplona.amethyst.model.User
|
|||||||
import com.vitorpamplona.amethyst.model.UserState
|
import com.vitorpamplona.amethyst.model.UserState
|
||||||
import com.vitorpamplona.amethyst.service.CashuProcessor
|
import com.vitorpamplona.amethyst.service.CashuProcessor
|
||||||
import com.vitorpamplona.amethyst.service.CashuToken
|
import com.vitorpamplona.amethyst.service.CashuToken
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
import com.vitorpamplona.amethyst.service.Nip05NostrAddressVerifier
|
import com.vitorpamplona.amethyst.service.Nip05NostrAddressVerifier
|
||||||
import com.vitorpamplona.amethyst.service.Nip11CachedRetriever
|
import com.vitorpamplona.amethyst.service.Nip11CachedRetriever
|
||||||
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
import com.vitorpamplona.amethyst.service.Nip11Retriever
|
||||||
@@ -1042,7 +1042,7 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
|||||||
) {
|
) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
account.proxyPort = portNumber.value.toInt()
|
account.proxyPort = portNumber.value.toInt()
|
||||||
account.proxy = HttpClient.initProxy(checked, "127.0.0.1", account.proxyPort)
|
account.proxy = HttpClientManager.initProxy(checked, "127.0.0.1", account.proxyPort)
|
||||||
account.saveable.invalidateData()
|
account.saveable.invalidateData()
|
||||||
serviceManager?.forceRestart()
|
serviceManager?.forceRestart()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user