mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-11 00:12:24 +01:00
voice: "play X" reopens the music app used last when none is open or it was closed
This commit is contained in:
1 parent
a526db6cd1
commit
28d99a3d87
1 file changed
+14
-1
@@ -1,6 +1,7 @@
|
|||||||
package app.seb3thehacker.gearslip.car
|
package app.seb3thehacker.gearslip.car
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import app.seb3thehacker.gearslip.media.CarMedia
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -169,7 +170,19 @@ object AssistantCommands {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
val app = media.appLabel ?: return "Open a music app first, then ask again."
|
// No music app open, or its connection is gone (the app was closed): use the one played
|
||||||
|
// last, the way "play X" works on Android Auto.
|
||||||
|
val phase = media.phase.value
|
||||||
|
if (media.appLabel == null || phase == CarMedia.Phase.IDLE || phase == CarMedia.Phase.REJECTED) {
|
||||||
|
if (!CarServices.reopenLastMedia()) return "Open a music app first, then ask again."
|
||||||
|
navigator.media()
|
||||||
|
}
|
||||||
|
withTimeoutOrNull(APP_CONNECT_MS) {
|
||||||
|
while (media.phase.value != CarMedia.Phase.READY || media.appLabel == null ||
|
||||||
|
(!media.canSearchLibrary && !media.now.value.canSearch)
|
||||||
|
) delay(200)
|
||||||
|
}
|
||||||
|
val app = media.appLabel ?: return "Your music app didn't open in time. Try again."
|
||||||
if (!media.canSearchLibrary && !media.now.value.canSearch) {
|
if (!media.canSearchLibrary && !media.now.value.canSearch) {
|
||||||
return "$app ignores voice searches. Pick something on its screen instead."
|
return "$app ignores voice searches. Pick something on its screen instead."
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user