New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

electron-prompt

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-prompt - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

11

lib/index.js

@@ -14,5 +14,11 @@ const electron = require('electron');

label: 'Please input a value:',
value: ''
value: null,
type: 'input',
selectOptions: null
}, options || {});
if(opts.type == 'select' && (opts.selectOptions === null || typeof(opts.selectOptions) !== 'object')) {
return reject(new Error('"selectOptions" must be an object'));
}
let promptWindow = new BrowserWindow({

@@ -25,4 +31,3 @@ width: 370, height: 130,

modal: parentWindow ? true : false,
title : opts.title,
type: 'text'
title : opts.title
});

@@ -29,0 +34,0 @@

const { ipcRenderer } = require('electron');
const docReady = require('doc-ready');
let promptId;
let promptId, promptOptions;
window.onerror = function(error) {
window.onerror = (error) => {
if(promptId) {

@@ -11,3 +11,3 @@ promptError("An error has occured on the prompt window: \n"+error);

function promptError(e) {
const promptError = (e) => {
if(e instanceof Error) {

@@ -19,8 +19,20 @@ e = e.message;

function promptCancel() {
const promptCancel = () => {
ipcRenderer.sendSync('prompt-post-data:'+promptId, null);
}
function promptSubmit() {
ipcRenderer.sendSync('prompt-post-data:'+promptId, document.getElementById('data').value);
const promptSubmit = () => {
const dataEl = document.getElementById('data');
let data = null;
if(promptOptions.type === 'input') {
data = dataEl.value
} else if(promptOptions.type === 'select') {
if(promptOptions.selectMultiple) {
data = dataEl.querySelectorAll('option[selected]').map((o) => o.getAttribute('value'));
} else {
data = dataEl.value;
}
}
ipcRenderer.sendSync('prompt-post-data:'+promptId, data);
}

@@ -31,5 +43,4 @@

let options;
try {
options = JSON.parse(ipcRenderer.sendSync('prompt-get-options:'+promptId));
promptOptions = JSON.parse(ipcRenderer.sendSync('prompt-get-options:'+promptId));
} catch(e) {

@@ -39,26 +50,54 @@ return promptError(e);

const dataEl = document.getElementById("data");
document.getElementById("label").textContent = promptOptions.label;
document.getElementById("ok").addEventListener('click', () => promptSubmit());
document.getElementById("cancel").addEventListener('click', () => promptCancel());
dataEl.addEventListener('keyup', (e) => {
e.which = e.which || e.keyCode;
if(e.which == 13) {
promptSubmit();
const dataContainerEl = document.getElementById('data-container');
let dataEl;
if(promptOptions.type === 'input') {
dataEl = document.createElement('input');
dataEl.setAttribute('type', 'text');
if(promptOptions.value) {
dataEl.value = promptOptions.value;
} else {
dataEl.value = '';
}
});
if(promptOptions.inputAttrs && typeof(promptOptions.inputAttrs) === 'object') {
for(let k in promptOptions.inputAttrs) {
if(!promptOptions.inputAttrs.hasOwnProperty(k)) continue;
document.getElementById("label").textContent = options.label;
dataEl.value = options.value;
if(options.inputAttrs && typeof(options.inputAttrs) === 'object') {
for(let k in options.inputAttrs) {
if(!options.inputAttrs.hasOwnProperty(k)) continue;
dataEl.setAttribute(k, promptOptions.inputAttrs[k]);
}
}
dataEl.addEventListener('keyup', (e) => {
e.which = e.which || e.keyCode;
if(e.which == 13) {
promptSubmit();
}
});
} else if(promptOptions.type === 'select') {
dataEl = document.createElement('select');
let optionEl;
for(let k in promptOptions.selectOptions) {
if(!promptOptions.selectOptions.hasOwnProperty(k)) continue;
dataEl.setAttribute(k, options.inputAttrs[k]);
optionEl = document.createElement('option');
optionEl.setAttribute('value', k);
optionEl.textContent = promptOptions.selectOptions[k];
if(k === promptOptions.value) {
optionEl.setAttribute('selected', 'selected');
}
dataEl.appendChild(optionEl);
}
}
dataContainerEl.appendChild(dataEl);
dataEl.setAttribute('id', 'data');
dataEl.focus();
});
});
{
"name": "electron-prompt",
"version": "0.3.0",
"description": "Electron helper to prompt for a string value",
"version": "0.4.0",
"description": "Electron helper to prompt for a value via input or select",
"main": "lib/index.js",
"keywords": ["electron", "prompt", "string"],
"keywords": [
"electron",
"prompt",
"string"
],
"author": {
"name": "sperrichon",
"email": "sperrichon@users.noreply.github.com",
"url": "https://github.com/sperrichon"
"name": "sperrichon",
"email": "sperrichon@users.noreply.github.com",
"url": "https://github.com/sperrichon"
},
"repository": {
"type": "git",
"type": "git",
"url": "https://github.com/sperrichon/electron-prompt.git"

@@ -15,0 +19,0 @@ },

# electron-prompt
Electron helper to prompt for a string value
Electron helper to prompt for a value via input or select

@@ -24,10 +24,16 @@ ## Usage

value: 'http://example.org',
inputAttrs: {
inputAttrs: { // attrs to be set if using 'input'
type: 'url'
},
type: 'select', // 'select' or 'input, defaults to 'input'
selectOptions: { // select options if using 'select' type
'value 1': 'Display Option 1',
'value 2': 'Display Option 2',
'value 3': 'Display Option 3'
}
})
.then((r) => {
console.log('result', r); //null if window was closed, or user clicked Cancel
console.log('result', r); // null if window was closed, or user clicked Cancel
})
.catch(console.error);
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc