Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not pick files on MacOS with tinyfd_openFileDialog when setting a filter #921

Open
shalva97 opened this issue Sep 6, 2023 · 3 comments

Comments

@shalva97
Copy link

shalva97 commented Sep 6, 2023

Question

I'am calling tinyfd_openFileDialog like this:

    val fileExtension = "json"

    val result = MemoryStack.stackPush().use { stack ->
        val filters = if (fileExtension.isNotEmpty()) fileExtension.split(",") else emptyList()
        val aFilterPatterns = stack.mallocPointer(filters.size)
        filters.forEach {
            aFilterPatterns.put(stack.UTF8("*.$it"))
        }
        aFilterPatterns.flip()
        TinyFileDialogs.tinyfd_openFileDialog(
            "Choose File",
            null,
            aFilterPatterns,
            null,
            false
        )
    }

It works on Windows and sets correct filter, but on MacOS it does not let me pick any file. My expectation is that on MacOS I should be able to pick .json files. Here is the project to reproduce the issue https://github.com/shalva97/lwjgl-bug, to run it, press green button next to main function.

Screenshot 2023-09-06 at 22 53 24

@Spasi
Copy link
Member

Spasi commented Sep 15, 2023

Hey @shalva97,

I can reproduce this. It seems that this is a quirk of AppleScript, which tinyfd uses internally to create the file dialog. The fix is to use public.json instead of json, i.e. "*.public.json" as a tinyfd filter pattern. (reference, but without a good explanation)

Alternatively, you could try switching to nativefiledialog (the lwjgl-nfd module). It uses NSOpenPanel internally and doesn't have this issue.

@shalva97
Copy link
Author

Writting "*.public.json" did work. But now the question is how do I make it work on all platforms? Do I check if app is run on Windows or MacOS and prefix public to the filter? also what other extensions need prefixes?

Alternatively, you could try switching to nativefiledialog

when I started to contribute to https://github.com/Wavesonics/compose-multiplatform-file-picker it initially used lwjgl-nfd but it crashes on MacOS with NSInternalInconsistencyException. Here is the issue still open. After some time I decided to switch to tinyfd.

@Spasi
Copy link
Member

Spasi commented Sep 15, 2023

Do I check if app is run on Windows or MacOS and prefix public to the filter?

Yes, you could test Platform.get().

also what other extensions need prefixes?

I'm not sure why it acts this way with json. I tried other known (to macOS) file types and they seemed to work fine, I didn't have to use the corresponding uniform type identifier.

the issue still open.

Yeah, if we're talking interaction with AWT/Swing... I can't provide support for the mess that is. We have a solution for GLFW (glfw-async), I guess nfd would have to work like that too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants