Skip to content

Commit 2cb4736

Browse files
committed
fixed a bug that would cause FS access via gluon attach on embedded devices
1 parent daf4fba commit 2cb4736

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

fxgl-core/src/main/kotlin/com/almasb/fxgl/core/util/Platform.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ enum class Platform {
2121
val isDesktop: Boolean
2222
get() = this === WINDOWS || this === MAC || this === LINUX
2323

24+
val isEmbedded: Boolean
25+
get() = this === EMBEDDED
26+
2427
companion object {
2528
@JvmStatic fun get(): Platform {
2629
// check if running on mobile first

fxgl-io/src/main/kotlin/com/almasb/fxgl/io/FileSystemService.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ class FileSystemService : EngineService() {
2626

2727
private val log = Logger.get(javaClass)
2828

29-
@Inject("isDesktop")
30-
private var isDesktop = true
29+
@Inject("isMobile")
30+
private var isMobile = false
3131

3232
@Inject("isFileSystemWriteAllowed")
3333
private var isFileSystemWriteAllowed = true
3434

3535
private lateinit var fs: FileSystemAccess
3636

3737
override fun onInit() {
38-
val rootStorage = if (isDesktop)
38+
val rootStorage = if (!isMobile)
3939
File(System.getProperty("user.dir") + "/")
4040
else
4141
StorageService.create()

fxgl-io/src/test/kotlin/com/almasb/fxgl/io/FileSystemServiceTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class FileSystemServiceTest {
4949

5050
fs = FileSystemService()
5151
val injectMap = mapOf(
52-
"isDesktop" to true,
52+
"isMobile" to false,
5353
"isFileSystemWriteAllowed" to true)
5454

5555
InjectInTest.inject(MethodHandles.lookup(), fs, injectMap)
@@ -237,7 +237,7 @@ class FileSystemServiceTest {
237237
fun `Fail on mobile if no private storage present`() {
238238
val f = FileSystemService()
239239
val injectMap = mapOf(
240-
"isDesktop" to false,
240+
"isMobile" to true,
241241
"isFileSystemWriteAllowed" to true)
242242

243243
InjectInTest.inject(MethodHandles.lookup(), f, injectMap)
@@ -251,7 +251,7 @@ class FileSystemServiceTest {
251251
fun `FS is not changed if FS write is not allowed`() {
252252
val f = FileSystemService()
253253
val injectMap = mapOf(
254-
"isDesktop" to true,
254+
"isMobile" to false,
255255
"isFileSystemWriteAllowed" to false)
256256

257257
InjectInTest.inject(MethodHandles.lookup(), f, injectMap)

fxgl/src/main/kotlin/com/almasb/fxgl/app/Settings.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,9 @@ class ReadOnlyGameSettings internal constructor(
653653
val isMobile: Boolean
654654
get() = platform.isMobile
655655

656+
val isEmbedded: Boolean
657+
get() = platform.isEmbedded
658+
656659
val isBrowser: Boolean
657660
get() = platform.isBrowser
658661

0 commit comments

Comments
 (0)