Develop and Configure

Version added 07-Mar-2018| Modified 04-May-2018

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

For easier understanding, the process to create built-in web apps 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

 

Setup Development Environment

Before starting development, you must do the following:

  1. Clone the build-webos repository.

    $ git clone https://github.com/webosose/build-webos.git
  2. Install all required components (on Ubuntu).

    $ sudo scripts/prerequisites.sh
  3. Configure the build.

    $ ./mcf -p 0 -b 0 raspberrypi3
  4. Build the webOS image.

    $ make webos-image

This is only a list of the main steps. For detailed information, see Building webOS OSE and Flashing webOS OSE.

 

Develop the Web App

Web app development can be done using standard web technology. 

If you want to use a webOS service in the web app, follow the steps described in the "Calling webOS Services in Web Apps" section in Web App Overview.

For the sample web app (com.example.app.web), you can create the index.html  file in the root web app folder.

<!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>
</head>
<body>
        <div>
                <h1>Hello, Web Application!!</h1>
        </div>
</body>
</html>

 

appinfo.json

Apps are required to have metadata before they can be packaged. This metadata is stored in a file that 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 web app.

  • Line(7) : The title to be shown on the Launcher on the target device.

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

For more details, see appinfo.json.

 

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 

Non-availability of the README.md file can result in an error at build time.
Make sure the 'Summary' subsection is a single line. Even a blankspace 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 shows the blankspace that can cause the error:

Summary
-------
web app sample
(no blankspace)
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

 

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 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, icon files for each application name in /usr/palm/applications/ on target. To install the files to 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 target. Exclude the files that do not have to be installed to 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.