Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Commit

Permalink
Fixed app loading on android, updates to readme, split out app js fro…
Browse files Browse the repository at this point in the history
…m helpers
  • Loading branch information
Fil Maj committed Dec 19, 2011
1 parent 295a443 commit e92cd60
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 103 deletions.
27 changes: 16 additions & 11 deletions README.md
@@ -1,14 +1,20 @@
Hydra
====

![Hydra!](http://github.com/filmaj/hydra/raw/master/img/icon128.png)
![Hydra!](http://github.com/filmaj/hydra/raw/master/img/icon-big.png)

A beast with many heads. Keep one or more [PhoneGap](http://www.phonegap.com) app assets "in the cloud" on
[build.phonegap.com](http://build.phonegap.com), and use this shell to
store different apps and keep each app up-to-date with the latest
assets.
A beast with many heads. Keep one or more [PhoneGap](http://www.phonegap.com) app assets "in the cloud" on [build.phonegap.com](http://build.phonegap.com), and use this shell to store different apps and keep each app up-to-date with the latest assets.

#### iOS ####
# Getting Started

1. Edit the `CALLBACK_ANDROID` and other platform paths at the top of
the `makefile`.
2. Run `make <platform>` to generate the PhoneGap/Callback/Cordova
project under `dist/<platform>`.
3. `cd dist/<platform>` and then run the platform-specific tools to
debug/test/deploy/sign/etc.

## iOS' Special Needs

1. Include libz.dylib in your project
- Xcode 4
Expand All @@ -24,24 +30,23 @@ assets.
2. For the key, add "com.nitobi.BinaryDownloader", and for the value, add "BinaryDownloader"
3. For the key, add "com.nitobi.ZipUtil", and for the value, add "ZipUtil"

3. For PhoneGap 1.1, In PhoneGap.plist, under "ExternalHosts", add these new entries:
3. For PhoneGap 1.1, In PhoneGap.plist, under "ExternalHosts", add these new entries:
* build.phonegap.com
* s3.amazonaws.com
* (any other hosts that your downloaded app needs to connect to - of course you need to know this in advance - or you can use "*" to allow everything)

Why?
----
# Why?

* Easier to manage application updates; a poor man's TestFlight.
* Theoretically more secure. However: be warned I don't know shit about
security.

Contributors
----
# Contributors

* [Fil Maj](http://www.github.com/filmaj)
* [Michael Brooks](http://www.github.com/mwbrooks)
* [Ryan Betts](http://www.github.com/ryanbetts)
* [Joe Bowser](http://www.github.com/infil00p)
* [Shazron Abdullah](http://www.github.com/shazron)
* [Brett Rudd](http://www.github.com/goya)

47 changes: 9 additions & 38 deletions ext/android/AppLoader.java
@@ -1,42 +1,13 @@
package com.phonegap.remote;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.params.ConnManagerPNames;
import org.apache.http.conn.params.ConnPerRouteBean;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Base64;
import java.io.*;
import java.util.*;
import org.apache.http.*;
import org.json.*;

import com.byarger.exchangeit.EasySSLSocketFactory;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.*;

public class AppLoader extends Plugin {

Expand Down Expand Up @@ -77,10 +48,10 @@ private void fetch(JSONArray args) {
String password;
String id;
try {
id = args.getString(1);
url = args.getString(2);
username = args.getString(3);
password = args.getString(4);
id = args.getString(0);
url = args.getString(1);
username = args.getString(2);
password = args.getString(3);

// Create directory for app.
local_path = "/data/data/" + ctx.getPackageName() + "/remote_app/" + id + "/";
Expand Down
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -2,7 +2,7 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi" />
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="js/pretty.js"></script>
<script type="text/javascript" src="js/helpers.js"></script>
<script type="text/javascript" src="js/hydration.js"></script>
<script type="text/javascript" src="js/hydra.js"></script>
<link rel="stylesheet" href="master.css" type="text/css" media="screen" />
Expand Down
51 changes: 51 additions & 0 deletions js/helpers.js
@@ -0,0 +1,51 @@
// constants
var BUILD_URL = 'https://build.phonegap.com';

// Dom helpers
function $(s) { return document.getElementById(s); }

// Extend the String object for simple templating
String.prototype.format = function(){
var args = arguments;
obj = (args.length == 1 && (typeof args[0] == 'object')) ? args[0] : args;
return this.replace(/\{(\w+)\}/g, function(m, i){
return obj[i];
});
}

// helper for XHR
function xhr(url, options) {
var xhr = new XMLHttpRequest();

if (options && options.username && typeof options.password != 'undefined') {
var schemeSeparator = "://";
var extractToIndex = url.indexOf(schemeSeparator) + schemeSeparator.length;
var scheme = url.substring(0, extractToIndex);
var rhs = url.substring(extractToIndex);
url = scheme + encodeURIComponent(options.username) + ':' + encodeURIComponent(options.password) + '@' + rhs;
}

xhr.open('GET', url, (options && typeof options.async != 'undefined'?options.async:true));

if (options && options.headers) {
// Lifted from xui source; github.com/xui/xui/blob/master/src/js/xhr.js
for (var key in options.headers) {
if (options.headers.hasOwnProperty(key)) {
xhr.setRequestHeader(key, options.headers[key]);
}
}
}

xhr.setRequestHeader("Accept", "application/json");

xhr.onreadystatechange = function(){
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 || xhr.status == 0) {
options.callback.call(xhr);
} else {
alert('XHR error, status: ' + xhr.status);
}
}
};
xhr.send((options && options.data? options.data : null));
}
53 changes: 0 additions & 53 deletions js/hydra.js
@@ -1,12 +1,6 @@
(function() {
if (!('localStorage' in window && window['localStorage'] !== null)) alert("No support for localStorage.");

// constants
var BUILD_URL = 'https://build.phonegap.com';

// Dom helpers
function $(s) { return document.getElementById(s); }

function showModal(txt) {
var wrap = $('modal-wrap');
var msg = $('modal-msg');
Expand All @@ -29,52 +23,6 @@
hideModal();
}

// Extend the String object for simple templating
String.prototype.format = function(){
var args = arguments;
obj = (args.length == 1 && (typeof args[0] == 'object')) ? args[0] : args;
return this.replace(/\{(\w+)\}/g, function(m, i){
return obj[i];
});
}

// helper for XHR
function xhr(url, options) {
var xhr = new XMLHttpRequest();

if (options && options.username && typeof options.password != 'undefined') {
var schemeSeparator = "://";
var extractToIndex = url.indexOf(schemeSeparator) + schemeSeparator.length;
var scheme = url.substring(0, extractToIndex);
var rhs = url.substring(extractToIndex);
url = scheme + encodeURIComponent(options.username) + ':' + encodeURIComponent(options.password) + '@' + rhs;
}

xhr.open('GET', url, (options && typeof options.async != 'undefined'?options.async:true));

if (options && options.headers) {
// Lifted from xui source; github.com/xui/xui/blob/master/src/js/xhr.js
for (var key in options.headers) {
if (options.headers.hasOwnProperty(key)) {
xhr.setRequestHeader(key, options.headers[key]);
}
}
}

xhr.setRequestHeader("Accept", "application/json");

xhr.onreadystatechange = function(){
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 || xhr.status == 0) {
options.callback.call(xhr);
} else {
alert('XHR error, status: ' + xhr.status);
}
}
};
xhr.send((options && options.data? options.data : null));
}

// plugin error handler
function pluginError(msg) {
alert('Hydration plugin error!' + msg);
Expand Down Expand Up @@ -273,7 +221,6 @@
// Do nothing; show the login form.
}
}

hideModal();
}, false);
})();

0 comments on commit e92cd60

Please sign in to comment.