You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by he...@apache.org on 2012/11/29 01:27:19 UTC

[2/2] js commit: Added pause/resume document events mapped to sysmgr calls, added online/offline document events mapped to network connection service

Added pause/resume document events mapped to sysmgr calls, added online/offline document events mapped to network connection service


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/75f2fa6d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/75f2fa6d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/75f2fa6d

Branch: refs/heads/master
Commit: 75f2fa6d075f632e138c4120283c44caa5dc03e7
Parents: fdfefbf
Author: Markus Leutwyler <ml...@yahoo.com>
Authored: Thu Nov 22 15:27:30 2012 +0100
Committer: hermwong <he...@gmail.com>
Committed: Wed Nov 28 16:27:06 2012 -0800

----------------------------------------------------------------------
 lib/webos/platform.js |   64 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 60 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/75f2fa6d/lib/webos/platform.js
----------------------------------------------------------------------
diff --git a/lib/webos/platform.js b/lib/webos/platform.js
index cc3f6d4..1d02f15 100644
--- a/lib/webos/platform.js
+++ b/lib/webos/platform.js
@@ -19,16 +19,72 @@
  *
 */
 
+var service=require('cordova/plugin/webos/service'),
+    cordova = require('cordova');
+
 module.exports = {
     id: "webos",
     initialize: function() {
         if (window.PalmSystem) {
             window.PalmSystem.stageReady();
         }
-        window.Mojo = window.Mojo || {};
-        window.Mojo.stageActivated = function() {
-            console.error("stageActivated");
-        };
+
+        var Mojo = window.Mojo || {};
+
+        // wait for deviceready before listening and firing document events
+        document.addEventListener("deviceready", function () {
+
+            // LunaSysMgr calls this when the windows is maximized or opened.
+            window.Mojo.stageActivated = function() {
+                console.log("stageActivated");
+                cordova.fireDocumentEvent("resume");
+            };
+            // LunaSysMgr calls this when the windows is minimized or closed.
+            window.Mojo.stageDeactivated = function() {
+                console.log("stageDeactivated");
+                cordova.fireDocumentEvent("pause");
+            };
+            // LunaSysMgr calls this when a KeepAlive app's window is hidden
+            window.Mojo.hide = function() {
+                console.log("hide");
+            };
+            // LunaSysMgr calls this when a KeepAlive app's window is shown
+            window.Mojo.show = function() {
+                console.log("show");
+            };
+
+            // LunaSysMgr calls this whenever an app is "launched;" 
+            window.Mojo.relaunch = function() {
+                // need to return true to tell sysmgr the relaunch succeeded.
+                // otherwise, it'll try to focus the app, which will focus the first
+                // opened window of an app with multiple windows.
+                console.log("relaunch");
+                return true;
+            };
+
+            // start to listen for network connection changes
+            service.Request('palm://com.palm.connectionmanager', {
+                method: 'getstatus',
+                parameters: { subscribe: true },
+                onSuccess: function (result) {
+                    console.log("subscribe:result:"+JSON.stringify(result));
+
+                    if (!result.isInternetConnectionAvailable) { 
+                        if (navigator.onLine) {
+                            console.log("Firing event:offline");
+                            cordova.fireDocumentEvent("offline");
+                        }
+                    } else {
+                        console.log("Firing event:online");
+                        cordova.fireDocumentEvent("online");
+                    }
+                },
+                onFailure: function(e) {
+                    console.error("subscribe:error");
+                }
+            });
+
+        });
     },
     clobbers: {
         requestFileSystem:{