Native OS X apps in JS? - javascript

I would like to write an application in JavsScript that runs natively on OS X. It would be a bonus if it could be used for Windows apps as well, however I am primarily interested in the OS X / Cocoa tie in initially.
I was entertaining the possibility of writing all of the business logic in JS and then the primary UI components with Cocoa and .NET respectively, but I got to thinking that it would be nice if there were something already in place that would facilitate such a workflow without having to support a few different codebases.
After researching this a bit, I obviously became overwhelmed with the solutions that seem to exist for iOS development, however hitherto I've found nothing that really seems to also work on OS X. Are there any solutions that I may be overlooking? If not, what might be the recommended path for basing most business logic in a JavaScript app and interfacing with that for the native UI components?

This is becoming a hot topic. I suggest you read this article about a JavaScript Objective-C bridge for OS 10.9. Also, check out this code sample from Apple in which the application controller is simply responsible for communicating between objects and JavaScript is really driving everything. The sample is called JavaScriptCoreHeadstart and Apple describes it as follows:
JavaScriptCore is a new system framework available in Mac OS X 10.5 that allows applications to run
JavaScripts. This sample shows one way to use JavaScriptCore for providing user configurable features
in a Cocoa application. Here, a number of JavaScript objects are defined that represent various parts
of the application and the application's controller is really just a thin shell that calls
JavaScripts that decide how the application will operate in response to Interface Builder action
method calls and WebKit delegate callbacks. The JavaScripts themselves control the application
through the objects that represent different parts of the application.

There is NodObjC that should allow you to write Cocoa applications for NodeJS.

Related

How to use observablehq/plot from .NET 5 app?

Our team intends to use JavaScript library observablehq/plot from an app written in C# and running on .NET 5. As a proof of concept, we were able to successfully use that library running in a separate process on Node.js. The downside of this approach is that we would need to implement all data serialization and inter-process communication ourselves, and we would need to bundle Node.js in our app installer. We are looking for an alternative approach that would not require Node.js, but instead would directly host V8 JavaScript engine in our .NET app. Currently, we are considering using ClearScript package for that. While we were able to successfully run simple JavaScript code using it, we discovered that observablehq/plot and its dependencies use some APIs that are present in Node.js, but are apparently unavailable in ClearScript out-of-the-box (it seems that Node.js implements some of those APIs in JavaScript, and some in C++). Making those implementations available to ClearScript running in .NET app looks like a significant task whose cost I cannot estimate at this point.
I would like to ask if anyone had to solve the same or similar problem, and what approach would you recommend? Is there an easy way to make all necessary APIs available to observablehq/plot running on ClearScript? Should I consider hosting Chromium/Edge browser engine in the .NET app instead? I haven’t yet tried this, but I assume it is possible because my understanding (correct me if I’m wrong) is that WebView2 control can be used in WPF apps running on .NET, and it is implemented using Chromium and V8 JavaScript engine. Is there any other approach you can recommend?
Update: The app GUI is built on Avalonia and SkiaSharp. It is possible that eventually we will choose another charting library, perhaps, one not written in JavaScript. But my task at hand is specifically to investigate whether and how we can use JavaScript libraries in our app, taking observablehq/plot as an example, and investigate its features and performance characteristics.
If you are building a WPF desktop app you should try a WPF based chart library that feats your needs.
Open source libraries:
OxyPlot
InteractiveDataDisplay
ScottPlot support pan and zoom.
Paid libraries:
Telerik RadChart
DevExpress
More info about WPF charts in this post.
If you are using Blazor WebAssembly:
Use jsRuntime and JSObjectReference to import and call your Javascript observablehp library.
If you are using Xamarin.Forms the best professional library out there is probably SyncFusion:
Syncfusion Charts
Update:
Avalonia Framework only will support this through a webview / embedded browser as you stated above. Here you have 3 options:
Cefnet is a .NET CLR binding for the Chromium Embedded Framework
CefGlue same than above
WebView Avaloria-CefGlue
For more usefull tools and libraries to use with Avalonia please refer to Awesome Avalonia.

Share code between platforms/languages (e.g. Swift, Kotlin, JavaScript)

