Skip to content

Commit

Permalink
Fix tool broadcasts
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Jul 20, 2024
1 parent f63ae9f commit f26e6b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.util.Log
import androidx.core.os.bundleOf
import com.kylecorry.andromeda.permissions.Permissions
import com.kylecorry.luna.coroutines.onMain
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.receivers.ServiceRestartAlerter
import com.kylecorry.trail_sense.shared.UserPreferences
Expand Down Expand Up @@ -61,11 +62,12 @@ class BacktrackToolService(private val context: Context) : ToolService {
Log.d("BacktrackSubsystem", "Cannot start backtrack")
return
}



prefs.backtrackEnabled = true
Tools.broadcast(PathsToolRegistration.BROADCAST_BACKTRACK_ENABLED)
restart()
if (!isBlocked()) {
start(true)
}
}

override suspend fun disable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package com.kylecorry.trail_sense.tools.tools.infrastructure
import android.content.Context
import android.os.Bundle
import com.kylecorry.andromeda.core.capitalizeWords
import com.kylecorry.andromeda.core.system.Intents
import com.kylecorry.andromeda.core.system.Resources
import com.kylecorry.luna.hooks.Hooks
import com.kylecorry.luna.topics.generic.Topic
import com.kylecorry.luna.topics.generic.ITopic
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.settings.SettingsToolRegistration
import com.kylecorry.trail_sense.shared.quickactions.QuickActionOpenTool
Expand Down Expand Up @@ -52,6 +50,9 @@ import com.kylecorry.trail_sense.tools.waterpurification.WaterBoilTimerToolRegis
import com.kylecorry.trail_sense.tools.weather.WeatherToolRegistration
import com.kylecorry.trail_sense.tools.whistle.WhistleToolRegistration
import com.kylecorry.trail_sense.tools.whitenoise.WhiteNoiseToolRegistration
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

object Tools {

Expand Down Expand Up @@ -99,6 +100,8 @@ object Tools {
LocalTalkToolRegistration
)
private val topics = mutableMapOf<String, Topic<Bundle>>()
private val broadcastScope = CoroutineScope(Dispatchers.Main)


fun isToolAvailable(context: Context, toolId: Long): Boolean {
return getTool(context, toolId) != null
Expand Down Expand Up @@ -146,7 +149,9 @@ object Tools {
}

fun broadcast(toolBroadcastId: String, data: Bundle? = null) {
topics[toolBroadcastId]?.publish(data ?: Bundle())
broadcastScope.launch {
topics[toolBroadcastId]?.publish(data ?: Bundle())
}
}

fun subscribe(toolBroadcastId: String, callback: (Bundle) -> Boolean) {
Expand Down

0 comments on commit f26e6b8

Please sign in to comment.