Developing Windows apps with JavaScript - javascript

I'm currently in the need of developing a Windows application. I want to keep things simple (in the spirit of uTorrent) and I would like the result program to be a single .exe file containing all that it needs.
The program is simple. It just needs some UI. It needs to run for a long period of time (lay there as a tray icon). It needs to do some routine tasks like simple I/O. It also needs to access the internet, specifically some web server.
Apart from these small requirements I would like to write all of it in JavaScript, as I feel more comfortable with it than any other language.
I know there's things like Windows Script Host that let you run JavaScript programs and interact with some Win32 API, but will I be able to do everything I need with Windows Script Host? Can I pack all of the Windows Script Host in a single .exe?
If not, what alternatives do I have for JavaScript?

I found that there's actually a JavaScript compiler that comes with the .NET framework called jsc.exe.
For more information:
http://www.phpied.com/make-your-javascript-a-windows-exe/
http://msdn.microsoft.com/en-us/library/7435xtz6(VS.80).aspx
I guess it's not really JavaScript since it introduces extra things like import and even some class syntax which is weird for me. But this works perfectly for me as I will just doing things as I am used to on the web.

Aside from Windows Script Host, there are
Windows Desktop Gadgets (Vista and Windows 7 only)
HTML Applications (HTAs)
Both are written with standard web technologies, HTML, JavaScript, Flash, etc. They can also be extended with COM objects/ActiveX controls such as FileSystemObject, WMI, WScript or even ones that you write yourself. Windows Desktop Gadgets have access to a separate API/namespace with various Win32-esque properties and methods.

It seems that nobody mentioned JSDB.
JSDB offers a command line environment which you can execute arbitrary javascript code. You can easily compile to a .exe file by using the command copy /b jsdb.exe+program.zip program.exe
It's important to know that you've got to call your main js file main.js within a standard zip file. Not sure if the name program.zip is required.
I haven't actually tried making GUI applications with this yet - although it seems to support various APIs like ActiveX.
It's possible that by using the copy /b command mentioned above, you could compile a script from the wscript.exe file - but I tried and couldn't get it working. Let me know if anybody tries and has success somehow.

I think you're looking for Adobe AIR
The Adobe® AIR® 2 runtime enables developers to use HTML, JavaScript, Adobe Flash® software, and ActionScript® to build web applications that run as standalone client applications without the constraints of a browser. ~ The AIR website

Internet Explorer introduced the concept of Hypertext Applications in IE 5. It never made a big breakthrough, so resources and documentation are scarce.
Mozilla-backed competitor Prism seems to be alive and well, though, and is definitely worth a look.
Prism is an application that lets users split web applications
out of their browser and run them directly on their desktop

I believe the best way to go is V8 JavaScript Engine provided by Google.
"V8 can run standalone, or can be embedded into any C++ application." - which I believe is perfect for your needs, because you can do most of the stuff in JavaScript and use provided interfaces to communicate with the system.

I'm not 100% but I believe WSH uses JScript or WScript, not JavaScript.

Color me crazy, but its only a short step form Javascript to Java or C#. I'd suggest C# as, on a windows machine, the libraries are already there. You can just copypaste your .exe and let 'er rip.

If you want a single .EXE, what runtimes are you okay if they are required pre-requisites?
If you're okay with requiring .NET runtime to be preinstalled, then you do all your work in JScript.NET

Chromium Embedded Framework (CEF) may give you some help. i have not clearly know how, but i realy found many Apps using this framework.
http://code.google.com/p/chromiumembedded/
Introduce for CEF are:
The Chromium Embedded Framework (CEF) is an open source project founded by Marshall Greenblatt in 2008 to develop a Web browser control based on the Google Chromium project. CEF currently supports a range of programming languages and operating systems and can be easily integrated into both new and existing applications. It was designed from the ground up with both performance and ease of use in mind. The base framework includes C and C++ programming interfaces exposed via native libraries that insulate the host application from Chromium and WebKit implementation details. It provides close integration between the browser control and the host application including support for custom plugins, protocols, JavaScript objects and JavaScript extensions. The host application can optionally control resource loading, navigation, context menus, printing and more, while taking advantage of the same performance and HTML5 technologies available in the Google Chrome Web browser.
Numerous individuals and organizations contribute time and resources to support CEF development, but more involvement from the community is always welcome. This includes support for both the core CEF project and external projects that integrate CEF with additional programming languages and frameworks (see the "External Projects" section below).

Why not use Rhino -- JavaScript on the JVM? You can even compile your scripts to .class files and package them into a JAR along with Rhino for easy distribution...

Related

Is there an HTA-like solution for modern web apps?