Applications are often created for three platforms (Web, iOS, Android).
Currently the tech stack we are using are AngularJS (web) and Ionic/Cordova (iOS and Android). Since they are JavaScript based, we are able to write the core business logics (e.g. login) once and then share it across three (I know, it's two) platforms, leaving the UI implementations to the individual platforms. This method is awesome which helps us save so much time and human resources - core business logics are written and tested once and deployed everywhere. Google used similar method to develop Inbox, which allows them to share 70% of the code using J2Objc.
We want to apply the same awesomeness to the new era - Swift, Kotlin and a JavaScript based web framework (e.g. React/VueJs). We are open to using any one of these three languages to write the shared code. I am new to Swift and Kotlin but here are my best research results so far:
SwiftKotlin Converts Swift to Kotlin
KotlinJS Converts Kotlin to Js
So the development process would be Swift -> Kotlin -> JavaScript. However, the converted code are not production ready and requires manually editing. Also, the code written has to be language/platform library independent. For example, to write a JSON parser, we use Codable protocol in Swift 4, Moshi (external lib) in Kotlin and JavaScript can natively manipulate JSON.
I'd like to see if anyone has some nice solution to this question. Or maybe the question is to figure out what can be shared and what has to be done three times. Or this process is taking more time or error-prone and we should write the same logic three different times.
Thanks!

How to call a keyboard key with javascript or a C language

I am trying to figure out a way to programmatically press a key that the operating system (Windows) can read, rather then just printing the characters as a string.
Goal: To make a small standalone helper application to automatically press hotkeys at specific times in order to change the lighting inside of a building that is controlled by one Windows PC. I would like to code the application if javascript if capable, or a C language.
In Windows, an application can generate keyboard events using SendKeys.Send and related variants. See Simulating Mouse and Keyboard Events in Code. However, this is really not a good or stable way to communicate from one application to another...
Communication between apps via the UI is fragile, because applications may change their UI at any time (and may not be aware that others are relying on it in a programmatic way like this). Instead, proper communication between apps is done through an Application Programmer Interface (API). Since this is a home automation sort of system, you may wish to consider adopting / using devices that adopt one of many standards in development around how to communicate between devices and the kind of messages that are to be understood by devices. For example, Google's project Weave and Apple's HomeKit both have standard ways to tell a light to turn on or off.

Serve PyQt4 GUIs in Web-Application using HTML/CSS/JavaScript

Currently, we have a number of GUIs that have been developed using PyQt4 and PyQtGraph.
We need to make these interfaces accessible to a number of remote users and are hoping to do so by serving the GUIs through an HTML/CSS/JavaScript Web-Application.
The link below provides a few suggestions for this task, but these seem to apply to a project that is in its initial stages of creation. I'm familiar with the development of Python-JavaScript Web-Applications using the Pyramid Server and would like to use this same method for providing users access to PyQt4 GUIs that have already been developed.
https://softwareengineering.stackexchange.com/questions/109572/can-i-create-a-desktop-python-gui-application-and-run-it-as-a-web-app
So my question is, can I serve a functional PyQt4 GUI as a widget using HTML/CSS/JavaScript?
This is hard. In theory you could use a VNC-like approach that sends an image of the window to the client browser and sends user events back to the server. This will probably have poor interactivity depending on the networking and would require a lot of server power, depending on the number of users. (For an example of this, see: https://github.com/campagnola/webqt)
You're probably better off distributing the application with something like py2exe, py2app, cx_freeze, etc.
I personally haven't tried it but you could look into Wt: http://www.webtoolkit.eu/wt/
It is a C++ framework that has a Qt flavour. It has a Java version called JWt. Hence, a Jython binding exists for us Python programmers: http://www.webtoolkit.eu/wt/other_language
It is not a direct replacement of Qt, and might need modification to your Qt code to work as a Wt web app, but it certainly seems worth it to look into.

Javascript communicate with C++

I have a desktop application that has a C++ backend and a HTML5/JS front end. We are currently having to use Google V8 or Mac Webview and Objective-C to allow Javascript and C++ to communicate. Is there any way to have them directly talk to each other without the middleware?
Trying to accomplish:
Share variables.
Call Functions from C++ to JS.
Call Functions from JS to C++.
I have tried googling this and everything points to the above solutions.
You could try using Google's Protocol Buffers which allows you to create data objects that get compiled to C++ objects. You could then use one of the following projects from their wiki to use protobuffers with javascript:
https://github.com/sirikata/protojs
http://code.google.com/p/protobuf-js/
Your software sounds like a lot like a web app, without the internet in the middle. NodeJS might make good middleware in this case, you can write modules for it in C++, and use them in javascript. I haven't done this yet myself. A short example :)
And now a few years layer we have the Electron project, which is basically the above but with a Chrome based web view.
I wrote a library for that
Take a look to https://skywarpcpp.wordpress.com
SKYWARP++
Data streaming and rpc enabler server library for c++ Applications
You can download it at github
https://github.com/xjrueda/skywarp_cpp
You can now use Electron to get basically a Chrome web browser with direct access to the Node.js API. Then you can use nbind to easily call C++ code from JavaScript. This way both share the same thread and heap.
You declare the C++ classes by adding something like this to a C++11 source file:
NBIND_CLASS(X) {
construct<int, int>();
method(Y);
method(Z);
}
That creates bindings for a class X with a constructor taking 2 ints and methods Y and Z with pretty much any kind of arguments and optional return values.
nbind comes with an example for how to package your C++ code into a Node.js addon, for use in Electron.
Please have a look at this , I am the owner
http://code.google.com/p/libjspp/
libjspp allows easy interfacing & interacting of C++ with javascript spidermonkey 1.8.5?
Non intrusive to C++ & javascript world at same time.
Useful for applications which want to Embed & Extend Javascript in object oriented manner.
Very thin interface virtually no overhead by using C++ templates.
I am

Categories