Package Exports
- electron-dialogs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (electron-dialogs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
electron-dialogs
A simple library that allows you to create dialogs like alert, confirm and prompt in Electron applications easily and quickly.
Basic Usage
Main codes
// Require main function from electron-dialogs
const { main } = require('electron-dialogs');
// Create an Electron window
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
});
// Set a file to be loaded by your window
win.loadFile('path/to/your/file.html');
// Set a window and a channel to electron-dialogs
main(win, 'dialogs-test');
Renderer codes
// Require electron-dialogs and pass the same channel you did on Main
const dialogs = require('electron-dialogs').renderer('dialogs-test');
//After that you can use the alert, confirm and promt functions.
//ALERT - You can use the alert function in the following ways
dialogs.alert({
title: 'My alert',
message: 'This is an alert from electron-dialogs.',
dismissText: 'OK'
}, () => {
console.log('Your alert is closed.');
});
await dialogs.alertSync({
title: 'My alert',
message: 'This is an alert from electron-dialogs.',
dismissText: 'OK'
});
console.log('Your alert is closed.');
//CONFIRM - - You can use the confirm function in the following ways
dialogs.confirm({
title: 'My confirm',
message: 'This is a confirm from electron-dialogs.',
confirmText: 'OK',
cancelText: 'Cancel'
}, (confirmed) => {
if(confirmed) doSomething();
});
const confirmed = await dialogs.confirmSync({
title: 'My confirm',
message: 'This is a confirm from electron-dialogs.',
confirmText: 'OK',
cancelText: 'Cancel'
});
if(confirmed) doSomething();
//PROMPT - You can use the prompt function in the following ways
dialogs.prompt({
title: 'My prompt',
message: 'This is a prompt from electron-dialogs.',
value: 'My prompt value',
confirmText: 'OK',
cancelText: 'Cancel'
}, (res) => {
if(!res.canceled) console.log(res.value);
});
const { canceled, value } = await dialogs.promptSync({
title: 'My confirm',
message: 'This is a confirm from electron-dialogs.',
value: 'My prompt value',
confirmText: 'OK',
cancelText: 'Cancel'
});
if(!canceled) console.log(value);
Nice coding! :)