Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two-way communication with the Swift binary #2

Closed
sindresorhus opened this issue Sep 14, 2017 · 5 comments · Fixed by #14
Closed

Two-way communication with the Swift binary #2

sindresorhus opened this issue Sep 14, 2017 · 5 comments · Fixed by #14

Comments

@sindresorhus
Copy link
Member

We'll need two-way communication to be able to implement pause/resume recording (#28) and to fix #40. We need to use some kind of socket/IPC communication (wulkano/Aperture#8 (comment)).

@sindresorhus
Copy link
Member Author

sindresorhus commented Sep 16, 2017

I just thought of a possible solution. We could use NSDistributedNotificationCenter to communicate between processes.

So on the Swift side we would send a notification when the Swift binary actually started recording:

DistributedNotificationCenter.default().postNotificationName(NSNotification.Name("aperture.recording"), object: nil, userInfo: ["file": url], deliverImmediately: true)

And on the Electron-side we would listen for that event:

electron.systemPreferences.subscribeNotification('aperture.recording', (event, userInfo) => {
	console.log('event', event, userInfo);
});

Which would output the following from Electron:

event aperture.recording { file: '…' }

This would work both ways. The downside is that we would need to write it specifically for Electron, so it would need to be a different mode/option in Aperture.


Additional reading: https://academy.realm.io/posts/thomas-goyne-fast-inter-process-communication/


@albinekb @LarsJK Thoughts?

@LarsJK
Copy link

LarsJK commented Sep 16, 2017

Yeah seems like a good solution to me, although I'm not too familiar with DistributedNotificationCenter or Electron..
Maybe you could use libnotify like that last article mentions as a C alternative to DistibutedNotificationCenter? Seems like there are a few node packages for libnotify..

@sindresorhus
Copy link
Member Author

@LarsJK Ah yeah, that's an interesting idea. I couldn't find a Node.js module for this, but shouldn't be too hard to create a simple one that interfaces libnotify using FFI.

@LarsJK
Copy link

LarsJK commented Sep 17, 2017

Maybe XPC could be an alternative as well..

Haven't actually used any of these myself, so I don't know which one would be best..

@albinekb
Copy link
Contributor

albinekb commented Nov 1, 2017

Perhaps that lib could use the electron implementation if it's available (and thus we could release a v0 that only supports the electron implementation now)? 🤔 @sindresorhus But yes, that sounds like the best solution so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants