More Web OS programming - Adding Models, Views, Controllers to your project.


In WebOS programming everything is about conventions, you create a  certain assistant in the predefined folder with a predefined name. The same for models, views, stylesheets, etc.
This makes the app structure very simple ;)

This is the continuation of the last post so here I go again...

Creating Assistant (or Controllers), Scenes (Views) and Models

In WebOS each scene needs an assistant. Hence creating a scene creates a view and its controller at the same time:

$pwd
/Users/nacho4d/Documents/palmWorkspace
$palm-generate -t new_scene -p "name=myView" Superapp

which means: generate a new scene for Superapp project using the template new_scene and its name is going to be myView.

palm-generate will create a myView-assistant.js file inside Superapp/app/assistants directory and a myView-scene.html file inside a new myView directory inside app, like so:
Superapp/app/myView/myView-scene.html
and finally will add the path of both new files to Superapp/sources.json file. If you prefer it, you can do this process manually and everything will work and give you the possibility of customizing names and places of your new files ;) But that is beyond this post.

There are 4 templates for palm-generate (-t option) and the default is new_app

hello_app        Generates a new application containing a "Hello World" scene.
hello_scene     Generates a "Hello World" scene.
new_app         Generates a new (empty) application.
new_scene      Generates a new (empty) scene.

We do the same process for Models, but manually since there is no template in palm-generate for this.

Create a directory models inside app.
Create a myModel.js and add its path to sources.json file.

So if you create a boxView and its assistant (or controller):
$palm-generate -t new_scene -p "name=boxView" Superapp

and created a box model:
$cd Superapp/app
$mkdir models
$cd models
$touch box.js
$cd ../../
$open sources.json -a Coda.app
then add box.js path like so:

[
    {
     "source": "app/assistants/stage-assistant.js"
    },
    {
        "scenes": "boxView",
        "source": "app/assistants/boxView-assistant.js"
    },
    {
     "source": "app/models/box.js"
    }
]

finally your project should have the following structure:


Be carefull and not make mistakes specially in the paths. (It took me one hour to realize the reason my app was not loading correctly was I missed adding the ','  after the second element of the array in sources.json!! lol)

Web OS programming - My very first Palm Pre 2 app (that really does nothing!)

I find programming model in WebOS very intuitive and easy. I really like it and even though I have no real device to test anything, there is an emulator and I think is very complete (probably better than the first iPhone Simulator app)

These are some notes on how to create Palm Pre apps using Terminal in the Mac but this should not be different in any other Unix like OS.
There is a Eclipse Plugin that should make things easier but I don't like very much Eclipse, is kind of sluggish, I prefer Xcode or NetBeans but there are no Web OS Development official plugins for these IDEs now. So my best choice is Terminal + Coda (Coda is awesome!!).
Moreover, Coda has Terminal inside of it so no need to really open Terminal.app in the Mac.

  • Download and install the SDK and Emulator (needs Virtual Box), follow instructions from here
  • Open the terminal and do:
//Step1: create a workspace directory
$mkdir palmWorkspace
$cd palmWorkspace

//Step2: create a project with name HelloWorld
$palm-generate -p "{title:'Hello World', id:com.nacho4d.hello, version:'1.0.0'}" HelloWorld
generating new_app in /Users/nacho4d/Documents/palmWorkspace/HelloWorld

//Step3: package the project (something equivalent to building an iPhone app)
$ palm-package Helloworld
creating package com.nacho4d.hello_1.0.0_all.ipk in /Users/nacho4d/Documents/palmWorkspace

//Step4: install the packaged project in the connected device, if none then install in the Emulator *4
$palm-install com.nacho4d.hello_1.0.0_all.ipk 
installing package com.nacho4d.hello_1.0.0_all.ipk on device "emulator" {41270192eca5e9403d535ba2f9e40b4483cda4ac} tcp 50997

//Step5: start the app
$ palm-launch com.nacho4d.hello               
launching application com.nacho4d.hello on device "emulator" {41270192eca5e9403d535ba2f9e40b4483cda4ac} tcp 50997

//Step6: close your app through a command. 
$palm-install -c com.nacho4d.hello_1.0.0_all.ipk
closing application com.nacho4d.hello on device "emulator" {41270192eca5e9403d535ba2f9e40b4483cda4ac} tcp 50997 


Now, regarding...

Step 2: palm-generate [OPTION...] APP_DIR
palm-generate -p option is optional. Hence, you could do $palm-generate HelloWorld and would create an app with title: HelloWorld id:com.yourdomain.helloworld and version:1.0.0.

Step 3: palm-package [OPTION...] APP_DIR
I said this step is something like building an iPhone but I don't think you will get any errors here. everything is HTML and Javascript so, you have to validate/check your code by yourself.

Step4: palm-install [OPTION...] [PACKAGE | APP_ID]
If your are using the emulator, you must start it manually(palm-install won't start it for you) but , starting it just before running this command probably will end in something like this:

$ palm-install com.nacho4d.hello_1.0.0_all.ipk 
palm-install: no devices found
palm-install: no device found

The first message is for real devices and the second is for the emulator. It seems that the emulator is not immediately available just after starting it. So, better start it at packaging time.

Step5: palm-launch [OPTION...] [APP_ID]

Step6: you can also close the app using the Emulator by swiping your app up. (I am very new to PalmPre and I didn't knew this ;) )


If your are using Coda, then do everything inside its built-in terminal!



You can even open the your workspace directory from its terminal, So won't even need the Finder. ;)

$cd palmWorkspace/
$open . -a Coda.app
... and do as usual ;)






Universal Ports


This is just a note for myself rather than a post... is just I always forget this:

sudo port upgrade --enforce-variants portname +universal

where portname should be replaced appropriately.

This work is licensed under BSD Zero Clause License | nacho4d ®