Skip to content

Commit

Permalink
Fix music widget not launching player app
Browse files Browse the repository at this point in the history
  • Loading branch information
MM2-0 committed Jul 24, 2024
1 parent de3b7ba commit fd50aa1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import de.mm20.launcher2.crashreporter.CrashReporter
import de.mm20.launcher2.ktx.sendWithBackgroundPermission
import de.mm20.launcher2.music.MusicService
import de.mm20.launcher2.music.PlaybackState
import de.mm20.launcher2.music.SupportedActions
Expand Down Expand Up @@ -68,8 +71,11 @@ class MusicPartProvider : PartProvider, KoinComponent {
.combinedClickable(
onClick = {
try {
musicService.openPlayer()?.send()
musicService
.openPlayer()
?.sendWithBackgroundPermission(context)
} catch (e: PendingIntent.CanceledException) {
CrashReporter.logException(e)
}
},
onLongClick = {
Expand Down Expand Up @@ -99,14 +105,17 @@ class MusicPartProvider : PartProvider, KoinComponent {
painter = rememberAnimatedVectorPainter(
animatedImageVector = playIcon,
atEnd = state == PlaybackState.Playing
), contentDescription = null
), contentDescription = stringResource(
if (state == PlaybackState.Playing) R.string.music_widget_pause
else R.string.music_widget_play
)
)
}
if (supportedActions.skipToNext) {
IconButton(onClick = { musicService.next() }) {
Icon(
imageVector = Icons.Rounded.SkipNext,
contentDescription = null
contentDescription = stringResource(R.string.music_widget_next_track)
)
}
}
Expand All @@ -122,7 +131,7 @@ class MusicPartProvider : PartProvider, KoinComponent {
.combinedClickable(
onClick = {
try {
musicService.openPlayer()?.send()
musicService.openPlayer()?.sendWithBackgroundPermission(context)
} catch (e: PendingIntent.CanceledException) {
}
},
Expand Down Expand Up @@ -156,7 +165,7 @@ class MusicPartProvider : PartProvider, KoinComponent {
IconButton(onClick = { musicService.previous() }) {
Icon(
imageVector = Icons.Rounded.SkipPrevious,
contentDescription = null
contentDescription = stringResource(R.string.music_widget_previous_track)
)
}
}
Expand All @@ -165,14 +174,17 @@ class MusicPartProvider : PartProvider, KoinComponent {
painter = rememberAnimatedVectorPainter(
animatedImageVector = playIcon,
atEnd = state == PlaybackState.Playing
), contentDescription = null
), contentDescription = stringResource(
if (state == PlaybackState.Playing) R.string.music_widget_pause
else R.string.music_widget_play
)
)
}
if (supportedActions.skipToPrevious) {
IconButton(onClick = { musicService.next() }) {
Icon(
imageVector = Icons.Rounded.SkipNext,
contentDescription = null
contentDescription = stringResource(R.string.music_widget_next_track)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fun MusicWidget(widget: MusicWidget) {
.clip(MaterialTheme.shapes.small)
.combinedClickable(
onClick = {
viewModel.openPlayer()
viewModel.openPlayer(context)
},
onLongClick = {
viewModel.openPlayerSelector(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.media.session.PlaybackState.CustomAction
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import de.mm20.launcher2.crashreporter.CrashReporter
import de.mm20.launcher2.ktx.sendWithBackgroundPermission
import de.mm20.launcher2.music.MusicService
import de.mm20.launcher2.music.PlaybackState
import de.mm20.launcher2.music.SupportedActions
Expand Down Expand Up @@ -50,9 +51,9 @@ class MusicWidgetVM: ViewModel(), KoinComponent {
musicService.togglePause()
}

fun openPlayer() {
fun openPlayer(context: Context) {
try {
musicService.openPlayer()?.send()
musicService.openPlayer()?.sendWithBackgroundPermission(context)
} catch (e: PendingIntent.CanceledException) {
CrashReporter.logException(e)
}
Expand Down

0 comments on commit fd50aa1

Please sign in to comment.