Skip to content

fix: use showSaveFilePicker for state export with browser fallback#83

Merged
jourdain merged 1 commit intoKitware:masterfrom
patrickoleary:fix/state-export
May 1, 2026
Merged

fix: use showSaveFilePicker for state export with browser fallback#83
jourdain merged 1 commit intoKitware:masterfrom
patrickoleary:fix/state-export

Conversation

@patrickoleary
Copy link
Copy Markdown
Member

@patrickoleary patrickoleary commented May 1, 2026

Improve state file export to use the native save-as dialog when available in the browser.

Note: This fix does not allow for the user to enter a path instead of just a filename. browser technology has file system access restrictions. We still ask for just a filename here. So, there are are three cases:

  • Tauri - Enter a filename and description, then Tauri presents a dialog is presented for selecting the save location.
  • Modern Browser (Chrome/Edge with HTTPS or localhost) - Enter a filename and description, then 'showSaveFilePicker' presents a dialog is presented for selecting the save location.
  • Browser (Not Modern [Firefox/Safari] or remote HTTP) - Enter a filename and description, then the browser saves to ~/Downloads only.

What we changed:

  • Rename "Download" to "Save" throughout the state export UI (dialog title, button, menu item)
  • showSaveFilePicker API (Chrome/Edge on secure contexts) — users get a native save-as dialog to choose location
  • Fallback to utils.download for Firefox/Safari or non-secure contexts — saves to ~/Downloads
  • Filename hint added: "Name only — save location is chosen via dialog or defaults to ~/Downloads"
  • Menu item simplified: always says "Save state file" (no longer conditional on Tauri)

Fallback chain:

  • Tauri → native OS save dialog (unchanged)
  • Browser (Chrome/Edge, localhost/HTTPS) → showSaveFilePicker
  • Browser (Firefox/Safari or remote HTTP) → utils.download to ~/Downloads

Remote host access:
The showSaveFilePicker API requires a secure context. When accessing QuickView remotely over plain http://, the native save dialog will not be available and the fallback browser download is used instead. To enable the full save-as experience for remote users:

  • SSH tunnel — ssh -L 8080:localhost:8080 remote-host — browser sees localhost, secure context satisfied
  • CapRover — auto-provisions HTTPS/WSS trame cloud docs

closes #78

utils.download(fname, content, 'application/json');
});
}
""",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While valid I would rather capture that JS code inside here and make the click just click="utils.quickview.exportDownload(download_name)"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In JS, you have access to trame but to change state variable, you will need to do window.trame.state.set("show_export_dialog", false).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the utils are available under window.trame.utils.

@jourdain jourdain merged commit d1c2d6d into Kitware:master May 1, 2026
1 check passed
@jourdain
Copy link
Copy Markdown
Collaborator

jourdain commented May 1, 2026

I'll do a small cleanup in another push

@jourdain
Copy link
Copy Markdown
Collaborator

jourdain commented May 1, 2026

Done it here

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.

State file download: allow user to specify path

3 participants