dialog
Native file pickers and message boxes, backed by the dialog module.
import { dialog } from '@owear/core'
showOpenDialog
dialog.showOpenDialog(options?: OpenDialogOptions)
: Promise<{ canceled: boolean; filePaths: string[] }>
interface OpenDialogOptions {
title?: string
defaultPath?: string
buttonLabel?: string
filters?: { name: string; extensions: string[] }[]
properties?: Array<
'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory'
>
}
showSaveDialog
dialog.showSaveDialog(options?: SaveDialogOptions)
: Promise<{ canceled: boolean; filePath: string }>
interface SaveDialogOptions {
title?: string
defaultPath?: string
buttonLabel?: string
filters?: { name: string; extensions: string[] }[]
}
showMessageBox
dialog.showMessageBox(options: MessageBoxOptions)
: Promise<{ response: number; checkboxChecked: boolean }>
interface MessageBoxOptions {
type?: 'none' | 'info' | 'error' | 'question' | 'warning'
title?: string
message: string
detail?: string
buttons?: string[]
defaultId?: number
cancelId?: number
checkboxLabel?: string
}
response is the index of the pressed button. checkboxChecked reflects the
optional checkbox.
Example
const { canceled, filePaths } = await dialog.showOpenDialog({
title: 'Open',
properties: ['openFile', 'multiSelections'],
filters: [{ name: 'Markdown', extensions: ['md'] }],
})
const { response } = await dialog.showMessageBox({
type: 'question',
message: 'Save changes?',
buttons: ['Save', 'Discard', 'Cancel'],
defaultId: 0,
cancelId: 2,
})
Notes
- Implemented by the native
dialogmodule; on Linux these are GTK dialogs and cannot be automated in CI. OpenDialogOptions.propertiesmaps to file/folder selection and hidden-file visibility.