cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject webos commit: CB-8417 moved platform specific js into platform
Date Sat, 07 Feb 2015 01:45:52 GMT
Repository: cordova-webos
Updated Branches:
  refs/heads/master e3ea795a3 -> 4b02d5f43


CB-8417 moved platform specific js into platform


Project: http://git-wip-us.apache.org/repos/asf/cordova-webos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-webos/commit/4b02d5f4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-webos/tree/4b02d5f4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-webos/diff/4b02d5f4

Branch: refs/heads/master
Commit: 4b02d5f438b52b55e6345830fad15f8d6011f147
Parents: e3ea795
Author: Steve Gill <stevengill97@gmail.com>
Authored: Fri Feb 6 17:45:46 2015 -0800
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Fri Feb 6 17:45:46 2015 -0800

----------------------------------------------------------------------
 cordova-js-src/exec.js          |  35 +++++++++++
 cordova-js-src/platform.js      |  86 +++++++++++++++++++++++++
 cordova-js-src/webos/service.js | 118 +++++++++++++++++++++++++++++++++++
 3 files changed, 239 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-webos/blob/4b02d5f4/cordova-js-src/exec.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/exec.js b/cordova-js-src/exec.js
new file mode 100644
index 0000000..2a0e0d8
--- /dev/null
+++ b/cordova-js-src/exec.js
@@ -0,0 +1,35 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var execProxy = require('cordova/exec/proxy');
+
+module.exports = function(success, fail, service, action, args) {
+    var proxy = execProxy.get(service,action);
+    if(proxy) {
+        try {
+            proxy(success, fail, args);
+        } catch(e) {
+            console.log("Exception calling exec with command :: " + service + " :: " + action
 + " ::exception=" + e);
+        }
+    } else {
+        fail && fail("Missing Command Error");
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-webos/blob/4b02d5f4/cordova-js-src/platform.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/platform.js b/cordova-js-src/platform.js
new file mode 100644
index 0000000..965a6ad
--- /dev/null
+++ b/cordova-js-src/platform.js
@@ -0,0 +1,86 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+module.exports = {
+    id: 'webos',
+    bootstrap: function() {
+        var channel = require('cordova/channel');
+        var isLegacy = ((navigator.userAgent.indexOf("webOS")>-1) || (navigator.userAgent.indexOf("hpwOS")>-1));
+        var webOSjsLib = (window.webOS!==undefined);
+        if(!webOSjsLib && window.PalmSystem && window.PalmSystem.stageReady
&& isLegacy) {
+            window.PalmSystem.stageReady();
+        }
+        
+        // create global legacy Mojo object if it does not exist
+        window.Mojo = window.Mojo || {};
+
+        // Check for support for page visibility api
+        if(typeof document.webkitHidden !== "undefined") {
+            document.addEventListener("webkitvisibilitychange", function(e) {
+                if(document.webkitHidden) {
+                    channel.onPause.fire();
+                } else {
+                    channel.onResume.fire();
+                }
+            });
+        } else { //backward compatability with webOS devices that don't support Page Visibility
API
+            // LunaSysMgr calls this when the windows is maximized or opened.
+            window.Mojo.stageActivated = function() {
+                channel.onResume.fire();
+            };
+            // LunaSysMgr calls this when the windows is minimized or closed.
+            window.Mojo.stageDeactivated = function() {
+                channel.onPause.fire();
+            };
+        }
+
+        if(isLegacy && !webOSjsLib) {
+            var lp = JSON.parse(PalmSystem.launchParams || "{}") || {};
+            window.cordova.fireDocumentEvent("webOSLaunch", {type:"webOSLaunch", detail:lp});
+            // LunaSysMgr calls this whenever an app is "launched;"
+            window.Mojo.relaunch = function(e) {
+                var lp = JSON.parse(PalmSystem.launchParams || "{}") || {};
+                if(lp['palm-command'] && lp['palm-command'] == 'open-app-menu') {
+                    window.cordova.fireDocumentEvent("menubutton");
+                    return true;
+                } else {
+                    window.cordova.fireDocumentEvent("webOSRelaunch", {type:"webOSRelaunch",
detail:lp});
+                }
+            };
+        }
+        document.addEventListener("keydown", function(e) {
+            // back gesture/button varies by version and build
+            if(e.keyCode == 27 || e.keyIdentifier == "U+1200001" ||
+                    e.keyIdentifier == "U+001B" || e.keyIdentifier == "Back") {
+                window.cordova.fireDocumentEvent("backbutton", e);
+            }
+        });
+        // SmartTV webOS uses HTML5 History API, so bind to that
+        // Leave freedom upto developers to enforce History states as they please
+        // rather than enforcing particular states
+        window.addEventListener("popstate", function(e) {
+            window.cordova.fireDocumentEvent("backbutton", e);
+        });
+
+        require('cordova/modulemapper').clobbers('cordova/webos/service', 'navigator.service');
+        channel.onNativeReady.fire();
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-webos/blob/4b02d5f4/cordova-js-src/webos/service.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/webos/service.js b/cordova-js-src/webos/service.js
new file mode 100644
index 0000000..0e4b111
--- /dev/null
+++ b/cordova-js-src/webos/service.js
@@ -0,0 +1,118 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var isLegacy = ((navigator.userAgent.indexOf("webOS")>-1) || (navigator.userAgent.indexOf("hpwOS")>-1));
+
+function LS2Request(uri, params) {
+    this.uri = uri;
+    params = params || {};
+    if(params.method) {
+        if(this.uri.charAt(this.uri.length-1) != "/") {
+            this.uri += "/";
+        }
+        this.uri += params.method;
+    }
+    if(typeof params.onSuccess === 'function') {
+        this.onSuccess = params.onSuccess;
+    }
+    if(typeof params.onFailure === 'function') {
+        this.onFailure = params.onFailure;
+    }
+    if(typeof params.onComplete === 'function') {
+        this.onComplete = params.onComplete;
+    }
+    this.params = (typeof params.parameters === 'object') ? params.parameters : {};
+    this.subscribe = params.subscribe || false;
+    if(this.subscribe) {
+        this.params.subscribe = params.subscribe;
+    }
+    if(this.params.subscribe) {
+        this.subscribe = this.params.subscribe;
+    }
+    this.resubscribe = params.resubscribe || false;
+    this.send();
+}
+
+LS2Request.prototype.send = function() {
+    if(!window.PalmServiceBridge) {
+        console.error("PalmServiceBridge not found.");
+        return;
+    }
+    this.bridge = new PalmServiceBridge();
+    var self = this;
+    this.bridge.onservicecallback = this.callback = function(msg) {
+        var parsedMsg;
+        if(self.cancelled) {
+            return;
+        }
+        try {
+            parsedMsg = JSON.parse(msg);
+        } catch(e) {
+            parsedMsg = {
+                errorCode: -1,
+                errorText: msg
+            };
+        }
+        if((parsedMsg.errorCode || parsedMsg.returnValue===false) && self.onFailure)
{
+            self.onFailure(parsedMsg);
+            if(self.resubscribe && self.subscribe) {
+                self.delayID = setTimeout(function() {
+                    self.send();
+                }, LS2Request.resubscribeDelay);
+            }
+        } else if(self.onSuccess) {
+            self.onSuccess(parsedMsg);
+        }
+        if(self.onComplete) {
+            self.onComplete(parsedMsg);
+        }
+        if(!self.subscribe) {
+            self.cancel();
+        }
+    };
+    this.bridge.call(this.uri, JSON.stringify(this.params));
+};
+
+LS2Request.prototype.cancel = function() {
+    this.cancelled = true;
+    if(this.resubscribeJob) {
+        clearTimeout(this.delayID);
+    }
+    if(this.bridge) {
+        this.bridge.cancel();
+        this.bridge = undefined;
+    }
+};
+
+LS2Request.prototype.toString = function() {
+    return "[LS2Request]";
+};
+
+LS2Request.resubscribeDelay = 10000;
+
+module.exports = {
+    request: function (uri, params) {
+        var req = new LS2Request(uri, params);
+        return req;
+    },
+    systemPrefix: ((isLegacy) ? "com.palm." : "com.webos."),
+    protocol: "luna://"
+};


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message