krimlabs / eiphop Goto Github PK
View Code? Open in Web Editor NEWA fetch like wrapper for elecron's ipc.
Home Page: https://eiphop.js.org
A fetch like wrapper for elecron's ipc.
Home Page: https://eiphop.js.org
Since 2020 the security of the electron apps require recommend a preload function. To use this lib with preload it could export the preload function.
I am able to make the pull request, it is just a questions if I should?
Export somehow this function
contextBridge.exposeInMainWorld('api', {
send: (channel: string, requestId: string, action: string, payload: any): void => {
const validChannel = ['asyncRequest'];
if (validChannel.includes(channel)) {
ipcRenderer.send(channel, requestId, action, payload);
}
},
on: (channel: string, callback: Function): void => {
const validChannel = [
'asyncResponseNotify',
'asyncResponse',
'errorResponse',
]
if (validChannel.includes(channel)) {
// Strip event but pass an empty object to the callback
ipcRenderer.on(channel, (_event, ...args) => callback({}, ...args));
}
}
});
So the user can do:
// preload.ts
import electron from 'electron';
import { generatePreload } from 'eiphop';
generatePreload(electron);
The current readme was a mindless copy paste from my blog post.
Create a more clear readme with that highlights the vision of this wrapper to be a fetch
equivalent for electron ipc. Make installation and getting started easier.
Comments and suggestions welcome :)
Hi all,
I'm compiling a list of projects that use Eiphop for IPC. If you are using it, please comment on this issue.
So far, I've found:
I noticed when an action takes some time I get an error:
WebSocket connection to 'ws://localhost:3000/sockjs-node/324/1puq2ekr/websocket' failed:
WebSocket is closed before the connection is established.
I receive the data no problem but I am getting this warning.
An example code I am using is the following:
console.log("Start");
emit('sourceGet', params).then(res => {
console.log("End");
setState({
mode: 0,
...res
});
});
The console output is
Start
The error mentionned
End
in SourceGet
if I remove the function that takes time, the error dissapears.
The function is a nodejs addon (c++ based) so it should not intervene with eiphop.
And thanks for such a great api
I want to unsubscribe pending events on unmount react component because it is causing memory leak.
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
This module looks greate, but i have a question. In the case where the action is async, for exemple:
const actions = {
test: async (req, res) => {
const list = await manager.someAsyncFunc();
res.send(list)
}
};
Would any error coming from someAsyncFunc be automatically send to renderer ?
Because it looks like right now we are supposed to always try/catch and use res.error.
There could be a default errorhandler in the engine that check sends the error automatically. Here what it imagine:
requestedAction({payload}, {
send: (res) => event.sender.send('asyncResponse', requestId, res),
error: (err) => event.sender.send('errorResponse', requestId, err)
});
could become
const res = {
send: (res) => event.sender.send('asyncResponse', requestId, res),
error: (err) => event.sender.send('errorResponse', requestId, err)
};
try {
const promise = requestedAction({payload}, res);
///isPromise needs to be implemented
if (isPromise(promise)) {
promise.catch((e) => {
//error in async code
res.error(e)
})
}
} catch (e) {
//error inside sync code
res.error(e);
}
Most of the functions can be tested using unit tests.
The overall functionality however will need an electron instance and some form of e2e testing.
Study available tools to implement that. This will increase the overall quality of the project.
I am getting the error [ERROR] TypeError: res.notify is not a function
when trying to invoke notify.
When I dump the contents of res
all I get is { send: [Function: send], error: [Function: error] }
node: v11.10.1
eiphop: ^1.0.12
emit('ping', {id: 123}, (msg) => {
console.log(msg)
})
.then((res) => console.log(res)) // will log {msg: 'pong'}
.catch((err) => console.log(err))
const actions = {
ping: (req, res) => {
const {payload} = req
res.notify('Downloading file ${payload.id}')
res.send({msg: 'pong'})
},
}
Hello,
I am using eiphop and whenever I call the emit function I get the following error:
renderer.js:111 Uncaught TypeError: Cannot read property 'dfd' of undefined
at EventEmitter. (renderer.js:111)
at EventEmitter.emit (events.js:199)
This is my actions variable:
const actions = {
getCategories: async (req, res) => {
var data = openJSON(CONFIG_DIR + path.sep + CAT_FILE);
if (data === undefined)
res.send({ categories: [] });
else
res.send({ categories: data });
}
}
I'm calling a function to setup the actions using:
module.exports = {
setupAPI: function(electron) {
setupMainHandler(electron, {...actions});
}
}
And finally in jsx:
emit('getCategories').then((res) => { this.setState({ categories: res.categories }); });
For my project, I want to send request to hidden renderer process. we have database layer in hidden window.
pendingRequests
is updated only on a success response.
After getting more familiar with electron, I have a question:
For me the ipcMain.handle
and ipcRenderer.invoke
seems to do the same thing that eiphop wants to achieve. Is there a reason why is eiphop better?
Thank you for the explanation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.