I have been developing an app using HTML, CSS, and JS, using the App Mode command line argument for Google Chrome. It works nice, but I would like some ability to use the local file system without manual input from the user. That is, if I want a file accessed directly, I want it automatically done, not requiring the user to load the file in.
One option is to disable web security, which I'm not doing because there is a need to use Google Chrome normally. I haven't been able to use a command line argument to create a separate instance of Chrome, either.
I tried working on an HTA, but any attempt to port the code to HTA ends in headaches. Also, it doesn't seem to enjoy the perks that Blink/Webkit grants.
I looked into Electron and other similar platforms, and it requires installing a handful of things, which is a no-go due to the computer setup.
Are there any solutions with a sort of portable app, that can be dropped in a folder with the HTML document (say, labeled index.html or main.html), and upon opening the browser it directly opens that file without having to configure anything? A sort of barebones chromium-based browser that only opens a single file, allowing use of HTML, JS, CSS, along with local file access? Kind of like HTA but modern?
The good news, is that it does exist, but it's not as "out-of-the-box" as HTA.
My team has migrated from HTA to WebView2.
The overall approach is to build a program with the WebView2 browser (you're basically building your own HTA like browser). Your javascript code can communicate back and forth with the program, which in turn has full access to local resources.
WebView2 is the Microsoft Edge Chromium browser, so you're getting the latest web tech and layouts (a big pain for HTA dev.). The program that contains the WebView2 control has full access to local files, scales, printers (without a pop-up dialog).
The approach has all the benefits of HTA (html / javascript programming, local file access, web based deployment, etc.), plus all layout and other benefits of a modern browser.
The program you'll build is very small, especially compared with the HUGE runtime of similar solutions, like Electron.
Rick Strahl has an excellent article on WebView2, and tips for building the program I'm describing. He has great advice on how to build an installer for it, including "Evergreen", which keeps the WebView2 up-to-date with the latest browser tech.
Microsoft's introduction to the technology here.
https://learn.microsoft.com/en-us/microsoft-edge/webview2/

Is Node.js the One Allows to Write Cross Platform Applications in JavaScript?

Node.js allows to access IO layer / database and it allows write javascript code in server-side.
I'm just wondering is Node.js the one allows to write cross platform applications ?
If yes,
How this possible?
Node.js just release on 2009 and has it opens up almost all platforms.
What is the reason preventing other languages such as C# to get this ability ?
(Apologies if i am mistaking the concept. i'm just stated to learn node.js) (googled)
How this possible?
It (or library code written in other languages) abstracts operating system specific stuff. Code is then compiled for each platform by the node executable that runs on each platform.
What is the reason preventing other languages such as C# to get this ability ?
Nothing. That is why C# programs are also able to run cross platform. Here is, for example, a C# compiler for Linux.
NodeJS does allow cross platform development, as node abstracts out the system specific functionality into APIs your code can access.
Regarding C#,you can do the same thing, you'll just need to run the code in in something like mono for *nix. However, it's worth noting that .net has gone open source and will soon be compiled natively for other environments (and won't need to run within mono). This also enables you to run it on arm devices as well, such as raspberry pi.

How to use Seed in Windows, Mac, Android to write standalone applications in JavaScript?

Use Javascript language with Seed looks great. But how do you use it in Windows, Mac, Android?
Is there any port available for those?
I was trying to test them in cross-platforms where in my Gnome it works only, such as: http://git.gnome.org/browse/seed-examples/tree/
#!/usr/bin/env seed
Gtk = imports.gi.Gtk;
Gtk.init(Seed.argv);
var window = new Gtk.Window({title: "Example"});
window.signal.hide.connect(Gtk.main_quit);
window.show_all();
Gtk.main();
It might not be the answer you are looking for, but the seed wiki states that seed is for the "GNOME platform", it's not coming with a cross platform GTK all-in-one package.
If you want to do lightweight and interpreter-centric cross platform development with javascript, you may want to look at Mozilla's rhino (probably coupled with swt, I found that pretty easy - did a couple of scripts that work on osx/win/linux if the machine has java and js.jar), or node.js (if no gui is required, I never had luck with node graphical bindings in a cross platform fashion) - node-webkit from Intel's opensource department also looks interesting.
If Android is a must and you care to give up interpreters, you may try as3 (the flex sdk is "free" and now we have captive runtime air apps) or neko/haxe, they are ecmascript dialects, but of course there are quite a lot of possibilities; these are the ones I looked at earlier. Hope it helps and sorry if it did not.
Szabolcs Kurdi is right but there is a solution to get javascript to work with gui in Windows.
its called app.js and is a highly developed nodejs module. (Windows, Mac, Linux)
appjs.org
check it out if you like. i personaly use it and love it.
you even can use webkits javascript debugger IN it by calling window.frame.openDevTools();
and you can forward module methods into the dom of it.
besides using appjs you could use .hta files in windows in order to create forms using javascript.
i would not recommend this though since microsoft jscript is very limited in debuggability, performance and support.
you also need to keep in mind that gnome uses javascript in its core in multiple ways so it has api's to native methods that you will not find in microsoft's jscript.
in order to get something similar i would srsly recommend you nodejs since you can extend it with thousands of modules (while appjs is one of them).

Desktop application development with Javascript and HTML

I am looking for Titanium Appcelerator alternatives for Desktop application development with HTML and JavaScript. I want to convert a web app to a desktop application. Hence, there will be a lot of server interaction. Appcelerator was a good choice, but it looks like the company is no longer interested in the Desktop SDK. Also, ajax request from Appcelerator does not retain cookies.
I read that Adobe Air can be used for desktop app development, but I don't want to use flash.
How good is XULRunner? Will it allow features like Growl notificaiton and creating tray icons?
Will I be able to develop applications using mostly Javascript and HTML in Qt?
I started looking into Titanium for desktop dev. I liked the concept but not the implementation. I then stumbled upon chromiumembedded and have been mostly very happy with it. It's basically a web browser control based on chromium.
http://code.google.com/p/chromiumembedded/
It's written in C++ so you can do all the low level OS stuff you want(Growl, tray icons, local file access, com ports, etc) in your container app, and then all the application logic and gui in html/javascript. It allows you to intercept any http request to either serve local resources or perform some custom action. For example, a request to http://localapp.com/SetTrayIconState?state=active could be intercepted by the container and then call the C++ function to update the tray icon.
It also allows you to create functions that can be called directly from javascript.
My biggest challenge has been debuging. It's very difficult to debug javascript directly in CEF. There's no support for anything like Firebug that I am aware of.
Appjs (appjs.org) looks very promising.
You could also check Bowline which is another alternative: http://bowlineapp.com/.
Although it's not officially intended for general-purpose use, a number of people have had success using brackets-shell for HTML/JS desktop apps. It embeds Chromium (CEF) and adds APIs for menu bar management and file IO. It also embeds an instance of Node.js so you get access to all its APIs for launching processes, etc. It's MIT-licensed and available for Mac & Win, with a Linux version currently making rapid progress.
As I mentioned, it's not officially a general-purpose app shell, but someone wrote a detailed blog post about how to customize brackets-shell for your own uses.
I notice that the other answer about Titanum says CEF is hard to debug. I'm not sure if that's true in Titanium, but in brackets-shell it's easy to debug JS – you just open http://localhost:9234/ to load a full instance of the Chrome Developer Tools (including breakpoints, profiling, etc.).
TideSDK is a continuation of the old Titanium desktop http://www.tidesdk.org/

I want to write a desktop OSX or Windows app in Javascript -- any experiences?

I'd like to write some small applications for Windows and OSX.
Portable is good. For instance, the simple TclKit solution for TCL would work well if I could stand to look at Tcl for any length of time.
I'm considering using Javascript + extensions -- I really like Javascript -- seems to me there should be some way to connect a Javascript engine to WxWin or even the Tk toolset -- it's been done for Perl, Python, Ruby, etc. Why not JS?
Any comments appreciated.
I would rather recommend using Adobe Air execution container, it offers way more capabilities / OS integration features compared to HTA of Microsoft or even XULRunner of Mozilla.
If you want to write a desktop app in Javascript, check out HTA: http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx
Here is an example of an app that I wrote a long time ago in HTA: http://www.boltbait.com/htmleditor/
Hope this helps.
If you have experience with HTML+JS web applications, I'd recommend Mozilla XULRunner. It gives you native-looking interface widgets (every piece of Firefox interface is a XUL element), and a workflow similar to building HTML-based interface.
You define the interface using XUL, an XML-based language, so it's almost like writing HTML, minus browser incompatibilities and CSS (you can use CSS, but only if you want). All application logic can be written in JavaScript, but in XULRunner you can do a lot more in JS than in a browser (read/write files, execute system commands, make cross-domain XMLHTTPRequests, and a lot of other stuff).
More: http://xulplanet.com/
A lot of example applications: http://code.google.com/p/xulapps/
Mac OS X users tend to dislike applications that don't follow usability guidelines of the platform (menu must be at top of the screen, standard shortcuts & drag'n'drop must work, "OK" must be at right-hand side of alertboxes, no "Apply" button in prefs and so on).
With one-size-fits-all toolkit this may be very difficult to achieve.
The good news is that there's JavaScript<>Cocoa bridge that can be used to create stand-alone full-featured Mac OS X application in JS – just keep front-end and back-end of your application separate enough to be able to plug different UI for each OS.
Rhino would probably give you access to swing. Though, I don't know how much work would be involved.
On the other hand, building a swing app with JRuby is so easy even a sock puppet can do it, so it shouldn't be too hard.
Definitely if you want to implement it using JavaScript, Adobe Air is the way to go. You will even have support on Linux.
Give Titanium Appceletaror a look: http://www.appcelerator.com/.

Categories

Resources