Example #1
1
export const showError = (title, errMsg, next) => {
  remote.dialog.showMessageBox({
    type: 'error',
    buttons: ['Ok'],
    title,
    message: errMsg.toString()
  }, next ? next : _ => {});
};
Example #2
0
  confirm (options, callback) {
    if (typeof callback === 'function') {
      // Async version: pass options directly to Electron but set sane defaults
      options = Object.assign({type: 'info', normalizeAccessKeys: true}, options)
      remote.dialog.showMessageBox(remote.getCurrentWindow(), options, callback)
    } else {
      // Legacy sync version: options can only have `message`,
      // `detailedMessage` (optional), and buttons array or object (optional)
      let {message, detailedMessage, buttons} = options

      let buttonLabels
      if (!buttons) buttons = {}
      if (Array.isArray(buttons)) {
        buttonLabels = buttons
      } else {
        buttonLabels = Object.keys(buttons)
      }

      const chosen = remote.dialog.showMessageBox(remote.getCurrentWindow(), {
        type: 'info',
        message,
        detail: detailedMessage,
        buttons: buttonLabels,
        normalizeAccessKeys: true
      })

      if (Array.isArray(buttons)) {
        return chosen
      } else {
        const callback = buttons[buttonLabels[chosen]]
        if (typeof callback === 'function') return callback()
      }
    }
  }
Example #3
0
 login: function () {
     dialog.showMessageBox({
         title: 'test',
         message: this.username,
         buttons: [],
     });
 }
Example #4
0
exports.showOpenDialog = function () {
    const remote = require('electron').remote;
    var fs = require('fs')
    remote.dialog.showOpenDialog({ properties: [ 'openFile']}, function(fileNames) {
        console.log(fileNames);
        if(fileNames === undefined) return;
        var fileName = fileNames[0]
        fs.readFile(fileName, 'utf-8', function (err, data) {
            if(err) {
                return;
            }
            console.log(data);
            try {
                //global.setting = eval('('+data+')');
                global.setting = JSON.parse(data);
                //var controller = require('./controller');
                showXlsxList();
            }
            catch (err) {
                //console.log(err);
                //var dialog = require('./dialog');
                //dialog.showConfirmDialog('文件格式不正确', err);
                alert("配置文件格式不正确");
            }
            //document.write(global.setting);
        });
    });
}
Example #5
0
 return scheduler.nativeBinding(callback => {
   dialog.showOpenDialog({
     properties: ['openFile', 'multiSelections']
   }, (filenames) => {
     callback(scheduler.succeed(fromArray(filenames || [])))
   });
 });
Example #6
0
    doExport() {
        let exportImage = (path) => {
            let svg = document.querySelector('svg'), // Inline SVG element
                can = document.createElement('canvas'), // Not shown on page
                ctx = can.getContext('2d'),
                loader = new Image(); // Not shown on page

            let svgAsXML = (new XMLSerializer()).serializeToString(svg);
            let DOMURL = window.URL || window.webkitURL || window;
            let svgBlob = new Blob([svgAsXML], {type: 'image/svg+xml;charset=utf-8'});
            let url = DOMURL.createObjectURL(svgBlob);

            loader.width = can.width = svg.width.baseVal.value;
            loader.height = can.height = svg.height.baseVal.value;
            loader.onload = () => {
                ctx.drawImage(loader, 0, 0);

                let dataURL = can.toDataURL('image/png');
                let img = nativeImage.createFromDataURL(dataURL);

                this.saveImage(img.toPng(), path);
                this.saveVect(svgAsXML, path);
            };
            loader.src = url;
        };

        if (this.state.filePath) {
            exportImage(this.state.filePath);
        } else {
            dialog.showSaveDialog([], exportImage);
        }
    }
Example #7
0
export const openFileDialog = function () {
  dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
    properties: ['openFile']
  }, function (file) {
    if (file) openFile(file[0])
  })
}
Example #8
0
window.alert = function (message = '', title = '') {
  remote.dialog.showMessageBox(remote.getCurrentWindow(), {
    message: String(message),
    title: String(title),
    buttons: ['OK']
  })
}
Example #9
0
/*
 * Selects a file off the local filesystem and populates the given element with the selected filename.
 */
