Skip to content

Instantly share code, notes, and snippets.

@aabytt
Forked from Ircama/LgMagicRemoteKeys.md
Created January 27, 2022 08:06
Show Gist options
  • Save aabytt/90e81bcca3802b0333cbf70ac5fc876e to your computer and use it in GitHub Desktop.
Save aabytt/90e81bcca3802b0333cbf70ac5fc876e to your computer and use it in GitHub Desktop.
Replacing Netflix and Amazon keys of the webOS LG TV LG Magic Remote with other apps

Replacing Netflix and Amazon keys of the webOS LG TV LG Magic Remote with other apps

This procedure allows substituting one or both Netflix and Amazon keys of the Magic Remote Control Unit with other apps or TV control menus of the webOS LG TV.

Netflix and Amazon keys can be found just over the Red-Green-Yellow-Blue color buttons of such remote.

Assumption for this procedure is that you accept to uninstall the apps related to the keys to be substituted. Example: if you want to replace the Netflix key, you need to uninstall Netflix (possibly, you are not using Netflix if you do not need such key).

To uninstall Netflix or Amazon Prime, press the Home key of the Magic Remote, select the "LG Content Store" app, press "APP" at the top of the screen, press "My Apps", press the "Remove" button at the top-right corner and select the apps you want to remove.

Also, you need to setup your LG TV in developer mode. If the service you need to start is a webOS App that you already can recompile, simply change its "id" in appinfo.json. Otherwise, you have to install specific webOS apps that launch the features that you need to activate by pressing the keys. The following steps help to setup the environment, develop the launcher apps, compile and install them on the TV.

Follow the instructions in App Testing page to:

Follow Deploying a Web App page to get acquainted with the CLI usage.

At the end of the previous steps, open the "webOS TV CLI" app on your PC. The following procedure is tested with Windows 10. The apps are tested on webOS TV release 4.1.4, API 4.1.0.

To connect to your TV, you might want to get your passphrase; this can be done through the "Developer mode" app on the TV or with the following command:

ares-setup-device -listfull | findstr "passphrase"

Notice that the passphrase is case sensitive.

With the following command, check the configured name of your TV device (deviceinfo: prisoner@...):

ares-setup-device -list

this is the same as:

ares-device-info --device-list

The output should be:

name      deviceinfo                   connection  profile
--------  ---------------------------  ----------  -------
oled      prisoner@<ip address>:9922   ssh         tv
emulator  developer@<ip address>:6622  ssh         tv

We suppose that the label used to reach your TV is "oled".

Check proper connection by retrieving the system information of your TV:

ares-device-info --device oled

You need to have developer mode active to connect (run the "Developer Mode" app and check that Dev Mode Status is ON). Also check your IP address. If it needs to be changed, run ares-setup-device and modify your TV configuration (oled).

First you need to discover the App ID of the applications you need to connect to the keys. Run the app you want to start. The following command allows to discover most of the appIds running on your TV.

ares-novacom --device oled --run "ps -ef|sed -n '/sed -n/d;/appId/{s/.*appId.:\([^,]*\).*/\1/;p;}'"

After discovering the ID, use the command ares-launch --device oled <appid> to test launching the app from your PC.

Here are some app ID that you can check:

ares-launch --device oled com.webos.app.livetv
ares-launch --device oled com.webos.app.hdmi1
ares-launch --device oled com.palm.app.settings
ares-launch --device oled com.webos.app.browser
ares-launch --device oled com.webos.app.photovideo
ares-launch --device oled com.webos.app.discovery
ares-launch --device oled com.webos.app.connectionwizard
ares-launch --device oled com.webos.app.miracast
ares-launch --device oled com.webos.app.notificationcenter
ares-launch --device oled com.webos.app.tvuserguide
ares-launch --device oled com.webos.app.scheduler
ares-launch --device oled com.webos.app.channelsetting
ares-launch --device oled spotify-beehive
ares-launch --device oled amazon
ares-launch --device oled netflix

Notice that the last two ones, amazon and netflix, should not be installed.

There are configuration files like this one in webOS, that are references for the OS action of WebOS.Key_webOS_Netflix and WebOS.Key_webOS_Amazon keys, that by default run appId = "netflix" and appId = "amazon" respectively. Check this for instance:

ares-novacom --device oled --run "cat /usr/lib/qt5/qml/KeyFilters/appLaunch.js"|clip

The previous command copies the file to the clipboard. Paste it to an editor (e.g., Notepad++) to inspect the file. All OS files are readonly and cannot be changed. Anyway, if amazon and netflix apps are not installed, the related appIds can be resused by app launchers.

Let us consider you want to substitute netflix with youtube, so that when pressing the netflix key, youtube is launched.

