Members
DialogBoxResult :Readonly.<{CANCEL: 0, OK: 1, YES: 1, NO: 2}>
This object contains all the values that can be returned by
You can use it to compare the result (e.g.
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}>
Methods
(async) dialogBox(opts) → {Promise.<DialogBoxValue>}
Open a dialog box.
- Source:
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object
|
|
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:
- Use
dialogBox()
instead.
- Use
- Source:
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object
|
|
Returns:
- Type:
-
Promise.<(0|1|2)>
A Promise representing the selected button number:
0 | 1 | 2 | |
"ok" | Ok | ||
"okCancel" | Cancel | Ok | |
"yesNo" | No | Yes | |
"yesNoCancel" | Cancel | Yes | 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) openDirectory(optsopt) → {Promise.<string>}
Open an "Open directory" window.
- Source:
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object
|
<optional> |
The options of the window.
|
Throws:
-
If the user didn't select any directory.
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.
|
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.
|
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
|
- Source:
Type:
-
Object