function pickFile(event, elementId) {
    event.preventDefault();
    let selected = dialog.showOpenDialog({ properties: [ 'openFile' ] });
    if (selected) {
        document.getElementById(elementId).value = selected;
    }
}
Example #10
0
    window.addEventListener("beforeunload", (evt) => {
        // Workaround for a bug in Electron where the window closes after a few
        // seconds even when calling dialog.showMessageBox() synchronously.
        if (closing) {
            return;
        }
        closing = true;
        evt.returnValue = false;

        this.removeListener("blur", onBlur);

        if (this.controller.getPreference("saveMode") === "onblur") {
            window.setTimeout(() => this.quit(true));
        }
        else if (this.hasOutdatedFiles()) {
            // If autosave is disabled and some files are outdated,
            // ask user confirmation.
            remote.dialog.showMessageBox(browserWindow, {
                type: "question",
                message: _("Do you want to save the presentation before closing?"),
                buttons: [_("Yes"), _("No")],
                defaultId: 0,
                cancelId: 1
            }, (index) => this.quit(index === 0));
        }
    });
          callback: function(e) {
            // Give ![] surround the selection and prepend the image link
            var chunk, cursor, selected = e.getSelection(),
              content = e.getContent(),
              link;

            if (selected.length === 0) {
              // Give extra word
              chunk = e.__localize('enter image description here');
            } else {
              chunk = selected.text;
            }
            const {dialog} = require('electron').remote;
            var linkList = dialog.showOpenDialog({
              properties: ['openFile'],
              filters: [
                {name: 'Images', extensions: ['jpg',' jpeg', 'png', 'gif']},
                {name: 'All Files', extensions: ['*']}
              ]
            });
            if (linkList != null && linkList.length > 0) {
              var link = e.$options.onInsertImage(e, linkList[0]);
              var sanitizedLink = $('<div>' + link + '</div>').text();

              // transform selection and set the cursor into chunked text
              e.replaceSelection('![' + chunk + '](' + sanitizedLink + ' "' + e.__localize('enter image title here') + '")');
              cursor = selected.start + 2;

              // Set the next tab
              e.setNextTab(e.__localize('enter image title here'));

              // Set the cursor
              e.setSelection(cursor, cursor + chunk.length);
            }
          }
Example #12
0
function saveFile () {
  dialog.showSaveDialog(function (fileName) {
    if (fileName === undefined) return;
    fs.writeFile(fileName, currentSvg, function (err) {
      if (err) console.error(err)
    })
  })
}
Example #13
0
    exec(command, (error, stdout, stderr) => {
      if (error) {
        remote.dialog.showErrorBox('Error [003]', `${lang.alerts.error_003} ${folder}\n${stderr}`);
        return;
      }

      readAllFiles(stdout.trim().split('\n'));
    });
Example #14
0
export const showSuccess = (title, message) => {
  remote.dialog.showMessageBox({
    type: 'info',
    buttons: ['Ok'],
    title,
    message
  }, _ => {});
};
Example #15
0
function showLoadFiles() {
  dialog.showOpenDialog({
    properties: ['openFile', 'multiSelections']
  }, (filenames) => {
    if (!filenames) { return; }
    watch(filenames);
  });
}
Example #16
0
function openSoundDialog(cb) {
  const filters = [{
    name: 'Sound file',
    extensions: allowedSoundExtensions.map(ext => ext.replace(/^\./, ''))
  }];
  remote.dialog.showOpenDialog({ properties: ['openFile'], filters: filters }, filenames => {
    return filenames && filenames.length && cb && cb(filenames);
  });
}
Example #17
0
$("#qrcode-result").delegate("canvas","click",function(){
    let src = $(this)[0].toDataURL("image/png").replace(/^data:image\/png;base64,/, "");
    const {dialog} = require('electron').remote;
    dialog.showOpenDialog({properties: ['openDirectory']}, (filenames) => {
        if(filenames && filenames[0]){
            fs.writeFile(filenames[0] + '/qrcode_' + (new Date().getTime() / 1000 | 0) + '.png', src, 'base64');
        }
    })
});
Example #18
0
export const saveFileConfirmDialog = function (path, contents) {
  dialog.showMessageBox({
    title: 'Save your changes',
    message: 'Do you wan\'t to save the changes you have made ?',
    buttons: ['Yes', 'No']
  }, function (index) {
    if (index === 0) saveFile(path, contents)
  })
}
function openSong()
{
	dialog.showOpenDialog(
		function(fileNames)
		{
			if (typeof fileNames === 'undefined')
				return;
			loadSong(fileNames[0]);
		});
}
Example #20
0
var onFfiProcessTerminated = function(title, msg) {
  remote.dialog.showMessageBox({
    type: 'error',
    buttons: [ 'Ok' ],
    title: title,
    message: msg
  }, function() {
    window.msl.closeWindow();
  });
};
Example #21
0
document.querySelector("#deleteThisNote").addEventListener("click", (evt) => {
    let result = remote.dialog.showMessageBox({
        message: "Delete this note?",
        buttons: ['Yes', 'No']
    });
    if (result == 0) {
        ISDELETED = true;
        ipcRenderer.send('nm-delete-note', WINDOWNAME);
    }
});
Example #22
0
module.exports.openDirDialog = (options, callback) => {
  options = Object.assign({
    properties: ['openDirectory'],
  }, options);
  dialog.showOpenDialog(options, (path) => {
    if (path) {
      callback(path[0]);
    }
  });
};
function promptSave() {
  return remote.dialog.showMessageBox(remote.getCurrentWindow(), {
    type: 'question',
    buttons: ['Yes', 'No', 'Cancel'],
    defaultId: 0,
    title: 'Do you want to save?',
    message: 'Do you want to save?',
    cancelId: 2
  });
}
Example #24
0
Electron.openFileChooser = function (_) {
    const files = remote.dialog.showOpenDialog({
        title: _("Choose an SVG file"),
        filters: [{name: _("SVG files"), extensions: ["svg"]}],
        properties: ["openFile"]
    });
    if (files) {
        this.load(files[0]);
    }
};
Example #25
0
  return new Promise((resolve, reject) => {
    remote.dialog.showSaveDialog({
      filters: filters,
    }, function (fileName) {
      if (fileName) {
        return resolve(fileName);
      }

      return reject();
    });
  });
