Modifying Stock Applications

From WebOS Internals

Revision as of 08:57, 3 August 2009 by Hopspitfire (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
This page is deprecated.

Please use the much simpler method at Applying Patches instead.


This section includes instructions for modifying the stock WebOS applications to add potentially useful capabilities...and/or remove annoyances. In general, the procedures listed here will normally require you to do the following:

  • Gain access to linux on your device.
  • Remount the file system as read/write: rootfs_open -w
  • Edit HTML, CSS, and/or JavaScript files by following one or more of the tutorials below.
  • Return the system to read-only state: mount -o remount,ro /

Standard caveats apply. If you aren't careful, you may render an application and/or your device non-functional. That said, if you are careful and ensure that you backup each file before you modify it, you should be fine. Worst case, you should be able to roll your changes back and fix any damage that you have done. Thus, we suggest backing up each file on the device before your initial edit. For example, for a file named some_file.js, first execute:

cp -ip some_file.js some_file.bak

Here is a "quick and dirty" backup script that you might want to use if you find yourself making a lot of changes. 1: At the # prompt, vi /opt/bin/backup 2: copy and paste this code:

#!/bin/sh
# This file backups whatever file is called as parameter to the user's home
# dir and adds a timestamp.
# AUTHOR:      firestorm_v1
# Modified by: JackieRipper

if [ -z "$1" ] ; then
	echo "You must specify the file to be copied."
	exit 1
fi

datestamp=$(date +%m%d%y)
source="$1"
destdir="${2:-${HOME}}"
srcname="$(echo "$source" | sed 's|/|_|g')"
dest="${destdir}/${srcname}-backup-${datestamp}"
x=0
until [ ! -f "$dest" ] ; do
#until [ ! -f "$dest" -a ! -d "$dest" ] ; do
	x=$((x + 1))
	dest="${destdir}/${srcname}-backup-${datestamp}.${x}"
done
cp -p "$source" "$dest"
#cp -rp "$source" "$dest"
echo "Backed up $source to $dest"

3: Save and quit VI (Esc, : w q )

4: Give the script execute permissions: chmod +x /opt/bin/backup

Usage: When you want to modify something but want to back it up, run the script with the file (or directory if using the commented version of the until and cp lines) to be backed up as an argument, and optionally a destination folder as a second argument. Though not necessary, it's best to provide the full path to the file to be backed up, so you can easily determine where the backup came from should you need to restore. The slashes will be converted to underscores.

root@castle:/opt/bin# cd /usr/palm/applications/com.palm.app.clock/app/views/ring/
root@castle:/usr/palm/applications/com.palm.app.clock/app/views/ring# ls
ring-scene.html
root@castle:/usr/palm/applications/com.palm.app.clock/app/views/ring# backup /usr/palm/applications/com.palm.app.clock/app/views/ring/ring-scene.html
Backed up /usr/palm/applications/com.palm.app.clock/app/views/ring/ring-scene.html to /var/home/firestorm   (Note, your user's name will show here)

This will save the file you added as a parameter (in this case ring-scheme.html) to your non-root user's home directory (/home/your_username) with today's datestamp on it. It you specified the full path, the slashes will be converted to underscores. If you back up a file more than once, a digit will be appended to the date stamp.

root@castle:/var/home/firestorm# ls
_usr_palm_applications_com.palm.app.clock_app_views_ring_ring-scene.html-backup-062309  pidof-backup-062309
chatview-assistant.js-backup                                                            pidof-backup-062309.1
chatview-assistant.js-backup-062309.1                                                   pidof-backup-062309.2
listview-assistant.js-backup-062309                                                     securityconfig-assistant.js-backup-062309

You then have a dated version to which you can roll back if your changes cause problems with the application.

If you use this backup script (works for file or directory version but ONLY for full path backups) then this corresponding restore script will restore any backup supplied as argument to it's original location (if it is a directory you'll lose ANY changes in the directory more recent than the backup).

#!/bin/sh

# This file restores whatever file is called as parameter
# IF IT WAS backed up with corresponding backup script by firestorm_v1 and JackieRipper
# See: http://predev.wikidot.com/stock-application-mods
# Only works for files backed up using full path (looks for /_ in restore file)
# you have to give a path to the restore file that incluse at least one dir (./ will work)
# and make sure there're no other '/_' in the path
# Also, make sure the are no '_' in the backup directory
# or in the file/directory backed up/to be restored

# Author: Merlin - based on backup

if [ -z "$1" ] ; then
    echo "You must specify the file to be restored."
    exit 1
fi

backup="$1"
restore="$(echo "$backup" | sed 's|.*/_|_|')"

if [ "$restore" = "$backup" ] ; then
    echo "restore only works for files backed up using full path"
    exit 1
fi
restore="$(echo "$restore" | sed 's|_|/|g')"
restore="$(echo "$restore" | sed 's|-backup-.*||')"
rm -rf "$restore"
cp -frp "$backup" "$restore"
echo "Restored $backup to $restore"

Usage:

root@castle:/var/home/root# backup /usr/palm/applications/com.palm.app.ondevicedemo/app
Backed up /usr/palm/applications/com.palm.app.ondevicedemo/app to /home/merlin/backup/_usr_palm_applications_com.palm.app.ondevicedemo_app-backup-20090715
root@castle:/var/home/root# ls -l /usr/palm/applications/com.palm.app.ondevicedemo/app/models/
-rw-r--r--    1 root     root         2937 Jun 16 21:51 podd-video.js
root@castle:/var/home/root# rm /usr/palm/applications/com.palm.app.ondevicedemo/app/models/podd-video.js
root@castle:/var/home/root# restore /home/merlin/backup/_usr_palm_applications_com.palm.app.ondevicedemo_app-backup-2009
0715
Restored /home/merlin/backup/_usr_palm_applications_com.palm.app.ondevicedemo_app-backup-20090715 to /usr/palm/applications/com.palm.app.ondevicedemo/app
root@castle:/var/home/root# ls -l /usr/palm/applications/com.palm.app.ondevicedemo/app/models/
-rw-r--r--    1 root     root         2937 Jun 16 21:51 podd-video.js

Alternatively, if you'd like to keep the original app in your launcher, see this method for copying the entire app as a new app before you begin making mods.

Modify stock app while keeping original in Launcher

Okay, here's the good stuff.

Personal tools
Google AdSense