tauri/cli/tauri.js/api-src/dialog.ts
nothingismagick 2681ad361b
refactor(tauri.js) rewrite API module in TypeScript, closes #679 #435 (#703)
Co-authored-by: Quentin Goinaud <armaldio@gmail.com>
Co-authored-by: Lucas Fernandes Nogueira <lucasfernandesnog@gmail.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
2020-06-27 12:20:00 -03:00

48 lines
1.0 KiB
TypeScript

import { OpenDialogOptions, SaveDialogOptions } from './types/dialog'
import { promisified } from './tauri'
/**
* @name openDialog
* @description Open a file/directory selection dialog
* @param [options]
* @param [options.filter]
* @param [options.defaultPath]
* @param [options.multiple=false]
* @param [options.directory=false]
* @returns 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 [options]
* @param [options.filter]
* @param [options.defaultPath]
* @returns 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
}