From c97ac3ce1a70b432b2a97e73fe1bcdba7c72a695 Mon Sep 17 00:00:00 2001 From: Nyabsi Date: Wed, 11 Dec 2024 12:33:28 +0200 Subject: [PATCH] changes for cherry-pick --- app/build.gradle.kts | 1 + .../sovellus/vrcaa/service/PipelineService.kt | 29 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6b8cbfb82..bc39e4725 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -139,4 +139,5 @@ dependencies { implementation ("androidx.glance:glance-appwidget:1.1.1") implementation ("androidx.glance:glance-material3:1.1.1@aar") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") + implementation("net.thauvin.erik.urlencoder:urlencoder-lib:1.6.0") } diff --git a/app/src/main/java/cc/sovellus/vrcaa/service/PipelineService.kt b/app/src/main/java/cc/sovellus/vrcaa/service/PipelineService.kt index 051cc8db0..8f11378a2 100644 --- a/app/src/main/java/cc/sovellus/vrcaa/service/PipelineService.kt +++ b/app/src/main/java/cc/sovellus/vrcaa/service/PipelineService.kt @@ -14,7 +14,6 @@ import android.os.Process.THREAD_PRIORITY_FOREGROUND import androidx.core.app.NotificationCompat import cc.sovellus.vrcaa.R import cc.sovellus.vrcaa.api.discord.DiscordGateway -import cc.sovellus.vrcaa.api.vrchat.VRChatPipeline import cc.sovellus.vrcaa.api.vrchat.models.websocket.FriendAdd import cc.sovellus.vrcaa.api.vrchat.models.websocket.FriendDelete import cc.sovellus.vrcaa.api.vrchat.models.websocket.FriendLocation @@ -24,6 +23,7 @@ import cc.sovellus.vrcaa.api.vrchat.models.websocket.FriendUpdate import cc.sovellus.vrcaa.api.vrchat.models.websocket.Notification import cc.sovellus.vrcaa.api.vrchat.models.websocket.UserLocation import cc.sovellus.vrcaa.api.vrchat.models.websocket.UserUpdate +import cc.sovellus.vrcaa.api.vrchat.pipeline.PipelineSocket import cc.sovellus.vrcaa.extension.discordToken import cc.sovellus.vrcaa.extension.richPresenceEnabled import cc.sovellus.vrcaa.extension.richPresenceWebhookUrl @@ -49,9 +49,8 @@ class PipelineService : Service(), CoroutineScope { override val coroutineContext = Dispatchers.Main + SupervisorJob() private lateinit var preferences: SharedPreferences - - private var pipeline: VRChatPipeline? = null - private var gateway: DiscordGateway? = null + private lateinit var pipeline: PipelineSocket + private lateinit var gateway: DiscordGateway private var serviceLooper: Looper? = null private var serviceHandler: ServiceHandler? = null @@ -64,7 +63,7 @@ class PipelineService : Service(), CoroutineScope { } } - private val listener = object : VRChatPipeline.SocketListener { + private val listener = object : PipelineSocket.SocketListener { override fun onMessage(message: Any?) { if (message != null) { serviceHandler?.obtainMessage()?.also { msg -> @@ -244,9 +243,9 @@ class PipelineService : Service(), CoroutineScope { val status = StatusHelper.getStatusFromString(user.user.status) val location = LocationHelper.parseLocationInfo(user.location) launch { - val instance = api.getInstance(user.location) + val instance = api.instances.fetchInstance(user.location) instance?.let { - instance.world.name.let { gateway?.sendPresence(it, "${location.instanceType} #${instance.name} (${instance.nUsers} of ${instance.capacity})", instance.world.imageUrl, status) } + instance.world.name.let { gateway.sendPresence(it, "${location.instanceType} #${instance.name} (${instance.nUsers} of ${instance.capacity})", instance.world.imageUrl, status) } } } } @@ -312,7 +311,7 @@ class PipelineService : Service(), CoroutineScope { launch { withContext(Dispatchers.Main) { - val sender = api.getUser(notification.senderUserId) + val sender = api.users.fetchUserByUserId(notification.senderUserId) when (notification.type) { "friendRequest" -> { @@ -341,15 +340,15 @@ class PipelineService : Service(), CoroutineScope { this.preferences = getSharedPreferences("vrcaa_prefs", 0) launch { - api.getAuth()?.let { token -> - pipeline = VRChatPipeline(token) - pipeline?.setListener(listener) - pipeline?.connect() + api.auth.fetchToken()?.let { token -> + pipeline = PipelineSocket(token) + pipeline.setListener(listener) + pipeline.connect() } if (preferences.richPresenceEnabled) { gateway = DiscordGateway(preferences.discordToken, preferences.richPresenceWebhookUrl) - gateway?.connect() + gateway.connect() } } @@ -386,9 +385,9 @@ class PipelineService : Service(), CoroutineScope { } override fun onDestroy() { - pipeline?.disconnect() + pipeline.disconnect() if (preferences.richPresenceEnabled) { - gateway?.disconnect() + gateway.disconnect() } }