2021-02-09 21:22:04 +03:00
|
|
|
import { promisified } from './tauri'
|
2020-06-27 18:20:00 +03:00
|
|
|
|
2020-07-13 01:34:44 +03:00
|
|
|
export interface OpenDialogOptions {
|
2021-02-09 21:22:04 +03:00
|
|
|
filter?: string
|
|
|
|
defaultPath?: string
|
|
|
|
multiple?: boolean
|
|
|
|
directory?: boolean
|
2020-07-13 01:34:44 +03:00
|
|
|
}
|
|
|
|
|
2020-08-19 05:36:46 +03:00
|
|
|
export type SaveDialogOptions = Pick<
|
|
|
|
OpenDialogOptions,
|
2021-02-09 21:22:04 +03:00
|
|
|
'filter' | 'defaultPath'
|
|
|
|
>
|
2020-07-13 01:34:44 +03:00
|
|
|
|
2020-06-27 18:20:00 +03:00
|
|
|
/**
|
|
|
|
* @name openDialog
|
|
|
|
* @description Open a file/directory selection dialog
|
2020-08-08 03:54:17 +03:00
|
|
|
* @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)
|
2020-06-27 18:20:00 +03:00
|
|
|
*/
|
2020-08-08 03:54:17 +03:00
|
|
|
async function open(
|
|
|
|
options: OpenDialogOptions = {}
|
|
|
|
): Promise<string | string[]> {
|
2021-02-09 21:22:04 +03:00
|
|
|
if (typeof options === 'object') {
|
|
|
|
Object.freeze(options)
|
2020-06-27 18:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return await promisified({
|
2021-02-09 21:22:04 +03:00
|
|
|
cmd: 'openDialog',
|
|
|
|
options
|
|
|
|
})
|
2020-06-27 18:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name save
|
|
|
|
* @description Open a file/directory save dialog
|
2020-08-08 03:54:17 +03:00
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {string} [options.filter]
|
|
|
|
* @param {string} [options.defaultPath]
|
|
|
|
* @returns {Promise<string>} Promise resolving to the select path
|
2020-06-27 18:20:00 +03:00
|
|
|
*/
|
2020-08-08 03:54:17 +03:00
|
|
|
async function save(options: SaveDialogOptions = {}): Promise<string> {
|
2021-02-09 21:22:04 +03:00
|
|
|
if (typeof options === 'object') {
|
|
|
|
Object.freeze(options)
|
2020-06-27 18:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return await promisified({
|
2021-02-09 21:22:04 +03:00
|
|
|
cmd: 'saveDialog',
|
|
|
|
options
|
|
|
|
})
|
2020-06-27 18:20:00 +03:00
|
|
|
}
|
|
|
|
|
2021-02-09 21:22:04 +03:00
|
|
|
export { open, save }
|