dialog.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { OpenDialogOptions, SaveDialogOptions } from './types/dialog'
  2. import { promisified } from './tauri'
  3. /**
  4. * @name openDialog
  5. * @description Open a file/directory selection dialog
  6. * @param [options]
  7. * @param [options.filter]
  8. * @param [options.defaultPath]
  9. * @param [options.multiple=false]
  10. * @param [options.directory=false]
  11. * @returns promise resolving to the select path(s)
  12. */
  13. async function open(options: OpenDialogOptions = {}): Promise<String | String[]> {
  14. if (typeof options === 'object') {
  15. Object.freeze(options)
  16. }
  17. return await promisified({
  18. cmd: 'openDialog',
  19. options
  20. })
  21. }
  22. /**
  23. * @name save
  24. * @description Open a file/directory save dialog
  25. * @param [options]
  26. * @param [options.filter]
  27. * @param [options.defaultPath]
  28. * @returns promise resolving to the select path
  29. */
  30. async function save(options: SaveDialogOptions = {}): Promise<String> {
  31. if (typeof options === 'object') {
  32. Object.freeze(options)
  33. }
  34. return await promisified({
  35. cmd: 'saveDialog',
  36. options
  37. })
  38. }
  39. export {
  40. open,
  41. save
  42. }