Wavesonics / compose-multiplatform-file-picker

A multiplatform compose widget for picking files
MIT License
347 stars 20 forks source link

on macOS cannot choose json file #43

Open tangshimin opened 1 year ago

tangshimin commented 1 year ago

version: v2.0.2 operating system: macOS Monterey v12.6.1 JDK: IBM OpenJ9, version: 17.0.8

demo:

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.darkrockstudios.libraries.mpfilepicker.FilePicker

fun main() = application {
    var show1 by remember { mutableStateOf(false) }
    var show2 by remember { mutableStateOf(false) }
    var pathChosen1 by remember { mutableStateOf("") }
    var pathChosen2 by remember { mutableStateOf("") }

    Window(onCloseRequest = ::exitApplication) {
        Column {
            Button(onClick = {
                show1 = true
            }) {
                Text("Choose File 1")
            }
            Text("File Chosen 1: $pathChosen1")

            /////////////////////////////////////////////////////////////////
            Button(onClick = {
                show2 = true
            }) {
                Text("Choose File 2")
            }
            Text("File Chosen 2: $pathChosen2")

        }

        // if set one json file extension, cannot choose json files
        FilePicker(show1, fileExtensions = listOf("json")) { file ->
            pathChosen1 = file?.path ?: "none selected"
            show1 = false
        }
        // if set multiple file extensions, can choose json files
        FilePicker(show2, fileExtensions = listOf("json", "txt")) { file ->
            pathChosen2 = file?.path ?: "none selected"
            show2 = false
        }
    }

}
shalva97 commented 1 year ago

It is a JVM variant, right?

tangshimin commented 1 year ago

yes, I use IBM OpenJ9, version: 17.0.8

tangshimin commented 1 year ago



If the fileExtensions is set to json and another arbitrary file extension, it seems that you can choose any type of file



        FilePicker(show2, fileExtensions = listOf("json", "txt")) { file ->
            pathChosen2 = file?.path ?: "none selected"
            show2 = false
        }



shalva97 commented 1 year ago

okay, I have asked it here https://github.com/LWJGL/lwjgl3/issues/921, now we wait for them

naijun0403 commented 9 months ago

These issues seem to apply to TOML files as well, not just JSON.