ben-ng / phonegap-air

Put your web app in the iOS App Store and update it whenever you want.
305 stars 26 forks source link

Pure JS implementation? #11

Open canac opened 9 years ago

canac commented 9 years ago

This looks a really awesome library, and I am looking forward to using it in a current project! I am curious though why you wrote it in Objective-C rather than in cross-platform JavaScript. Were there technical limitations that made a pure JS implementation impossible? I ask because if it is feasible I would consider helping rewrite what you already have in JavaScript so that it will be cross-platform compatible.

ben-ng commented 9 years ago

I'm so glad someone is thinking of doing this in a cross-platform way!

I am not aware of any technical limitations. I wrote it in Objective-C because I understand iOS dev much better than I understand PhoneGap, and needed a reliable system out in a couple of days. I have no idea how reliable this system would be if you implemented it in JS. One nice thing about doing it with native code is that the application could be updated even if it was totally broken (think parse errors, file corruption...)

Let me know if I can help.

canac commented 9 years ago

I am waiting to hear back from my project manager about whether we want OTA update support for Android enough to justify me taking the time to work on porting phonegap-air to JavaScript. I will let you know when I do. If I were to start working on this, it would be helpful to have an overview of what the code does at a level of detail somewhere between what you already have in the README file and the detail of the code of itself. I ask for that because I simply cannot read Objective-C code :smile:.

canac commented 9 years ago

I just heard back from my project manager, and getting phonegap-air to work for Android would be useful for our app, but it is not our highest priority right now. But I will let you know if/when I am given the green light to begin working on this. Thanks for your input and willingness to help!

ben-ng commented 9 years ago

Sure, let me know when you do want to work on this.

Gp2mv3 commented 9 years ago

Why don't you use a mechanism using HTML5 cache ? The idea is to use an HTTP server and to host the important script file with the cache.manifest. The app only has the minimal files which don't do much (an index.html, a js and a css file to display something nice when there is no internet at all for the first launch). The index.html only links the remote files. Then the cache manifest will be triggered and everything will be saved in cache (which is not limited in size I think ?). When an update occurs, simply modify the cache manifest and the resources will be re-fetched.

What do you think ?

ben-ng commented 9 years ago

I am not sure if the method you're proposing is feasible. You should create a simple proof of concept.

Gp2mv3 commented 9 years ago

I thought a bit more about it and in fact no, it will not work so well because of the Same Origin Policy.

However, maybe having a js script that will poll by itself the cache manifest, then download everything in a separated folder if needed and create an array of files to link (css, js). Then it can be in pure js. The only changes to do are to poll the cache manifest (or any other list of file), download everything in the right folder, then add every file in a list that can be read from the embedded script.

I can try to implement something like this.

bfischer1121 commented 9 years ago

For what it's worth, every implementation I've seen has involved saving the scripts to localstorage then eval'ing.

For example, with Sencha Touch the process goes like: index.html loads microloader.js (inlined in production) which loads bootstrap.json. bootstrap.json is a manifest of css/js resources w/ checksums. Microloader compares checksums with checksums of code cached in localstorage. If they don't match, reload the asset files and update localstorage. In the case of Sencha Touch, they have a CLI so they can generate diff files used for delta updates of the assets. Once the microloader gets the assets up to date, it asks the user if they want to refresh the window.

There's an open source library that may follow a similar idea: http://addyosmani.github.io/basket.js/

Gp2mv3 commented 9 years ago

I've something very basic working. It loads a JSON list from a webserver then save the files listed there and load them in the FileSystem. It's working on Chrome currently, the only issue is the path of the files which begins with filesystem://... meaning that there will be a path conversion to think about...

Here is a repository my current tests: https://github.com/Gp2mv3/js-updater