Global

Members

DialogBoxResult :Readonly.<{CANCEL: 0, OK: 1, YES: 1, NO: 2}>

This object contains all the values that can be returned by dialogBox(), where the keys are the names of the buttons (`YES`, `CANCEL`, etc.).
You can use it to compare the result (e.g. if (result === DialogBoxResult.YES) { ... })
Source:
Type:
  • Readonly.<{CANCEL: 0, OK: 1, YES: 1, NO: 2}>

config :Config

An object that contains the entire configuration of the library.
Source:
Type:

Methods

(async) dialogBox(opts) → {Promise.<DialogBoxValue>}

Open a dialog box.
Source:
Parameters:
Name Type Description
opts Object
Name Type Attributes Default Description
title string <optional>
"message" The title of the popup
message string <optional>
"message" The message of the popup
dialogType "ok" | "okCancel" | "yesNo" | "yesNoCancel" | "" <optional>
"ok" The dialog type of the popup
iconType "info" | "warning" | "error" | "question" | "" <optional>
"info" The icon and sound types of the popup
defaultSelected "ok" | "cancel" | "yes" | "no" | 0 <optional>
"ok" The default selected button of the popup
Returns:
Type:
Promise.<DialogBoxValue>
A Promise representing the selected button number: 0 = Cancel, 1 = OK or Yes, 3 = No
Example
// With asynchronous method
messageBox({
    title: 'Shutdown',
    message: 'Do you want to continue?',
    dialogType: 'yesNo',
    defaultSelected: 'no'
}).then(data => console.log(data)) // E.g. 1 if the user clicked Yes

// With synchronous method 
(async () => {
    const data = await messageBox({
        title: 'Shutdown',
        message: 'Do you want to continue?',
        dialogType: 'yesNo',
        defaultSelected: 'no'
    })
    console.log(data) // E.g. 1 if the user clicked Yes
})

(async) messageBox(opts) → {Promise.<(0|1|2)>}

Open a dialog box.
Deprecated:
Source:
Parameters:
Name Type Description
opts Object
Name Type Attributes Default Description
title string <optional>
"message" The title of the popup
message string <optional>
"message" The message of the popup
dialogType "ok" | "okCancel" | "yesNo" | "yesNoCancel" | "" <optional>
"ok" The dialog type of the popup
iconType "info" | "warning" | "error" | "question" | "" <optional>
"info" The icon and sound types of the popup
defaultSelected "ok" | "cancel" | "yes" | "no" | 0 <optional>
"ok" The default selected button of the popup
Returns:
Type:
Promise.<(0|1|2)>
A Promise representing the selected button number:
012
"ok"Ok
"okCancel"CancelOk
"yesNo"NoYes
"yesNoCancel"CancelYesNo
Example
// With asynchronous method
messageBox({
    title: 'Shutdown',
    message: 'Do you want to continue?',
    dialogType: 'yesNo',
    defaultSelected: 'no'
}).then(data => console.log(data)) // E.g. 1 if the user clicked Yes

// With synchronous method 
(async () => {
    const data = await messageBox({
        title: 'Shutdown',
        message: 'Do you want to continue?',
        dialogType: 'yesNo',
        defaultSelected: 'no'
    })
    console.log(data) // E.g. 1 if the user clicked Yes
})

(async) openDirectory(optsopt) → {Promise.<string>}

Open an "Open directory" window.
Source:
Parameters:
Name Type Attributes Description
opts Object <optional>
The options of the window.
Name Type Attributes Default Description
title string <optional>
"message" The title of the popup.
Throws:
If the user didn't select any directory.
Type
NoSelectedDirectoryError
Returns:
Type:
Promise.<string>
A Promise representing the path to the selected directory. For example, "C:\\Users\\user\\Desktop\\"
Example
// With asynchronous method
openDirectory({
    title: 'Open a directory',
}).then(data => console.log(data)) // E.g. C:\Users\user\Desktop\

// With synchronous method 
(async () => {
    const data = await openDirectory({
        title: 'Open a directory',
    })

    console.log(data) // E.g. C:\Users\user\Desktop\
})

(async) openFile(optsopt) → {Promise.<Array.<string>>}

