Skip to content

Commit 14878a7

Browse files
committedAug 2, 2024
Use SERVER_LOCAL_START_AUTOMATICALLY, hide ENABLE_EXTERNAL_SERVER_MODE on desktop
1 parent d8b056f commit 14878a7

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed
 

‎shared/src/commonMain/kotlin/com/toasterofbread/spmp/service/playercontroller/PlayerState.kt

+12-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,18 @@ class PlayerState(
222222
}
223223
}
224224

225-
private fun getServiceCompanion(): PlayerServiceCompanion =
226-
if (!PlatformInternalPlayerService.isServiceAttached(context) && (!PlatformInternalPlayerService.isAvailable(context, launch_arguments) || settings.platform.ENABLE_EXTERNAL_SERVER_MODE.get()))
227-
PlatformExternalPlayerService
228-
else PlatformInternalPlayerService
225+
private fun getServiceCompanion(): PlayerServiceCompanion {
226+
if (!PlatformInternalPlayerService.isAvailable(context, launch_arguments)) {
227+
return PlatformExternalPlayerService
228+
}
229+
if (PlatformInternalPlayerService.isServiceAttached(context)) {
230+
return PlatformInternalPlayerService
231+
}
232+
if (settings.platform.ENABLE_EXTERNAL_SERVER_MODE.get()) {
233+
return PlatformExternalPlayerService
234+
}
235+
return PlatformInternalPlayerService
236+
}
229237

230238
fun onStart() {
231239
SpMp.addLowMemoryListener(low_memory_listener)

‎shared/src/commonMain/kotlin/com/toasterofbread/spmp/ui/layout/apppage/settingspage/category/PlatformCategory.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fun getServerGroupItems(context: AppContext): List<SettingsItem> {
9595
getSubtitleOverride = {
9696
getLocalServerUnavailabilityReason()
9797
}
98-
),
98+
).takeIf { !Platform.DESKTOP.isCurrent() },
9999

100100
ToggleSettingsItem(context.settings.platform.EXTERNAL_SERVER_MODE_UI_ONLY).takeIf { PlatformExternalPlayerService.playsAudio() },
101101

‎shared/src/desktopMain/kotlin/com/toasterofbread/spmp/platform/playerservice/PlatformInternalPlayerService.desktop.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package com.toasterofbread.spmp.platform.playerservice
33
import ProgramArguments
44
import com.toasterofbread.spmp.platform.AppContext
55
import com.toasterofbread.spmp.platform.PlatformBinder
6-
import dev.toastbits.composekit.platform.PlatformFile
76
import dev.toastbits.spms.server.SpMs
87

98
private class PlayerServiceBinder(val service: PlatformInternalPlayerService): PlatformBinder()
109

1110
actual class PlatformInternalPlayerService: ExternalPlayerService(plays_audio = false) {
12-
private fun launchLocalServer() {
13-
LocalServer.startLocalServer(
14-
context,
15-
context.settings.platform.SERVER_PORT.get()
16-
)
11+
private fun autoLaunchLocalServer() {
12+
if (context.settings.platform.SERVER_LOCAL_START_AUTOMATICALLY.get()) {
13+
LocalServer.startLocalServer(
14+
context,
15+
context.settings.platform.SERVER_PORT.get()
16+
)
17+
}
1718
}
1819

1920
actual companion object: PlayerServiceCompanion {
@@ -36,12 +37,12 @@ actual class PlatformInternalPlayerService: ExternalPlayerService(plays_audio =
3637
if (instance != null)
3738
instance.also {
3839
it.setContext(context)
39-
it.launchLocalServer()
40+
it.autoLaunchLocalServer()
4041
}
4142
else
4243
PlatformInternalPlayerService().also {
4344
it.setContext(context)
44-
it.launchLocalServer()
45+
it.autoLaunchLocalServer()
4546
it.onCreate()
4647
}
4748
onConnected(service)

0 commit comments

Comments
 (0)