Test launching Youtube from your PC:

ares-launch --device oled youtube.leanback.v4

You can discover "youtube.leanback.v4" appId with the previously described method.

Now we need to create the launcher app. Read Build Your First App for webOS TV to understand how to create an app using the CLI.

Change directory to your local development path (let us consider Downloads for instance):

cd %HOMEPATH%\Downloads

Use ares-generate to create the basic Web App template for webOS TV. Let us call it "launcher". We need to set the custom property id to the name of the key. netflix in our case. Title should be set to a description name related to the launched app:

ares-generate -t basic -p "id=netflix" -p "title=YouTube App Launcher with the Netflix key" -p "vendor=open source" -p "transparent=true" launcher

The previous command creates the launcher directory, including a working source.

Edit appinfo.json in the launcher directory and remove the double quotes from the true value of transparent parameter, so that it is set as follows:

  "transparent": true

Other App Metadata can be optionally set, but are not strictly necessary.

Replace the index.html file in the launcher directory with the following:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=1920, user-scalable=no">
	<script src="webOSTVjs-1.2.0/webOSTV.js" charset="utf-8"></script>
	<script src="webOSTVjs-1.2.0/webOSTV-dev.js" charset="utf-8"></script>
	<script type="text/javascript">
    (function() {
        // Launching app without parameter
        var request = webOS.service.request("luna://com.webos.applicationManager", {
            method: "launch",
            parameters: { "id": "youtube.leanback.v4" },
            onSuccess(response) {
              window.close();
            },
            onFailure(error) {
              window.close();
            },
        });
    })();
	</script>
</head>
<body>
</body>
</html>

We use the webOS.service.request LS2 API to call a webOS Service from the Web App, including the appropriate URI (e.g., luna://com.webos.applicationManager), method (launch), parameters ({ "id": "<appId>" }) and setting up callbacks to close the application.

The id parameter in the javascript shall be assigned to the feature or the app to launch; in our case, YouTube is youtube.leanback.v4:

            parameters: { "id": "youtube.leanback.v4" },

Create a package with the name of the original ID (in our case, netflix):

ares-package launcher

The local directory will include a file named with the original ID of the application, followed by the version and "_all.ipk" (netflix_0.0.1_all.ipk in our case).

Install the created app to the TV:

ares-install --device oled netflix_0.0.1_all.ipk

Done.

Note. Connecting your TV via SSH is not needed. In case you have SSH installed and you want to test it, use the following command:

ssh -i %HOMEPATH%\.ssh\oled_webos prisoner@<ip address> -p 9922 "/bin/bash -i"

Custom installed applications are stored in folder /media/developer/apps/usr/palm/applications/. Files can be edited online.

Notice that luna-send is protected and luna-send-pub should be used instead:

# Get TV data:
luna-send-pub -n 1 -f luna://com.palm.systemservice/osInfo/query '{ "subscribe": false }'
cat /var/run/nyx/device_info.json
cat /var/run/nyx/os_info.json

# Start YouTube application
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{ "id": "youtube.leanback.v4" }'

# Run Netflix application
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "netflix", "params":{}}'

# Welcome popup 
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.mystarter", "params": {}}'

# Configuration menu:
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"picture"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"sound"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"channel"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"network"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"general"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"accessibility"}}'

# Show TV User Guide:
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.tvuserguide"}'

# Switch to TV
luna-send-pub -n 1 "luna://com.webos.applicationManager/launch" '{ "id": "com.webos.app.livetv" }'

# Toggle TV/Radio
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.livetv", "params": {"id":"tvKey"}}'

# Subtitle menu
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.tvhotkey", "params": {"activateType":"subtitle"}}'

# Multi-sound menu
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.tvhotkey", "params": {"activateType":"multi-sound-setting"}}'

# Audio-description
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.tvhotkey", "params": {"activateType":"audio-description"}}'

# Channel menu
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.livemenu", "params": {"activateType":"channels"}}'

# Virtual keyboard Search
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.voice", "params": {"activateType":"mrcu", "launchMode":"vkb"}}'

# listing launch points is not allowed:
luna-send-pub -n 1 "luna://com.palm.applicationManager/listLaunchPoints" "{}"

# Also, closing an application or getting app info is denied:
luna-send-pub -n 1 -f "luna://com.webos.service.applicationmanager/closeByAppId" '{"id":"youtube.leanback.v4"}'
luna-send-pub -n 1 -f "luna://com.webos.service.applicationmanager/getAppInfo" '{"id":"youtube.leanback.v4"}'
luna-send-pub -n 1 -f "luna://com.webos.service.applicationmanager/getForegroundAppInfo" '{}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment