Permalink
Browse files

Added pause/resume document events mapped to sysmgr calls, added onli…

…ne/offline document events mapped to network connection service
  • Loading branch information...
ghtomcat authored and hermwong committed Nov 22, 2012
1 parent fdfefbf commit 75f2fa6d075f632e138c4120283c44caa5dc03e7
Showing with 60 additions and 4 deletions.
  1. +60 −4 lib/webos/platform.js
View
@@ -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:{

0 comments on commit 75f2fa6

Please sign in to comment.