Skip to content

Commit

Permalink
Begin PlayerState refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterofbread committed Jul 24, 2024
1 parent 676f443 commit a8792d3
Show file tree
Hide file tree
Showing 193 changed files with 1,588 additions and 1,258 deletions.
12 changes: 6 additions & 6 deletions buildSrc/src/main/kotlin/plugins/spmp/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ class SpMpDeps(extra: Map<String, Any>) {
val dependencies: Map<String, DependencyInfo> =
mapOf(
"dev.toastbits:spms" to DependencyInfo(
version = "0.4.0-beta2-SNAPSHOT",
version = "0.3.1-wasm2",
name = "spmp-server",
author = "toasterofbread",
url = "https://github.com/toasterofbread/spmp-server",
license = "GPL-2.0",
license_url = "https://github.com/toasterofbread/spmp-server/blob/6dde651ffc102d604ac7ecd5ac7471b1572fd2e6/LICENSE"
),
"dev.toastbits.composekit" to DependencyInfo(
version = "0.0.3-SNAPSHOT",
version = "e83119148b",
name = "ComposeKit",
author = "toasterofbread",
url = "https://github.com/toasterofbread/composekit",
license = "GPL-3.0",
license_url = "https://github.com/toasterofbread/ComposeKit/blob/136f216e65395660255d3270af9b79c90ae2254c/LICENSE"
),
"dev.toastbits.ytmkt" to DependencyInfo(
version = "0.2.6-SNAPSHOT",
version = "0.3.0",
name = "ytm-kt",
author = "toasterofbread",
url = "https://github.com/toasterofbread/ytm-kt",
Expand All @@ -59,8 +59,8 @@ class SpMpDeps(extra: Map<String, Any>) {
license = "Apache-2.0",
license_url = "https://github.com/toasterofbread/mediasession-kt/blob/fd4c5e876e2782dbe856b886f5b8dc083c26293c/LICENSE"
),
"dev.toastbits.kanakt" to DependencyInfo(
version = "0.0.1",
"dev.toastbits.kana-kt" to DependencyInfo(
version = "c891811875",
name = "kana-kt",
author = "toasterofbread",
url = "https://github.com/toasterofbread/kana-kt",
Expand All @@ -77,7 +77,7 @@ class SpMpDeps(extra: Map<String, Any>) {
license_url = "https://github.com/Kotlin/kotlinx.serialization/blob/51cb8e8e556983fc83a565d5f04bb089363453e0/LICENSE.txt"
),
"org.jetbrains.compose" to DependencyInfo(
version = "1.6.2",
version = extra["compose.version"] as String,
name = "Compose Multiplatform",
author = "JetBrains",
url = "https://github.com/JetBrains/compose-multiplatform",
Expand Down
4 changes: 2 additions & 2 deletions desktopApp/src/jvmMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.toasterofbread.spmp.ui.component.shortcut.trigger.KeyboardShortcutTri
import com.toasterofbread.spmp.ui.layout.apppage.mainpage.getTextFieldFocusState
import com.toasterofbread.spmp.ui.layout.apppage.mainpage.isTextFieldFocused
import com.toasterofbread.spmp.model.appaction.shortcut.ShortcutState
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import kotlinx.coroutines.*
import org.jetbrains.compose.resources.getString
import org.jetbrains.skiko.OS
Expand Down Expand Up @@ -70,7 +70,7 @@ fun main(args: Array<String>) {
val enable_window_transparency: Boolean = runBlocking { context.settings.theme.ENABLE_WINDOW_TRANSPARENCY.get() }

val shortcut_state: ShortcutState = ShortcutState()
var player: PlayerState? = null
var player: OldPlayerStateImpl? = null

application {
val text_field_focus_state: Any = getTextFieldFocusState()
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pluginManagement {
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
repositories {
google()
mavenCentral()
Expand Down
41 changes: 24 additions & 17 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ kotlin {
implementation(deps.get("dev.toastbits:spms"))
implementation(deps.get("dev.toastbits.composekit:library"))
implementation(deps.get("dev.toastbits.ytmkt:ytmkt"))
implementation(deps.get("dev.toastbits.kanakt:kanakt"))
implementation(deps.get("dev.toastbits.kana-kt:kanakt"))

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
Expand Down Expand Up @@ -174,9 +174,16 @@ kotlin {
implementation(deps.get("app.cash.sqldelight:web-worker-driver-wasm-js"))

// TEMP
implementation("com.catppuccin:catppuccin-kotlin-wasm-js:1.0.3-dev")
implementation("com.github.wanasit.kotori:kotori-wasm-js:1.0.0-TEST")
}
}

commonTest {
dependencies {
implementation(kotlin("test"))
}
}
}
}

Expand Down Expand Up @@ -243,20 +250,20 @@ afterEvaluate {
finalizedBy(fixDatabaseVersion)
}

rootProject.tasks.apply {
getByName("kotlinNodeJsSetup") {
enabled = false
}

getByName("kotlinNpmInstall") {
enabled = false
}

getByName<YarnLockStoreTask>("kotlinStoreYarnLock") {
inputFile.asFile.get().apply {
parentFile.mkdirs()
createNewFile()
}
}
}
// rootProject.tasks.apply {
// getByName("kotlinNodeJsSetup") {
// enabled = false
// }
//
// getByName("kotlinNpmInstall") {
// enabled = false
// }
//
// getByName<YarnLockStoreTask>("kotlinStoreYarnLock") {
// inputFile.asFile.get().apply {
// parentFile.mkdirs()
// createNewFile()
// }
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.platform.AppContext
import com.toasterofbread.spmp.platform.startPlatformService
import com.toasterofbread.spmp.platform.unbindPlatformService
import com.toasterofbread.spmp.service.playercontroller.DownloadRequestCallback
import com.toasterofbread.spmp.model.state.DownloadRequestCallback
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import com.toasterofbread.spmp.platform.AppContext
import LocalProgramArguments
import LocalPlayerState
Expand All @@ -19,7 +19,7 @@ import spmp.shared.generated.resources.loading_splash_button_launch_without_serv
internal class HeadlessExternalPlayerService: ExternalPlayerService(plays_audio = false), PlayerService {
@Composable
override fun PersistentContent(requestServiceChange: (PlayerServiceCompanion) -> Unit) {
val player: PlayerState = LocalPlayerState.current
val player: OldPlayerStateImpl = LocalPlayerState.current
val launch_arguments: ProgramArguments = LocalProgramArguments.current
val ui_only: Boolean by player.settings.platform.EXTERNAL_SERVER_MODE_UI_ONLY.observe()
LaunchedEffect(ui_only) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.model.radio.RadioInstance
import com.toasterofbread.spmp.platform.AppContext
import com.toasterofbread.spmp.platform.PlayerListener
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import dev.toastbits.spms.socketapi.shared.SpMsPlayerRepeatMode
Expand Down Expand Up @@ -47,7 +47,7 @@ actual class PlatformExternalPlayerService: ForegroundPlayerService(play_when_re

@Composable
override fun PersistentContent(requestServiceChange: (PlayerServiceCompanion) -> Unit) {
val player: PlayerState = LocalPlayerState.current
val player: OldPlayerStateImpl = LocalPlayerState.current
val launch_arguments: ProgramArguments = LocalProgramArguments.current
val ui_only: Boolean by player.settings.platform.EXTERNAL_SERVER_MODE_UI_ONLY.observe()
LaunchedEffect(ui_only) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import dev.toastbits.composekit.utils.composable.SubtleLoadingIndicator
import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.platform.playerservice.getMediaNotificationImageMaxOffset
import com.toasterofbread.spmp.platform.playerservice.getMediaNotificationImageSize
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import kotlin.math.roundToInt
import kotlinx.coroutines.CoroutineScope
import org.jetbrains.compose.resources.stringResource
Expand All @@ -67,7 +67,7 @@ actual class NotifImagePlayerOverlayMenu: PlayerOverlayMenu() {
getCurrentSongThumb: () -> ImageBitmap?,
) {
val song: Song = getSong() ?: return
val player: PlayerState = LocalPlayerState.current
val player: OldPlayerStateImpl = LocalPlayerState.current

Column(
Modifier.fillMaxSize(),
Expand Down
12 changes: 6 additions & 6 deletions shared/src/commonMain/kotlin/SpMp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.toasterofbread.spmp.model.settings.category.FontMode
import com.toasterofbread.spmp.platform.AppContext
import com.toasterofbread.spmp.platform.getUiLanguage
import com.toasterofbread.spmp.platform.playerservice.ClientServerPlayerService
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import com.toasterofbread.spmp.service.playercontroller.openUri
import com.toasterofbread.spmp.ui.layout.apppage.mainpage.RootView
import com.toasterofbread.spmp.ui.layout.loadingsplash.LoadingSplash
Expand All @@ -45,7 +45,7 @@ import spmp.shared.generated.resources.app_name
import spmp.shared.generated.resources.warning_spms_api_version_mismatch
import spmp.shared.generated.resources.`warning_spms_api_version_mismatch_$theirs_$ours`

val LocalPlayerState: ProvidableCompositionLocal<PlayerState> = staticCompositionLocalOf { SpMp.player_state }
val LocalPlayerState: ProvidableCompositionLocal<OldPlayerStateImpl> = staticCompositionLocalOf { SpMp.player_state }
val LocalProgramArguments: ProvidableCompositionLocal<ProgramArguments> = staticCompositionLocalOf { ProgramArguments() }

object LocalNowPlayingExpansion {
Expand All @@ -58,9 +58,9 @@ object SpMp {

private lateinit var context: AppContext

var _player_state: PlayerState? = null
var _player_state: OldPlayerStateImpl? = null
private set
val player_state: PlayerState get() = _player_state!!
val player_state: OldPlayerStateImpl get() = _player_state!!

val prefs: PlatformPreferences get() = context.getPrefs()

Expand All @@ -74,10 +74,10 @@ object SpMp {
suspend fun initPlayer(
launch_arguments: ProgramArguments,
composable_coroutine_scope: CoroutineScope
): PlayerState {
): OldPlayerStateImpl {
val np_theme_mode: ThemeMode = context.settings.theme.NOWPLAYING_THEME_MODE.get()
val swipe_sensitivity: Float = context.settings.player.EXPAND_SWIPE_SENSITIVITY.get()
val player: PlayerState = PlayerState(context, launch_arguments, composable_coroutine_scope, np_theme_mode, swipe_sensitivity)
val player: OldPlayerStateImpl = OldPlayerStateImpl(context, launch_arguments, composable_coroutine_scope, np_theme_mode, swipe_sensitivity)
player.onStart()
_player_state = player
return player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.toasterofbread.spmp.platform.getUiLanguage
import com.toasterofbread.spmp.platform.observeUiLanguage
import com.toasterofbread.spmp.resources.Language
import com.toasterofbread.spmp.resources.getResourceEnvironment
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import dev.toastbits.ytmkt.uistrings.RawUiString
import dev.toastbits.ytmkt.uistrings.UiString
import dev.toastbits.ytmkt.uistrings.YoutubeUiString
Expand All @@ -36,7 +36,7 @@ data class AppUiString(

@Composable
fun UiString.observe(): String {
val player: PlayerState = LocalPlayerState.current
val player: OldPlayerStateImpl = LocalPlayerState.current
var string: String by remember { mutableStateOf("") }
val ui_language: String by player.context.observeUiLanguage()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.ui.*
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import com.toasterofbread.spmp.model.appaction.action.playback.*
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import kotlinx.serialization.Serializable
import org.jetbrains.compose.resources.stringResource
import spmp.shared.generated.resources.Res
Expand All @@ -25,7 +25,7 @@ sealed interface AppAction {
fun getIcon(): ImageVector
fun isUsableDuringTextInput(): Boolean = false

suspend fun executeAction(player: PlayerState)
suspend fun executeAction(player: OldPlayerStateImpl)

fun hasCustomContent(): Boolean = false
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.toasterofbread.spmp.model.appaction

import kotlinx.serialization.Serializable
import com.toasterofbread.spmp.ui.layout.apppage.AppPage
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import com.toasterofbread.spmp.model.appaction.AppAction
import com.toasterofbread.spmp.model.appaction.action.navigation.*
import dev.toastbits.composekit.utils.composable.LargeDropdownMenu
Expand All @@ -28,7 +28,7 @@ data class NavigationAppAction(
): AppAction {
override fun getType(): AppAction.Type = AppAction.Type.NAVIGATION
override fun getIcon(): ImageVector = action.getIcon()
override suspend fun executeAction(player: PlayerState) {
override suspend fun executeAction(player: OldPlayerStateImpl) {
action.execute(player)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.material3.Button
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import com.toasterofbread.spmp.model.appaction.AppAction
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import dev.toastbits.composekit.utils.composable.LargeDropdownMenu
import dev.toastbits.composekit.platform.Platform
import dev.toastbits.composekit.platform.composable.onWindowBackPressed
Expand All @@ -37,7 +37,7 @@ data class OtherAppAction(
override fun getIcon(): ImageVector = action.getIcon()
override fun isUsableDuringTextInput(): Boolean = action.isUsableDuringTextInput()

override suspend fun executeAction(player: PlayerState) {
override suspend fun executeAction(player: OldPlayerStateImpl) {
action.execute(player)
}

Expand Down Expand Up @@ -138,7 +138,7 @@ data class OtherAppAction(
else -> false
}

suspend fun execute(player: PlayerState) {
suspend fun execute(player: OldPlayerStateImpl) {
when (this) {
NAVIGATE_BACK -> onWindowBackPressed(player.context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.material3.Text
import androidx.compose.material3.Button
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import com.toasterofbread.spmp.model.appaction.action.playback.*
import dev.toastbits.composekit.utils.composable.LargeDropdownMenu
import org.jetbrains.compose.resources.stringResource
Expand All @@ -24,7 +24,7 @@ data class PlaybackAppAction(
): AppAction {
override fun getType(): AppAction.Type = AppAction.Type.PLAYBACK
override fun getIcon(): ImageVector = action.getType().getIcon()
override suspend fun executeAction(player: PlayerState) {
override suspend fun executeAction(player: OldPlayerStateImpl) {
action.execute(player)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.toasterofbread.spmp.model.appaction

import kotlinx.serialization.Serializable
import com.toasterofbread.spmp.service.playercontroller.PlayerState
import com.toasterofbread.spmp.model.state.OldPlayerStateImpl
import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.model.mediaitem.song.updateLiked
import com.toasterofbread.spmp.model.mediaitem.playlist.Playlist
Expand Down Expand Up @@ -69,7 +69,7 @@ data class SongAppAction(
action.CustomContent(onClick, song, modifier)
}

override suspend fun executeAction(player: PlayerState) {
override suspend fun executeAction(player: OldPlayerStateImpl) {
val song: Song = player.status.song ?: return
val index: Int = player.status.index
if (index < 0) {
Expand All @@ -92,7 +92,7 @@ data class SongAppAction(

@Composable
override fun ConfigurationItems(item_modifier: Modifier, onModification: (AppAction) -> Unit) {
val player: PlayerState = LocalPlayerState.current
val player: OldPlayerStateImpl = LocalPlayerState.current

var show_action_selector: Boolean by remember { mutableStateOf(false) }
val available_actions: List<Action> = remember { Action.getAvailable(player.context) }
Expand Down Expand Up @@ -224,7 +224,7 @@ data class SongAppAction(
else -> true
}

suspend fun execute(song: Song, queue_index: Int, player: PlayerState) {
suspend fun execute(song: Song, queue_index: Int, player: OldPlayerStateImpl) {
when (this) {
TOGGLE_LIKE -> {
val set_liked_endpoint: SetSongLikedEndpoint? = player.context.ytapi.user_auth_state?.SetSongLiked
Expand Down
Loading

0 comments on commit a8792d3

Please sign in to comment.