Skip to content

Commit

Permalink
fix(app): actions crash
Browse files Browse the repository at this point in the history
Signed-off-by: rhunk <[email protected]>
  • Loading branch information
rhunk committed Jun 8, 2024
1 parent c8819cf commit 5fbd766
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
14 changes: 14 additions & 0 deletions app/src/main/kotlin/me/rhunk/snapenhance/RemoteSideContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import me.rhunk.snapenhance.bridge.BridgeService
import me.rhunk.snapenhance.common.BuildConfig
import me.rhunk.snapenhance.common.Constants
import me.rhunk.snapenhance.common.action.EnumAction
import me.rhunk.snapenhance.common.bridge.wrapper.LocaleWrapper
import me.rhunk.snapenhance.common.bridge.wrapper.LoggerWrapper
import me.rhunk.snapenhance.common.bridge.wrapper.MappingsWrapper
Expand Down Expand Up @@ -223,4 +225,16 @@ class RemoteSideContext(
return true
}
}

fun launchActionIntent(action: EnumAction) {
val intent = androidContext.packageManager.getLaunchIntentForPackage(
Constants.SNAPCHAT_PACKAGE_NAME
)
if (intent == null) {
shortToast("Can't execute action: Snapchat is not installed")
return
}
intent.putExtra(EnumAction.ACTION_PARAMETER, action.key)
androidContext.startActivity(intent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ class HomeRootSection : Routes.Route() {

private lateinit var activityLauncherHelper: ActivityLauncherHelper

private fun launchActionIntent(action: EnumAction) {
val intent = context.androidContext.packageManager.getLaunchIntentForPackage(
Constants.SNAPCHAT_PACKAGE_NAME
)
intent?.putExtra(EnumAction.ACTION_PARAMETER, action.key)
context.androidContext.startActivity(intent)
}

private val cards by lazy {
EnumQuickActions.entries.map {
Expand All @@ -70,7 +63,7 @@ class HomeRootSection : Routes.Route() {
}.toMutableMap().apply {
EnumAction.entries.forEach { action ->
this[context.translation["actions.${action.key}.name"] to action.icon] = {
launchActionIntent(action)
context.launchActionIntent(action)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ class HomeSettings : Routes.Route() {
}
}

private fun launchActionIntent(action: EnumAction) {
val intent = context.androidContext.packageManager.getLaunchIntentForPackage(Constants.SNAPCHAT_PACKAGE_NAME)
intent?.putExtra(EnumAction.ACTION_PARAMETER, action.key)
context.androidContext.startActivity(intent)
}

@Composable
private fun ShiftedRow(
modifier: Modifier = Modifier,
Expand All @@ -151,7 +145,7 @@ class HomeSettings : Routes.Route() {
RowTitle(title = translation["actions_title"])
EnumAction.entries.forEach { enumAction ->
RowAction(key = enumAction.key) {
launchActionIntent(enumAction)
context.launchActionIntent(enumAction)
}
}
RowAction(key = "regen_mappings") {
Expand Down

0 comments on commit 5fbd766

Please sign in to comment.