WebOS: register your own app as file handler
This is some info I gathered doing enhancing my app iCalImporter. If you like this info here, you could buy this app to show me your appreciation.
Have you ever tried the menu item “Default Apps” (German: Standardanwendungen) in the App Launcher’s menu? Then you know that apps can register for certain file/mime types. But how to do it isn’t documented yet. According to this forums thread one might expect to get some documentations about it rather soon. Until then, Jay Canuck and the WebOSInternals-Team both using some luna-send commands to perform the file type registration for their applications: Internalz and Preware. Translating this luna-sends into proper service calls was easy and looks like this:
this.controller.serviceRequest("palm://com.palm.applicationManager/", { method: 'addResourceHandler', parameters: { "appId": "de.metaviewsoft.icalimporter", "extension": "ical", "mimeType": "text/calendar", "shouldDownload": true }, onSuccess: function() { }.bind(this), onError: function(e) { Mojo.Log.error("Error %j",e); }.bind(this), onFailure: function(e) { Mojo.Log.error("Failure %j",e); }.bind(this) });
After you registered your app with this call, your app will be called by WebOS whenever such a file is to handle. To handle this call you will need to move your app from a simple stage application into a single or multi stage application which uses an app-controller:
- in your appinfo.json set “noWindow”:true,
- remove the stage-assistant.js from your sources.json and add an app-assistant.js to your app
- in your app-assistant.js you add an handleLaunch function with the launchParams as parameters
The app-assitant.js looks usually like this:
var gblLaunchParams; var MainStageName = "main"; function AppAssistant (appController) { } AppAssistant.prototype.handleLaunch = function(launchParams) { // Look for an existing main stage by name. var stageProxy = this.controller.getStageProxy(MainStageName); var stageController = this.controller.getStageController(MainStageName); try { var params = launchParams;//Mojo.getLaunchParameters(); if (typeof(params) == 'object') { gblLaunchParams = params; } else { gblLaunchParams = Object.toJSON(params); } } catch (e) {} if (stageProxy) { // If the stage exists, just bring it to the front by focusing its window. // Or, if it is just the proxy, then it is being focused, so exit. if (stageController) { stageController.window.focus(); } stageProxy.delegateToSceneAssistant("importICal"); } else { // Create a callback function to set up the new main stage // after it is done loading. It is passed the new stage controller // as the first parameter. var pushMainScene = function(stageController) { stageController.pushScene(MainStageName); }; var stageArguments = {name: MainStageName, lightweight: true}; // Specify the stage type with the last property. this.controller.createStageWithCallback(stageArguments, pushMainScene, "card"); } };
“importICal” is a function in my main-assistant.js which reads the file given in gblLaunchParam.target. If your app isn’t already open you still might be called from WebOS with some launch parameters. That’s why I call importICal also from my main-assistant.js setup method.
When using an app-assistant you need to remember that certain calls to access the sceneController aren’t possible anymore. Use this.controller.serviceRequest or this.controller.stageController.
Email attachments are stored in a non-public path. Reading the file using Ajax-Get-Request doesn’t work and results in this error message:
Not allowed to load local resource: file:///var/luna/data/attachments/bucket
Unwiredben gave then the hint to use PalmGetResource() which does the trick in reading from this path.
At the moment calling this API isn’t allowed yet:
Your App Has Been Rejected[...]The following issues were found:
main-assistant.js: found a call to a non-public service: palm://com.palm.applicationManager/addResourceHandler main-assistant.js: found a call to a non-public service: palm://com.palm.applicationManager/addResourceHandler main-assistant.js: found a call to a non-public service: palm://com.palm.applicationManager/addResourceHandler main-assistant.js: found a call to a non-public service: palm://co m.palm.applicationManager/addResourceHandler
And now to something slightly different: Here is an easy 3 steps walk-through of adding scroll fades to your Mojo scenes.
Juli 27, 2010
· admin · No Comments
Posted in: Allgemein
Leave a Reply
You must be logged in to post a comment.