gluon-framework / gluon

A new framework for creating desktop apps from websites, using system installed browsers and NodeJS
https://gluonjs.org
MIT License
3.1k stars 76 forks source link

RFC: IPC API v2 #29

Closed CanadaHonk closed 1 year ago

CanadaHonk commented 1 year ago

Second (major) iteration of IPC API. I dislike having to use an event-based system, I think there should be a wrapper for most developers to use which allows seemingly exposing functions into the web context, either via a function or using a setter in the IPC API object.

Expose

Function

Implementation A

Window.ipc.expose('key', (arg1, arg2) => {});

Implementation B

Window.ipc.expose({
  key: (arg1, arg2) => {}
});

Setter

Window.ipc.key = (arg1, arg2) => {};

Example usage

// node
Window.ipc.myFunction = () => {}; // or

Window.ipc.expose('myFunction', () => {}); // or

Window.ipc.expose({
  myFunction: () => {}
});

// web
Gluon.ipc.myFunction();

Unexpose

Function

Window.ipc.unexpose('key');

Setter

delete.Window.ipc.key:

Example usage

delete Window.ipc.key; // or

Window.ipc.unexpose('key');

I'm leaning towards using a setter, but it might seem strange/wrong to some people (for the first time). Please comment with which you prefer and/or opinions on all!

yellowsink commented 1 year ago

I like the simplicity of a setter, but I fear the "magic" to do it is a bad idea.

Comfiest api though...

yellowsink commented 1 year ago

I think i prefer impl A to impl B though of those two.

CanadaHonk commented 1 year ago

I suppose we could support both (or all)? Would probably overcomplicate things though.

CanadaHonk commented 1 year ago

Adding all 3 implementations described in the issue.

WorriedArrow commented 1 year ago

I prefer Implementation B since it allows you to easily define multiple functions in 1 call, so you wouldn't have to keep calling the function.

CanadaHonk commented 1 year ago

Thanks for your input. Both implementations are now supported in current branch, as well as the setter.

WorriedArrow commented 1 year ago

I like the idea of having two implementations as well. Can't wait to see where this API goes!

yellowsink commented 1 year ago

given this is fully implemented, is this rfc closable now?

CanadaHonk commented 1 year ago

Will be closed upon v0.10 release shortly.