Example #26
0
function openFile() {
  dialog.showOpenDialog({
    filters: [{
      name: 'html&jsp',
      extensions: ['html', 'jsp', 'htm']
    }],
    properties: ['openFile', 'multiSelections']
  }, function(fileNames) {
    readFiles(fileNames)
  });
}
Example #27
0
 dirSelect = (event) => {
   let path = dialog.showOpenDialog({
     title:'title',
     buttonLabel: 'label',
     properties: [ 'openDirectory' ]
   });
   if(path) {
     path = path[0];
     this.props.onKeyPress(path);
   }
 }
Example #28
0
	download () {
		let resultContent = fs.readFileSync(this.path)

		dialog.showSaveDialog({
			title: 'Preview image',
			defaultPath: 'result.jpg'
		}, (filePath) => {
			fs.writeFile(filePath, resultContent, function (err) {
		        if(err) console.error(err);
		    });
		})
	}
Example #29
0
  $('#toolbar button').on('click', function(evt){
    var btn = $(evt.target).attr('action');
    switch(btn) {
      case 'record':
        record();
        break;
      case 'stop':
        stop();
        break;
      case 'pause':
        pause();
        break;
      // case 'resume':
      //   resume();
      //   break;

      // open file dialog
      case 'playvideo':
      //   ipcRenderer.send('asynchronous-message', JSON.stringify({event:'button', data:'playvideo'}));
        dialog.showOpenDialog(
          {filters: [
            { name: 'x264 Video', extensions: ['mp4'] }
          ]},function(file){
            console.log(file);
            if(!file) {
              return;
            }
            $('#editor-2 > video > source').attr('src', 'file://'+file[0]);
            $('#editor-2 > video').get(0).load();
          });
        break;

      case 'opendir':
      exec('start ' + outputDir);
        break;

      case 'help':
        {
          var localVer = null
          try{
            localVer = fs.readFileSync('ver.info').toString();
          }catch(e){
            console.log("error read file ver.info:", JSON.stringify(e));
          }

          alert('建议录制不要少于10秒钟, 以免视频生成失败\r\n如果发生问题, 请重启软件\r\nF10: 录制/结束\r\nF11: 暂停/继续\r\n播放视频文件: 选择本地视频文件播放' + (localVer?('\r\n当前版本:' + localVer):''));
        }
        break;

      default:
        console.log('unknown action:', btn);
    }
  });
Example #30
0
  onOpenDir() {
    const {dialog} = require('electron').remote;
    let path = dialog.showOpenDialog({
        properties: ['openDirectory']
    }, (d) => {
      console.log(d);

      this.setState({
        gpath: d[0]
      });
    });
  }