Lots of progress

This commit is contained in:
Timothy Warren 2018-04-13 23:28:55 -04:00
parent cc01a37ec8
commit 365e69c589
9 changed files with 67 additions and 21 deletions

View File

@ -6,6 +6,7 @@
"@stdlib/stdlib": "^0.0.35", "@stdlib/stdlib": "^0.0.35",
"dotenv": "5.0.1", "dotenv": "5.0.1",
"dotenv-expand": "4.2.0", "dotenv-expand": "4.2.0",
"electron-log": "^2.2.14",
"exiftool-vendored": "^4.20.0", "exiftool-vendored": "^4.20.0",
"inferno": "^5.0.1", "inferno": "^5.0.1",
"inferno-bootstrap": "^5.0.0", "inferno-bootstrap": "^5.0.0",

View File

@ -45,7 +45,16 @@ export class App extends Component {
webSocketLoaded: true, webSocketLoaded: true,
}); });
window.clientWS.onmessage = console.info; window.clientWS.onmessage = message => {
console.info(message);
console.info(message.data);
console.info(JSON.parse(message.data));
// const fr = new FileReader();
// fr.readAsArrayBuffer(message.data);
// console.info(fr.result);
};
console.info(window.clientWS); console.info(window.clientWS);
} }

View File

@ -1,13 +1,12 @@
const electron = require('electron'); const {app, BrowserWindow} = require('electron');
// Module to control application life. const log = require('electron-log');
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
const WS = require('isomorphic-ws'); log.transports.file.level = false;
log.transports.console.level = 'info';
const path = require('path'); const path = require('path');
const url = require('url'); const url = require('url');
const WS = require('isomorphic-ws');
// eslint-disable-next-line // eslint-disable-next-line
global.eval = () => {}; global.eval = () => {};
@ -51,6 +50,10 @@ const createWindow = () => {
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on('ready', createWindow); app.on('ready', createWindow);
app.on('browser-window-created', () => {
log.info('New browser window created');
});
// Quit when all windows are closed. // Quit when all windows are closed.
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar // On OS X it is common for applications and their menu bar
@ -71,7 +74,6 @@ app.on('activate', () => {
const wss = new WS.Server({ const wss = new WS.Server({
port: 65432, port: 65432,
}); });
// In this file you can include the rest of your app's specific main process // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here. // code. You can also put them in separate files and require them here.
require('./websocket-events')(wss); require('./websocket-events')(wss);

View File

@ -1,18 +1,29 @@
const {spawn} = require('child_process');
const log = require('electron-log');
const net = require('net'); const net = require('net');
const port = process.env.PORT ? (process.env.PORT - 100) : 3000; const port = process.env.PORT ? (process.env.PORT - 100) : 3000;
process.env.ELECTRON_START_URL = `http://localhost:${port}`; process.env.ELECTRON_START_URL = `http://localhost:${port}`;
log.transports.file.level = false;
const client = new net.Socket(); const client = new net.Socket();
let startedElectron = false; let startedElectron = false;
const tryConnection = () => client.connect({port: port}, () => { const tryConnection = () => client.connect({port}, () => {
client.end(); client.end();
if (!startedElectron) { if (!startedElectron) {
console.log('starting electron'); log.info('starting electron');
startedElectron = true; startedElectron = true;
const exec = require('child_process').exec; const instance = spawn('node', ['node_modules/electron/cli.js', '.'], {
exec('npm run electron'); env: {
...process.env,
},
stdio: 'inherit',
});
instance.on('message', (message, sendHandle) => {
console.log(message, sendHandle);
});
} }
}); });

View File

@ -1,13 +1,18 @@
/** /**
* Websocket event handlers * Websocket event handlers
*/ */
const {JSONMessage} = require('../helpers/web-socket');
module.exports = (wss) => { module.exports = (wss) => {
wss.on('open', ws => { wss.on('connection', ws => {
wss.send('server-log', 'Connected to client!'); ws.send(JSONMessage('server-log', 'Connected to client!'));
wss.on('dropped-files', e => { ws.on('message', (...args) => {
wss.send('recieved-dropped-files', e); console.info(args);
});
ws.on('dropped-files', e => {
ws.send(JSONMessage('recieved-dropped-files', e));
}); });
}); });
}; };

1
src/helpers/index.js Normal file
View File

@ -0,0 +1 @@
export * from './web-socket';

11
src/helpers/web-socket.js Normal file
View File

@ -0,0 +1,11 @@
const JSONMessage = (messageType, data) => {
// return new Blob([messageType, JSON.stringify(data)], {type: 'application/json'});
return JSON.stringify([
messageType,
data,
]);
};
module.exports = {
JSONMessage,
};

View File

@ -3,17 +3,19 @@ import {
Jumbotron, Jumbotron,
Row, Row,
} from '../components/Bootstrap'; } from '../components/Bootstrap';
import { JSONMessage } from '../helpers/web-socket';
function handleDrop (e) { function handleDrop (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
// console.log(e.dataTransfer.files); const draggedFiles = [];
window.clientWS.send('dropped-files', e.dataTransfer.files);
for (const f of e.dataTransfer.files) { for (const f of e.dataTransfer.files) {
console.log('Dragged files', f.path); console.log('Dragged files', f.path);
draggedFiles.push(f.path);
} }
window.clientWS.send(JSONMessage('dropped-files', draggedFiles));
} }
function handleDragOver (e) { function handleDragOver (e) {

View File

@ -2668,6 +2668,10 @@ electron-download@^3.0.1:
semver "^5.3.0" semver "^5.3.0"
sumchecker "^1.2.0" sumchecker "^1.2.0"
electron-log@^2.2.14:
version "2.2.14"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-2.2.14.tgz#2123319ccb8d70b0db07f0eda57d5823cb42b4b0"
electron-osx-sign@0.4.10: electron-osx-sign@0.4.10:
version "0.4.10" version "0.4.10"
resolved "https://registry.npmjs.org/electron-osx-sign/-/electron-osx-sign-0.4.10.tgz#be4f3b89b2a75a1dc5f1e7249081ab2929ca3a26" resolved "https://registry.npmjs.org/electron-osx-sign/-/electron-osx-sign-0.4.10.tgz#be4f3b89b2a75a1dc5f1e7249081ab2929ca3a26"