rfd icon indicating copy to clipboard operation
rfd copied to clipboard

macOS AsyncFileDialog with no windows?

Open probablykasper opened this issue 2 years ago • 3 comments

Unless I'm missing something, async seems to not be possible if an app has no windows. Is that intentional?

https://github.com/PolyMeilex/rfd/blob/73d9e3f75298974ba7197c3ad28615e9a5542c41/src/backend/macos/modal_future.rs#L67-L69

probablykasper avatar Feb 23 '23 11:02 probablykasper

As far as I remember there is no async equivalent of runmodal so that's the reason.

Also, if you don't have a window there is high chance that you don't have https://developer.apple.com/documentation/appkit/nsapplication (usually started by winit or sdl) running in your process, so there is no event loop one could attach to, and no way to do anything asynchronously. (all cocoa functions internally have if thread != main { panic!() }, so moving stuff to different thread is not an option)

TLDR: It's a mess

PolyMeilex avatar Feb 23 '23 12:02 PolyMeilex

Alright, thanks for clarifying. The reason I opened the issue is because someone opened an issue related to this with Tauri: https://github.com/tauri-apps/tauri/issues/6301. I think in that case the event loop does exist, but with no windows, so they're getting this error:

Hi! It looks like you are running async dialog in unsupported environment, I will fallback to sync dialog for you.

thread '<unnamed>' panicked at 'Fallback Sync Dialog Must Be Spawned On Main Thread (Why? If async dialog is unsupported in this env, it also means that spawning dialogs outside of main thread is also inpossible', /Users/rpatterson/.cargo/registry/src/github.com-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/modal_future.rs:115:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', /Users/rpatterson/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-1.2.2/src/api/dialog.rs:250:22
libc++abi: terminating with uncaught foreign exception

probablykasper avatar Feb 23 '23 19:02 probablykasper

Yeah if that's the case it should be possible to fix, new if branch would be needed for app running but without window, it would still be sync dialog, but we should be able to queue it to run on main thread.

PolyMeilex avatar Feb 23 '23 20:02 PolyMeilex