📜 ⬆️ ⬇️

Porting a web application under Adobe AIR

This article will look at an example of porting a web application written in JavaScript to an Adobe AIR application.
First of all, since the advent of Adobe AIR and the first examples of ExtJS porting to AIR, I was tormented by the thought - how hard or just convert a web application written in JavaScript to an AIR application. A couple of days ago there was time to experiment.

The first step was to download the SDK for developing AIR applications. Poryskav on the Internet, found a couple of examples of how to make your first application on AIR.

For the porting, I chose one of my last works - this is the web application www.datamash.us . Datemash is YouTube for widgets. Widgets have now become a new form of media, but so far they can only be created by programmers. Datamash helps ordinary people manage such a new form of content, such as widgets, assembling and connecting internal data streams for them, making them easier to publish. Datamash client interface is implemented on a mixture of Fullajax and ExtJS. PHP server side.

I set myself the following task - to make an application that runs the entire interface from the local file system, but takes business data from the Internet. Starting experiments, going from simple to complex, after an hour I compiled my first AIR application. It turned out that the AIR sandbox has restrictions on the execution of JavaScript — one of them is the execution of eval, which is necessary to assemble objects from JSON responses, the second is the creation and execution of dynamically connected scripts. Looking for information about the security of the sandbox, I found very comprehensive information labs.adobe.com/wiki/index.php/AIR : HTML_Security_FAQ. A little thought, it was decided to make an application that will not be limited to the security of the AIR sandbox. It turns out that such a possibility exists, which was pleasantly surprised. And to do this is simple: you need to load the application’s strata page in the iframe with additional attributes.
<iframe id="UI" style="width:100%;height:100%;border:0" frameborder="0"
src="/chips/index.html"
sandboxRoot="http://www.datamash.us/"
allowCrossDomainXHR="true"
documentRoot="app:/">

Where
sandboxRoot = http: //www.datamash.us/ - defines the area of ​​the sandbox
allowCrossDomainXHR = "true" - indicates the resolution of cross-domain requests
documentRoot = "app: /"> - indicates the base location for relative paths
')
So we got an application that loads the interface from the local file system.
The important point was that at the first stage of development I rendered all the path settings for AJAX requests from the web application into a separate file, and this saved time. It was enough to redefine all the paths in the configuration file to an external site and everything worked as it should.
...
var URL_LOGIN = 'http://datamash.us/system/login.php';
var URL_FOLDERS_LIST = 'http://datamash.us/system/folders.php';
var URL_OBJECT_LIST = 'http://datamash.us/system/objects.php';
var URL_OBJECT_JUMP = 'http://datamash.us/system/jump.php';
...
So I advise you to take all the paths for AJAX requests into a separate configuration file.
There was one problem that I had been busy for about two hours. The problem was that initially with AJAX requests I received empty responses from the server. I have long puzzled why, because everything was done correctly. The problem turned out to be as follows: if I indicated for the iframe
sandboxRoot = http: //www.datamash.us/ and wrote www.datamash.us in the paths
or
sandboxRoot = http: //datamash.us/ and in the paths prescribed datamash.us
In the answer came empty answers. Everything worked only when instructed
sandboxRoot = http: //www.datamash.us/ and in the datamash.us paths
Strange bug.

So, we have a web application that is launched from the local file system and the business takes data from the Internet. Porting a web application to an AIR application was relatively simple and fast. Personally, I liked the AIR technology.
You can look at the resulting application in action by downloading and installing datamash.air

PS: My colleague made a significant observation in the direction of AIR - this technology does not have mechanisms for auto-updating applications. Those. for example, starting once again from the local file system and finding a more recent version of the interface in the outside world it would be great if AIR could automatically download a new version of content to the local file system and run subsequent times with the new interface. Hopefully Adobe will add this feature.

Source: https://habr.com/ru/post/28985/


All Articles