Develop and Configure

Version added 07-Mar-2018| Modified 28-Oct-2018

To create a built-in web app, you must write the source code and prepare the required configuration files.

For easier understanding, the process to create a built-in web app is explained using the example of a web app named com.example.app.web that responds with the string "Hello, Web Application!!".

The directory structure of com.example.app.web must be as follows:

com.example.app.web
├── CMakeLists.txt
├── README.md
├── appinfo.json
├── icon.png
├── index.html
└── webOSjs-0.1.0
    ├── LICENSE-2.0.txt
    └── webOS.js

Prerequisites

Before you begin developing the built-in web app, you must:

  • Build and flash the webOS OSE image. For detailed information, see Building webOS OSE and Flashing webOS OSE.

  • Create a project directory (com.example.app.web) for the sample web app.

$ mkdir com.example.app.web

Developing the Web App

You can develop a web app using standard web technologies. 

Web apps built for webOS devices can also provide enhanced functionality by leveraging the APIs provided by webOS services. Let us understand this with a sample code that prints a hello message and also prints the current time on the console.

Prerequisite (when calling webOS service in the web app): Download the webOS library file from webOSjs-0.1.0.zip and decompress it to the source code directory. This library is required to call LS2 API.

For the sample web app (com.example.app.web), create the index.html  file in the project root directory.

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
                width: 100%;
                height: 100%;
                background-color: #202020;
}
div {
            position:absolute;
                height:100%;
                width:100%;
                display: table;
}
h1 {
            display: table-cell;
                vertical-align: middle;
                text-align:center;
                color: #FFFFFF;
}
</style>
        <script src="webOSjs-0.1.0/webOS.js" charset="utf-8"></script>
        <script type="text/javascript">
        //sample code for calling LS2 API
        var lunaReq= webOS.service.request("luna://com.webos.service.systemservice",
        {
            method:"clock/getTime",
            parameters:{},
            onSuccess: function (args) {
                                console.log("UTC:" + args.utc);
            },
            onFailure: function (args) {
            }
        });
        </script>
</head>
<body>
        <div>
                <h1>Hello, Web Application!!</h1>
        </div>
</body>
</html>

A brief explanation of the webOS-specific lines of code:

  • Line(23) : Include the webOS.js JavaScript file.

  • Line(24~36) : Define a JS script that calls the luna://com.webos.service.systemservice/clock/getTime method. If it succeeds, it prints the UTC value to console (/var/log/messages file on target).

README.md

This file provides general information of the web app. For the sample web app (com.example.app.web), you must:

  • Create and update the file : README.md

    • Directory : com.example.app.web 

If the REAMD.md file is missing, a build error occurs.
Make sure the 'Summary' subsection is a single line. Even a blank space before the 'Description' section is considered a part of the summary and can cause the build to fail. 
Here is a snippet of the README.md file that will not cause a build error. Any whitespace character in the red-colored line would cause a build error.

Summary
-------
web app sample
(no blank space)
Description
-----------

Sample File

Summary
-------
web app sample

Description
-----------

web app sample

How to Build on Linux
---------------------

## Dependencies

Below are the tools and libraries (and their minimum versions) required to build sample program:

* cmake (version required by cmake-modules-webos)
* gcc
* glib-2.0
* make
* cmake-modules-webos
 
## Building
 
    $ cd build-webos
    $ source oe-init-build-env
    $ bitbake com.example.app.web
 
Copyright and License Information
=================================
Unless otherwise specified, all content, including all source code files and
documentation files in this repository are:
 
Copyright (c) 2018 LG Electronics, Inc.
 
Licensed 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.
 
SPDX-License-Identifier: Apache-2.0

Configuration Files

This section describes how to prepare the configuration files required to build and test the built-in web app.

appinfo.json

Apps are required to have metadata before they can be packaged. This metadata is stored in a file called appinfo.json, which is used by the webOS device to identify the app, its icon, and other information that is needed to launch the app. For the sample web app (com.example.app.web), you must:

  • Create and update the file : appinfo.json

    • Directory : com.example.app.web

{
  "id": "com.example.app.web",
  "version": "0.0.1",
  "vendor": "My Company",
  "type": "web",
  "main": "index.html",
  "title": "Web app sample",
  "icon": "icon.png"
}

A brief explanation of the above file:

  • Line(2) : The ID for the app.

  • Line(5) : The type of the web app.

  • Line(7) : The title to be shown on the Home Launcher app.

  • Line(8) : The icon to be shown on the Home Launcher app. Make sure the icon file is available in the project root directory. You can use your own icon.png (80*80) file or attached icon.png.

For more details, see appinfo.json.

CMakeLists.txt

This file is required to generate the standard build files. For the sample web app (com.example.app.web), you must:

  • Create and update the file : CMakeLists.txt

    • Directory : com.example.app.web

cmake_minimum_required(VERSION 2.8.7)
project(com.example.app.web NONE)
include(webOS/webOS)
webos_modules_init(1 0 0 QUALIFIER RC4)
 
set(INSTALL_DIR ${WEBOS_INSTALL_WEBOS_APPLICATIONSDIR}/${CMAKE_PROJECT_NAME})
#install necessary files to destination directory
install(DIRECTORY . DESTINATION ${INSTALL_DIR}
        PATTERN "*~" EXCLUDE
        PATTERN "CMake*" EXCLUDE
        PATTERN "build*" EXCLUDE
        PATTERN "README.md" EXCLUDE
        PATTERN "oe-*" EXCLUDE
        PATTERN "*.lock" EXCLUDE)

A brief explanation of the above file:

  • Line(2) : Specify the project name and the file extension type. In this tutorial, we use "com.example.app.web" as the project name for indicating various filenames and pathnames. The file extension type "NONE" allows CMake to skip unnecessary compiler checks.

  • Line(3) : Include webOS OSE modules for the build.

  • Line(4) : Specify the "cmake-modules-webos" version.

  • Line(6) : The built-in app must have source codes, appinfo.json, and icon files for each application name in /usr/palm/applications/ on the target. To install the files to the target, set /usr/palm/applications/com.example.app.web as the path.

  • Line(8~14) : Install the required files to /usr/palm/applications/com.example.app.web on the target. Exclude the files that do not have to be installed to the target device. 

Except as noted, this content is licensed under Creative Commons Attribution 4.0 and sample code is licensed under Apache License 2.0.