1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00

pipe fixes

This commit is contained in:
Razor 2019-09-12 14:53:16 +03:00
parent c20ffb8273
commit c3100bda49
6 changed files with 30 additions and 27 deletions

View file

@ -23,23 +23,21 @@ function createWindow () {
};
let win = new BrowserWindow(param);
let pipe = null;
win.loadURL('http://localhost:8080');
ipcMain.on('appLoaded', () => {
console.log('appLoaded');
let pipe = Pipe.start();
pipe.reader((event) => {
pipe = Pipe.start();
pipe.read((event) => {
win.webContents.send('pipeEvent', event);
});
let i = 0;
let sendStandardEvent = () => {
pipe.writer({ entity: "standard", op: "test", data: String(i) });
});
ipcMain.on('pipeCmd', (e, data) => {
if (pipe) {
pipe.write(data);
};
setInterval(sendStandardEvent, 1000);
});
ipcMain.on('appClose', () => {

View file

@ -42,27 +42,31 @@ class Pipe {
childProcess.exec('rm -rf ' + JS_TMP);
};
writer (msg) {
write (msg) {
let eventMsg = Event.create(msg);
let encoded = Event.encode(eventMsg).finish();
this.fifo.write(btoa(encoded.toString()));
console.log('Pipe.write', msg);
};
reader (cb) {
read (cb) {
let rl = readline.createInterface({ input: fs.createReadStream(GO_TMP) });
rl.on('line', (line) => {
// b64 -> msg + remove \n at the end
const msg = atob(line.slice(0, -1));
cb(Event.decode(Buffer.from(msg)));
console.log('Pipe.read', msg);
});
};
generateId () {
let chars = '0123456789ABCDEF'.split('');
let len = 32;
let arr = Array(len).fill(null).map(()=> chars[ Math.ceil(Math.random() * chars.length) - 1 ]);
let arr = Array(len).fill(null).map(() => chars[ Math.ceil(Math.random() * chars.length) - 1 ]);
return arr.join('');
};

View file

@ -8,7 +8,6 @@ body {
overscroll-behavior: none;
}
body.over { overflow-y: hidden; }
body.page-auth, body.page-index-index { background: #000; }
:focus { outline: 0px; }

View file

@ -30,12 +30,6 @@ const rootStore = {
class App extends React.Component<{}, {}> {
constructor (props: any) {
super(props);
Dispatcher.init();
};
render () {
return (
<Router history={history}>
@ -61,6 +55,10 @@ class App extends React.Component<{}, {}> {
};
componentDidMount () {
ipcRenderer.on('pipeEvent', (e: any, data: any) => {
Dispatcher.event(data);
});
ipcRenderer.send('appLoaded', true);
};

View file

@ -4,6 +4,7 @@ import { Provider } from 'mobx-react';
import { RouteComponentProps } from 'react-router';
import { Title, Label, Error, Input, Button } from 'ts/component';
import { observer, inject } from 'mobx-react';
import { Dispatcher } from 'ts/lib';
const $ = require('jquery');
@ -56,7 +57,7 @@ class PageAuthCode extends React.Component<Props, State> {
const authStore = this.props.auth;
const code: string = this.codeRef.getValue();
authStore.setCode(code);
Dispatcher.cmd({ entity: 'auth', op: 'code', data: code });
};
resize () {

View file

@ -7,12 +7,15 @@ class Dispatcher {
constructor () {
};
init () {
ipcRenderer.on('pipeEvent', (e: any, data: any) => {
console.log('PipeEvent', e, data);
authStore.setCode(JSON.stringify(data));
});
event (event: any) {
console.log('Dispatcher.event', event);
authStore.setCode(event.data);
};
cmd (data: any) {
console.log('Dispatcher.cmd', data);
ipcRenderer.send('pipeCmd', data);
};
};