tauri/cli/tauri.js/api-src/dialog.ts
Oleg Shilov 0a5bac1dd6
fix(tauri.js): fix typings for open and save dialogs (#926)
* fix(tauri.js): fix typings for open and save dialogs

add JSDoc types;

* chore(tauri.js): add changelog
2020-08-07 19:54:17 -05:00

58 lines
1.3 KiB
TypeScript

import { promisified } from './tauri'
export interface OpenDialogOptions {
filter?: string
defaultPath?: string
multiple?: boolean
directory?: boolean
}
export type SaveDialogOptions = Pick<OpenDialogOptions, 'filter' | 'defaultPath'>
/**
* @name openDialog
* @description Open a file/directory selection dialog
* @param {Object} [options]
* @param {string} [options.filter]
* @param {string} [options.defaultPath]
* @param {boolean} [options.multiple=false]
* @param {boolean} [options.directory=false]
* @returns {Promise<string | string[]>} Promise resolving to the select path(s)
*/
async function open(
options: OpenDialogOptions = {}
): Promise<string | string[]> {
if (typeof options === 'object') {
Object.freeze(options)
}
return await promisified({
cmd: 'openDialog',
options
})
}
/**
* @name save
* @description Open a file/directory save dialog
* @param {Object} [options]
* @param {string} [options.filter]
* @param {string} [options.defaultPath]
* @returns {Promise<string>} Promise resolving to the select path
*/
async function save(options: SaveDialogOptions = {}): Promise<string> {
if (typeof options === 'object') {
Object.freeze(options)
}
return await promisified({
cmd: 'saveDialog',
options
})
}
export {
open,
save
}