Skip to content

Fix file open (ADD) button not opening file picker in Safari#5

Open
lxpollitt wants to merge 1 commit intolanceewing:masterfrom
lxpollitt:fix/safari-file-picker
Open

Fix file open (ADD) button not opening file picker in Safari#5
lxpollitt wants to merge 1 commit intolanceewing:masterfrom
lxpollitt:fix/safari-file-picker

Conversation

@lxpollitt
Copy link
Copy Markdown

Safari enforces the "user activation" rule for opening native file pickers more strictly than Chrome: .click() on an
<input type="file"> must run in the same synchronous event stack as the user-gesture event. HomeScreen.importProgram() was wrapping the call in Gdx.app.postRunnable(...), which defers by one frame - long enough for Safari to revoke the token and silently refuse the picker.

Calling synchronously is safe on all three platforms because each DialogHandler.openFileDialog implementation handles its own thread affinity internally (Desktop wraps for Swing, Android uses runOnUiThread, GWT runs synchronously).

Testing

  • Safari 18 on macOS - ADD button now opens the picker.
  • Chrome on macOS - still works, no regression.
  • Desktop / Android - not tested but should be no behavioural change (each platform's dialog handler retains its own thread wrapping).

Safari enforces the "user activation" rule for opening native file
pickers more strictly than Chrome: .click() on an <input type="file">
must run in the same synchronous event stack as the user-gesture
event. HomeScreen.importProgram() was wrapping the call in
Gdx.app.postRunnable(...), which defers by one frame — long enough
for Safari to revoke the token and silently refuse the picker.
Calling synchronously is safe on all three platforms because each
DialogHandler.openFileDialog implementation handles its own thread
affinity internally (Desktop wraps for Swing, Android uses
runOnUiThread, GWT runs synchronously).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant