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
|
* Websocket event handlers
|
||||||
*/
|
*/
|
||||||
const {JSONMessage} = require('../helpers/web-socket');
|
const {dialog, BrowserWindow} = require('electron');
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
|
||||||
|
const {getExifTags} = require('./exif-helpers');
|
||||||
|
const {JSONMessage} = require('../helpers/web-socket');
|
||||||
|
|
||||||
const wss = new WebSocket.Server({
|
const wss = new WebSocket.Server({
|
||||||
perMessageDeflate: false,
|
perMessageDeflate: false,
|
||||||
port: 65432,
|
port: 65432,
|
||||||
@ -22,17 +24,47 @@ wss.broadcast = (data) => {
|
|||||||
wss.on('connection', ws => {
|
wss.on('connection', ws => {
|
||||||
ws.send(JSONMessage('server-log', 'Connected to client!'));
|
ws.send(JSONMessage('server-log', 'Connected to client!'));
|
||||||
ws.on('message', async (...args) => {
|
ws.on('message', async (...args) => {
|
||||||
const [type, message] = JSON.parse(args);
|
try {
|
||||||
switch (type) {
|
const [type, message] = JSON.parse(args);
|
||||||
case 'dropped-files':
|
switch (type) {
|
||||||
const filemap = await Promise.all(
|
case 'dropped-files':
|
||||||
message.map(file => getExifTags(file))
|
const filemap = await Promise.all(
|
||||||
);
|
message.map(file => getExifTags(file))
|
||||||
wss.broadcast(JSONMessage('parsed-exif-tags', await filemap));
|
);
|
||||||
break;
|
wss.broadcast(JSONMessage('parsed-exif-tags', await filemap));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
case 'show-open-dialog':
|
||||||
return ws.send(JSONMessage('server-log', [type, message]));
|
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 {
|
import {
|
||||||
|
Button,
|
||||||
|
Col,
|
||||||
Container,
|
Container,
|
||||||
Jumbotron,
|
Jumbotron,
|
||||||
Row,
|
Row,
|
||||||
@ -22,6 +24,21 @@ function handleDragOver (e) {
|
|||||||
e.stopPropagation();
|
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) => {
|
export const HomeView = (props) => {
|
||||||
return (
|
return (
|
||||||
<Jumbotron onDrop={handleDrop} onDragover={handleDragOver}>
|
<Jumbotron onDrop={handleDrop} onDragover={handleDragOver}>
|
||||||
@ -36,6 +53,17 @@ export const HomeView = (props) => {
|
|||||||
Drop files here.
|
Drop files here.
|
||||||
</p>
|
</p>
|
||||||
</Row>
|
</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>
|
</Container>
|
||||||
</Jumbotron>
|
</Jumbotron>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user