Playing with some dialogs
This commit is contained in:
parent
baf620133b
commit
83e53cf84e
@ -1,11 +1,13 @@
|
||||
const {getExifTags} = require('./exif-helpers');
|
||||
/**
|
||||
* Websocket event handlers
|
||||
*/
|
||||
const {JSONMessage} = require('../helpers/web-socket');
|
||||
const {dialog, BrowserWindow} = require('electron');
|
||||
// eslint-disable-next-line
|
||||
const WebSocket = require('ws');
|
||||
|
||||
const {getExifTags} = require('./exif-helpers');
|
||||
const {JSONMessage} = require('../helpers/web-socket');
|
||||
|
||||
const wss = new WebSocket.Server({
|
||||
perMessageDeflate: false,
|
||||
port: 65432,
|
||||
@ -22,6 +24,7 @@ wss.broadcast = (data) => {
|
||||
wss.on('connection', ws => {
|
||||
ws.send(JSONMessage('server-log', 'Connected to client!'));
|
||||
ws.on('message', async (...args) => {
|
||||
try {
|
||||
const [type, message] = JSON.parse(args);
|
||||
switch (type) {
|
||||
case 'dropped-files':
|
||||
@ -31,8 +34,37 @@ wss.on('connection', ws => {
|
||||
wss.broadcast(JSONMessage('parsed-exif-tags', await filemap));
|
||||
break;
|
||||
|
||||
case 'show-open-dialog':
|
||||
const files = dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
|
||||
filters: [{
|
||||
extension: ['jpg', 'jpeg', 'tif', 'tiff', 'dng'],
|
||||
name: 'EXIF image types',
|
||||
}, {
|
||||
extensions: ['*'],
|
||||
name: 'All Files',
|
||||
}],
|
||||
properties: [
|
||||
'openFile',
|
||||
'multiSelections',
|
||||
],
|
||||
});
|
||||
wss.broadcast(JSONMessage('selected-files', files));
|
||||
break;
|
||||
|
||||
case 'show-save-dialog':
|
||||
const saveFile = dialog.showSaveDialog(BrowserWindow.getFocusedWindow());
|
||||
wss.broadcast(JSONMessage('save-file-location', saveFile));
|
||||
break;
|
||||
|
||||
case 'show-error-box':
|
||||
dialog.showErrorBox('An Error has Occured', message);
|
||||
break;
|
||||
|
||||
default:
|
||||
return ws.send(JSONMessage('server-log', [type, message]));
|
||||
}
|
||||
} catch (e) {
|
||||
console.info(args);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,6 @@
|
||||
import {
|
||||
Button,
|
||||
Col,
|
||||
Container,
|
||||
Jumbotron,
|
||||
Row,
|
||||
@ -22,6 +24,21 @@ function handleDragOver (e) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
function showOpenDialog () {
|
||||
window.clientWS.send(JSONMessage('show-open-dialog', {}));
|
||||
}
|
||||
|
||||
function showSaveDialog () {
|
||||
window.clientWS.send(JSONMessage('show-save-dialog', {}));
|
||||
}
|
||||
|
||||
function showErrorDialog () {
|
||||
window.clientWS.send(JSONMessage(
|
||||
'show-error-box',
|
||||
'Looks like there was a problem. (╥﹏╥) \n (╯°□°)╯︵ ┻━┻'
|
||||
));
|
||||
}
|
||||
|
||||
export const HomeView = (props) => {
|
||||
return (
|
||||
<Jumbotron onDrop={handleDrop} onDragover={handleDragOver}>
|
||||
@ -36,6 +53,17 @@ export const HomeView = (props) => {
|
||||
Drop files here.
|
||||
</p>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col md={4}>
|
||||
<Button onClick={showOpenDialog}>Show Open Dialog</Button>
|
||||
</Col>
|
||||
<Col md={4}>
|
||||
<Button onClick={showSaveDialog}>Show Save Dialog</Button>
|
||||
</Col>
|
||||
<Col md={4}>
|
||||
<Button onClick={showErrorDialog}>Show Error Dialog</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
</Jumbotron>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user