Electron desktop client added

This commit is contained in:
2018-03-09 16:48:30 -05:00
parent 9533abc20e
commit fc9075c33f
1817 changed files with 250193 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 1.5em;
color: #333;
background-color: #fff;
overflow: hidden;
}
#container {
align-items: center;
justify-content: center;
display: flex;
height: 100%;
}
#form {
width: 100%;
}
#label {
max-width: 100%;
margin-bottom: .8em;
padding: 0 .5em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#data {
border-radius: 2px;
background: #fff;
width: 90%;
padding: .4em .5em;
border: 1px solid black;
min-height: 2em;
margin: 0 0 1.2em;
}
select#data {
height: 2em;
}
#data-container {
text-align: center;
}
#buttons {
text-align: right;
padding: 0 .5em 0 0;
}
#buttons > button {
border-radius: 2px;
border: 0;
margin: 0 0 0 .5em;
font-size: .8em;
line-height: 1em;
padding: .6em 1em
}
#ok {
background-color: #3879D9;
color: white;
}
#cancel {
background-color: #DDD;
color: black;
}

View File

@@ -0,0 +1,18 @@
<html>
<head>
<link href="prompt.css" rel="stylesheet" />
</head>
<body>
<div id="container">
<div id="form">
<div id="label">...</div>
<div id="data-container"></div>
<div id="buttons">
<button id="cancel">Cancel</button>
<button id="ok">OK</button>
</div>
</div>
</div>
<script src="prompt.js"></script>
</body>
</html>

View File

@@ -0,0 +1,99 @@
const { ipcRenderer } = require('electron');
const docReady = require('doc-ready');
let promptId, promptOptions;
window.onerror = (error) => {
if(promptId) {
promptError("An error has occured on the prompt window: \n"+error);
}
};
const promptError = (e) => {
if(e instanceof Error) {
e = e.message;
}
ipcRenderer.sendSync('prompt-error:'+promptId, e);
}
const promptCancel = () => {
ipcRenderer.sendSync('prompt-post-data:'+promptId, null);
}
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);
}
docReady(() => {
promptId = document.location.hash.replace('#','');
try {
promptOptions = JSON.parse(ipcRenderer.sendSync('prompt-get-options:'+promptId));
} catch(e) {
return promptError(e);
}
document.getElementById("label").textContent = promptOptions.label;
document.getElementById("ok").addEventListener('click', () => promptSubmit());
document.getElementById("cancel").addEventListener('click', () => promptCancel());
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;
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;
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();
});