Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions clients/desktop/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/desktop/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"commander": "^2.19.0",
"crypto": "^1.0.1",
"debounce": "^1.2.0",
"migrate": "^1.6.1",
"electron-updater": "^3.2.3",
"express": "^4.16.4",
"hyperbridge-funding-protocol": "^1.0.13",
Expand All @@ -33,6 +32,7 @@
"hyperbridge-token": "^1.0.12",
"json-beautify": "^1.0.1",
"lokijs": "^1.5.5",
"migrate": "^1.6.1",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"rimraf": "^2.5.2",
Expand Down
19 changes: 18 additions & 1 deletion clients/desktop/app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as PeerService from '../framework/peer-service'
import * as Wallet from '../framework/wallet'
import * as Windows from './windows'
import * as Updater from './updater'

import electronPrompt from './windows/prompt/index.js'

const config = require('../config')

Expand Down Expand Up @@ -181,6 +181,23 @@ export const initApp = () => {
callback({ cancel: false })
}
})

// Test for the electron prompt


electronPrompt({
title: 'TEST PROMPT',
label: 'TEST INPUT',
value: 'TEST',
inputAttr: {
type: 'text'
},
type: 'input'
}).then(r => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass in Windows.main as the 2nd param (parentWindow)

console.log('Input is ', r);
}).catch(console.error);



DB.init()
Windows.main.init(deeplinkUri, !config.IS_PRODUCTION, argv.tools)
Expand Down
72 changes: 72 additions & 0 deletions clients/desktop/app/src/main/windows/prompt/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 1.5em;
color: #333;
background-color: #fff;
}

#container {
align-items: center;
justify-content: center;
/* display: flex; */
height: 100%;
overflow: auto;

}

#form {
width: 100%;
}

#label {
max-width: 100%;
max-height: 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;
}
18 changes: 18 additions & 0 deletions clients/desktop/app/src/main/windows/prompt/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

<head>
<link href="prompt.css" rel="stylesheet" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.css

</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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.js?

</body>
</html>
98 changes: 98 additions & 0 deletions clients/desktop/app/src/main/windows/prompt/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const electron = require('electron');

const BrowserWindow = electron.BrowserWindow || electron.remote.BrowserWindow;
const ipcMain = electron.ipcMain || electron.remote.ipcMain;
const url = require('url');
const path = require('path');

function electronPrompt(options, parentWindow) {
return new Promise((resolve, reject) => {
const id = `${new Date().getTime()}-${Math.random()}`;

const opts = Object.assign(
{
width: 370,
height: 130,
resizable: false,
title: 'Prompt',
label: 'Please input a value:',
alwaysOnTop: false,
value: null,
type: 'input',
selectOptions: null,
icon: 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({
width: opts.width,
height: opts.height,
resizable: opts.resizable,
parent: parentWindow,
skipTaskbar: true,
alwaysOnTop: opts.alwaysOnTop,
useContentSize: true,
modal: Boolean(parentWindow),
title: opts.title,
icon: opts.icon
});

promptWindow.setMenu(null);

const getOptionsListener = event => {
event.returnValue = JSON.stringify(opts);
};

const cleanup = () => {
if (promptWindow) {
promptWindow.close();
promptWindow = null;
}
};

const postDataListener = (event, value) => {
resolve(value);
event.returnValue = null;
cleanup();
};

const unresponsiveListener = () => {
reject(new Error('Window was unresponsive'));
cleanup();
};

const errorListener = (event, message) => {
reject(new Error(message));
event.returnValue = null;
cleanup();
};

ipcMain.on('prompt-get-options:' + id, getOptionsListener);
ipcMain.on('prompt-post-data:' + id, postDataListener);
ipcMain.on('prompt-error:' + id, errorListener);
promptWindow.on('unresponsive', unresponsiveListener);

promptWindow.on('closed', () => {
ipcMain.removeListener('prompt-get-options:' + id, getOptionsListener);
ipcMain.removeListener('prompt-post-data:' + id, postDataListener);
ipcMain.removeListener('prompt-error:' + id, postDataListener);
resolve(null);
});

const promptUrl = url.format({
protocol: 'file',
slashes: true,
pathname: path.join(__dirname, 'page', 'prompt.html'),

@contextlimit contextlimit Nov 21, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no 'page'
index.html not prompt.html

hash: id
});

promptWindow.loadURL(promptUrl);
});
}

module.exports = electronPrompt;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export default electronPrompt

3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.