Open an "Open file" window.
Source:
Parameters:
Name Type Attributes Description
opts Object <optional>
The options of the window.
Name Type Attributes Default Description
title string <optional>
"open" The title of the popup
startPath string <optional>
"./" The start path of the popup
filterPatterns Array.<string> <optional>
["*"] The filter patterns of the popup. For example, ["*.exe", "*.txt"]
filterPatternsDescription string <optional>
"" The filter patterns description of the popup, separated by commas; for example, "Executable files,Text files"
allowMultipleSelects boolean | number <optional>
false The boolean that define if the window allow multiple selects of files
Throws:
If the user didn't select any file.
Type
NoSelectedFileError
Returns:
Type:
Promise.<Array.<string>>
A promise representing an array that contains the paths to the selected files. For example, ["C:\\Users\\user\\Desktop\\file.exe"]
Example
// With asynchronous method
openFile({
    title: 'Open several files',
    filterPatterns: ["*.txt"],
    allowMultipleSelects: true
}).then(data => console.log(data.join(', '))) // E.g. C:\Users\user\Desktop\file.txt, C:\Users\user\Desktop\other-file.txt

// With synchronous method 
(async () => {
    const data = await openFile({
        title: 'Open several files',
        filterPatterns: ["*.txt"],
        allowMultipleSelects: true
    })

    console.log(data.join(', ')) // E.g. C:\Users\user\Desktop\file.txt, C:\Users\user\Desktop\other-file.txt
})

(async) saveFile(opts) → {Promise.<string>}

Open a "Save file" window.
Source:
Parameters:
Name Type Description
opts Object The options of the window.
Name Type Attributes Default Description
title string <optional>
"save" The title of the popup.
startPath string <optional>
"./default.txt" The start path of the popup and the saved file name
filterPatterns Array.<string> <optional>
["*"] The filter patterns of the popup. For example, ["*.exe", "*.txt"]
filterPatternsDescription string <optional>
"" The filter patterns description of the popup, separated by commas; for example, "Executable files,Text files"
Throws:
If the user cancelled and didn't select any file to save in.
Type
NoSavedFileError
Returns:
Type:
Promise.<string>
A Promise representing the path to the saved file. Example: "C:\\Users\\user\\Desktop\\default.txt"
Example
// With asynchronous method
saveFile({
    title: 'Save into a file',
    filterPatterns: ["*.txt"],
    allowMultipleSelects: true
}).then(data => console.log(data)) // E.g. C:\Users\user\Desktop\default.txt

// With synchronous method 
(async () => {
    const data = await saveFile({
        title: 'Save into a file',
        filterPatterns: ["*.txt"],
        allowMultipleSelects: true
    })

    console.log(data) // E.g. C:\Users\user\Desktop\default.txt
})

Type Definitions

AvailableCommandItem

Properties:
Name Type Description
name string The name of the command. This is used by all library methods to invoke the executable that opens the popups.
flags AvailableCommandItemFlags The differents flags of the command.
Source:
Type:
  • Object

AvailableCommandItemFlags

Properties:
Name Type Attributes Description
title AvailableCommandItemFlagsItem The title of the popup.
message AvailableCommandItemFlagsItem <optional>
The message written in the popup.
dialogType AvailableCommandItemFlagsItem <optional>
The type of message box.
startPath AvailableCommandItemFlagsItem <optional>
The path to the folder where the popup will be opened.
filterPatterns AvailableCommandItemFlagsItem <optional>
The pattern used to filter the files.
filterPatternsDescription AvailableCommandItemFlagsItem <optional>
The description of the filter patterns, wiewed by the user.
allowMultipleSelects AvailableCommandItemFlagsItem <optional>
The value that defines if the user can select several files.
iconType AvailableCommandItemFlagsItem <optional>
The type of icon (and sound) of the message box.
defaultSelected AvailableCommandItemFlagsDefaultDelected <optional>
The button that is selected by default in the message box.
Source:
Type:
  • Object

AvailableCommandItemFlagsDefaultDelected

Properties:
Name Type Attributes Description
name string The name of the flag. For exemple, --title.
typesMapper Object.<string, number> <optional>
An object that contains all the possible values of the flag.
default number The default value.
Source:
Type:
  • Object

AvailableCommandItemFlagsItem

Properties:
Name Type Attributes Description
name string The name of the flag. For exemple, --title.
defaultValue string The default value.
typesMapper Object.<string, string> <optional>
An object that contains all the possible values of the flag.
types Array.<string> <optional>
An array that contains all the possible values of the flag.
Source:
Type:
  • Object

Config

Properties:
Name Type Description
vendorPath string The path to the library executable. It is set according to the operating system.
availableCommand Object The available commands and their attributes.
Properties
Name Type Description
openFile AvailableCommandItem The open file command and its attributes.
saveFile AvailableCommandItem The save file command and its attributes.
openDirectory AvailableCommandItem The open directory command and its attributes.
messageBox AvailableCommandItem The message box command and its attributes.
Source:
Type:
  • Object

DialogBoxValue

Source:
Type:
  • 0 | 1 | 2