Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i use OSX native API's in electron

Is there a way to use OSX Native API's using Electron. Let say i want to use System Configuration Framework, is there a way to use the power of native OSX API?

Thanks

like image 620
Dawood Mujib Avatar asked Jan 08 '16 06:01

Dawood Mujib


2 Answers

I realize this is a late answer but you have some options:

  • native node modules allow you to write in C++ and ObjectiveC (or Swift) and expose an API to node.js using v8. This gives you a lot of flexibility and power but requires the most time to develop.

  • NodObjC is a native node module that allows you to interact with the ObjC runtime. I've never used it but it seems like a solid project and would simplify whatever you're trying to do. Another option similar to this is node-ffi. The framework you referenced looks like an ObjC API though, so not sure if that'll work for your specific use case.

  • For simple stuff, you can use node-applescript. I've only played with applescript a little bit but I was surprised at some of the things you can do with it. For example, you can use it to set your app to start on login (see node-auto-launch). While limited compared to the above, if it does what you want, it's simpler and requires no compiling, which is nice. Note that this is going to use child_process under the hood to spawn a new process to run the applescript in. That may have some ramifications to consider for whatever you're trying to do.

  • You can also just use the node child_process module if the OSX API you're trying to use has a good CLI. The upside here is simplicity, the downside is you may have to parse the strings it outputs into meaningful data structures, which can be moderately difficult in my experience.

like image 106
ccnokes Avatar answered Nov 19 '22 04:11

ccnokes


You can also use ffi to call native libraries directly from javascript.

like image 45
justin.m.chase Avatar answered Nov 19 '22 05:11

justin.m.chase