Skip to content

Commit

Permalink
changes for cherry-pick
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyabsi committed Dec 11, 2024
1 parent 7e043fe commit c97ac3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
29 changes: 14 additions & 15 deletions app/src/main/java/cc/sovellus/vrcaa/service/PipelineService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 ->
Expand Down Expand Up @@ -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) }
}
}
}
Expand Down Expand Up @@ -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" -> {
Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -386,9 +385,9 @@ class PipelineService : Service(), CoroutineScope {
}

override fun onDestroy() {
pipeline?.disconnect()
pipeline.disconnect()
if (preferences.richPresenceEnabled) {
gateway?.disconnect()
gateway.disconnect()
}
}

Expand Down

0 comments on commit c97ac3c

Please sign in to comment.