dialog.js 841 B

12345678910111213141516171819202122232425262728
  1. const {dialog} = require('electron');
  2. const obj = {};
  3. obj.messagePromise = function(title, content, type = '', buttons = ['Ok'], defaultButton = 0, attach = true) {
  4. const opts = {
  5. type: type,
  6. title: title,
  7. message: content,
  8. buttons: buttons,
  9. defaultId: defaultButton
  10. };
  11. if (attach) {
  12. return dialog.showMessageBox(mainWindow, opts);
  13. } else {
  14. return dialog.showMessageBox(opts);
  15. }
  16. }
  17. obj.message = function(title, content, type = 'info', buttons = ['Ok'], defaultButton = 0, attach = true, callback = null) {
  18. const promise = obj.messagePromise(title, content, type, buttons, defaultButton, attach);
  19. if (callback !== null) {
  20. promise.then(data => {
  21. callback(data.response, buttons[data.response]);
  22. });
  23. }
  24. }
  25. module.exports = obj;