public void LaunchAppWithInfo(AppInfo appInfo, Object ps, ResponseListener listener)
        {
            var appName = HttpMessage.Encode(appInfo.Name);
            var appId = appInfo.Id;
            string contentId = null;
            JsonObject mps = null;
            var o = ps as JsonObject;
            if (o != null)
                mps = o;

            if (mps != null)
            {
                contentId = mps.GetNamedString("contentId");
            }

            LaunchApplication(appName, appId, contentId, listener);
        }
        public void GetApplication(string appName, ResponseListener listener)
        {
            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var strObj = LoadEventArgs.GetValue<string>(loadEventArg);

                    var appId = new AppInfo(Util.DecToHex(strObj));

                    if (!string.IsNullOrEmpty(strObj))
                    {
                        Util.PostSuccess(listener, appId);
                    }
                },
                serviceCommandError =>
                {
                    if (listener != null)
                        Util.PostError(listener, serviceCommandError);
                }
            );

            var uri = UdapPathApptoappData + appName;
            var requestUrl = GetUdapRequestUrl(uri);

            var command = new ServiceCommand(this, requestUrl, null, responseListener) { HttpMethod = ServiceCommand.TypeGet };
            command.Send();
        }
 public void LaunchAppWithInfo(AppInfo appInfo, ResponseListener listener)
 {
     LaunchAppWithInfo(appInfo, null, listener);
 }
        public void ShowClickableToastForApp(string message, AppInfo appInfo, JsonObject ps, string iconData, string iconExtension, ResponseListener listener)
        {
            var payload = new JsonObject();

            try
            {
                payload.Add("message", JsonValue.CreateStringValue(message));

                if (iconData != null)
                {
                    payload.Add("iconData", JsonValue.CreateStringValue(iconData));
                    payload.Add("iconExtension", JsonValue.CreateStringValue(iconExtension));
                }

                if (appInfo != null)
                {
                    var onClick = new JsonObject {{"appId", JsonValue.CreateStringValue(appInfo.Id)}};
                    if (ps != null)
                    {
                        onClick.Add("params", ps);
                    }
                    payload.Add("onClick", onClick);
                }
            }
            catch
            {

            }

            SendToast(payload, listener);
        }
        public ServiceCommand GetRunningApp(bool isSubscription, ResponseListener listener)
        {
            var responseListener = new ResponseListener
                (
                loadEventArg =>
                {
                    var jsonObj = (JsonObject)(((LoadEventArgs)loadEventArg).Load.GetPayload());
                    var appInfo = new AppInfo(jsonObj.GetNamedString("appId"))
                    {
                        Name = jsonObj.GetNamedString("title", ""),
                        RawData = jsonObj
                    };
                    Util.PostSuccess(listener, appInfo);
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
                );

            var request = isSubscription
                ? new UrlServiceSubscription(this, ForegroundApp, null, true, responseListener)
                : new ServiceCommand(this, ForegroundApp, null, responseListener);

            request.Send();

            return request;
        }
        public void LaunchYouTube(string contentId, float startTime, ResponseListener listener)
        {
            var ps = new JsonObject();
            if (!string.IsNullOrEmpty(contentId))
            {
                if (startTime < 0.0)
                {
                    Util.PostError(listener, new ServiceCommandError(0, "Start time may not be negative"));
                    return;
                }

                try
                {
                    ps.Add("contentId",
                        JsonValue.CreateStringValue(String.Format("{0}&pairingCode={1}&t={2}", contentId,
                            Guid.NewGuid(), startTime)));
                }
                catch
                {
                }
            }

            var appInfo = new AppInfo("youtube.leanback.v4")
            {
                Name = "YouTube"
            };

            LaunchAppWithInfo(appInfo, ps, listener);
        }
 public void ShowClickableToastForApp(string message, AppInfo appInfo, JsonObject ps, ResponseListener listener)
 {
     ShowClickableToastForApp(message, appInfo, ps, null, null, listener);
 }
 public void LaunchInputPicker(ResponseListener listener)
 {
     var appInfo = new AppInfo("com.webos.app.inputpicker")
     {
         Name = "InputPicker"
     };
     LaunchAppWithInfo(appInfo, listener);
 }
        public void LaunchNetflix(string contentId, ResponseListener listener)
        {
            var ps = new JsonObject();
            var netflixContentId = "m=http%3A%2F%2Fapi.netflix.com%2Fcatalog%2Ftitles%2Fmovies%2F" + contentId + "&source_type=4";
            if (!string.IsNullOrEmpty(contentId))
            {
                try
                {
                    ps.Add("contentId", JsonValue.CreateStringValue(netflixContentId));
                }
                catch
                {
                }
            }

            var appInfo = new AppInfo("netflix")
            {
                Name = "Netflix"
            };

            LaunchAppWithInfo(appInfo, ps, listener);
        }
        public void LaunchHulu(string contentId, ResponseListener listener)
        {
            var ps = new JsonObject();
            if (!string.IsNullOrEmpty(contentId))
            {
                try
                {
                    ps.Add("contentId", JsonValue.CreateStringValue(contentId));
                }
                catch
                {
                }
            }

            var appInfo = new AppInfo("hulu")
            {
                Name = "Hulu"
            };

            LaunchAppWithInfo(appInfo, ps, listener);
        }
        public void LaunchAppWithInfo(AppInfo appInfo, object ps, ResponseListener listener)
        {
            const string uri = "ssap://system.launcher/launch";
            var payload = new JsonObject();

            var appId = appInfo.Id;
            string contentId = null;

            if (ps != null)
            {
                if (((JsonObject) ps).ContainsKey("contentId"))
                {
                    try
                    {
                        contentId = ((JsonObject)ps).GetNamedString("contentId");
                    }
                    // ReSharper disable once EmptyGeneralCatchClause
                    catch
                    {

                    }
                }
            }

            try
            {
                payload.Add("id", JsonValue.CreateStringValue(appId));

                if (contentId != null)
                    payload.Add("contentId", JsonValue.CreateStringValue(contentId));

                if (ps != null)
                    payload.Add("params", (JsonObject)ps);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {

            }

            var responseListener = new ResponseListener
                (
                loadEventArg =>
                {
                    var obj = (JsonObject)(((LoadEventArgs)loadEventArg).Load.GetPayload());
                    var launchSession = new LaunchSession
                    {
                        Service = this,
                        AppId = appId,
                        SessionId = obj.GetNamedString("sessionId"),
                        SessionType = LaunchSessionType.App
                    };

                    Util.PostSuccess(listener, launchSession);
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
                );
            var request = new ServiceCommand(this, uri, payload, responseListener);
            request.Send();
        }
        public void LaunchAppStore(string appId, ResponseListener listener)
        {
            var appInfo = new AppInfo("com.webos.app.discovery") { Name = "LG Store" };

            var ps = new JsonObject();

            if (!string.IsNullOrEmpty(appId))
            {
                var query = string.Format("category/GAME_APPS/{0}", appId);
                try
                {
                    ps.Add("query", JsonValue.CreateStringValue(query));
                }
                catch
                {

                }
            }

            LaunchAppWithInfo(appInfo, ps, listener);
        }
        public void LaunchApp(string appId, ResponseListener listener)
        {
            var appInfo = new AppInfo(appId) { Id = appId };

            LaunchAppWithInfo(appInfo, listener);
        }
        private void SetControlApps()
        {
            if (selectedDevice != null)
            {
                GoogleCommand.Enabled = selectedDevice.HasCapability(Launcher.Browser);
                ShowToastCommand.Enabled = selectedDevice.HasCapability(ToastControl.ShowToast);
                NetflixCommand.Enabled = selectedDevice.HasCapability(Launcher.Netflix) || selectedDevice.HasCapability(Launcher.NetflixParams);
                YouTubeCommand.Enabled = selectedDevice.HasCapability(Launcher.YouTube);
                MyDialAppCommand.Enabled = selectedDevice.HasCapability("Launcher.Levak");
                AppStoreCommand.Enabled = selectedDevice.HasCapability(Launcher.AppStoreParams);

                if (selectedDevice.HasCapability(Launcher.RunningAppSubscribe))
                {
                    var runningAppListener = new ResponseListener
                        (
                        loadEventArg =>
                        {
                            var appInfo = LoadEventArgs.GetValue<AppInfo>(loadEventArg);

                            App.MainDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                            {
                                selectedApp = appInfo;
                            });

                        },
                        serviceCommandError =>
                        {

                        }
                        );
                    launcher.SubscribeRunningApp(runningAppListener);
                }

                if (selectedDevice.HasCapability(Launcher.ApplicationList))
                {
                    var rappListListener = new ResponseListener
                        (
                        loadEventArg =>
                        {
                            var apps = LoadEventArgs.GetValue<List<AppInfo>>(loadEventArg);

                            App.MainDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                            {
                                AppsList = apps;
                            });
                        },
                        serviceCommandError =>
                        {

                        }
                        );
                    launcher.GetAppList(rappListListener);
                }

            }
        }