Ejemplo n.º 1
0
        public async Task OpenChat(LivestreamModel livestreamModel, IViewAware fromScreen)
        {
            // guard against invalid/missing chrome path
            var chromeLocation = settingsHandler.Settings.ChromeFullPath;

            if (string.IsNullOrWhiteSpace(chromeLocation))
            {
                await fromScreen.ShowMessageAsync("No chrome locations specified",
                                                  $"Chrome location is not set in settings.{Environment.NewLine}Chat relies on chrome to function.");

                return;
            }
            if (!File.Exists(chromeLocation))
            {
                await fromScreen.ShowMessageAsync("Chrome not found",
                                                  $"Could not find chrome @ {chromeLocation}.{Environment.NewLine}Chat relies on chrome to function.");

                return;
            }
            // guard against stream provider not having chat support
            if (!livestreamModel.ApiClient.HasChatSupport)
            {
                await fromScreen.ShowMessageAsync("Chat not supported",
                                                  $"No external chat support for stream provider '{livestreamModel.ApiClient.ApiName}'");

                return;
            }

            string chromeArgs = $"--app={livestreamModel.ChatUrl} --window-size=350,758";

            await Task.Run(async() =>
            {
                try
                {
                    var proc = new Process
                    {
                        StartInfo =
                        {
                            FileName        = chromeLocation,
                            Arguments       = chromeArgs,
                            CreateNoWindow  = true,
                            UseShellExecute = false
                        }
                    };

                    proc.Start();
                }
                catch (Exception ex)
                {
                    await fromScreen.ShowMessageAsync("Error launching chat", ex.Message);
                }
            });
        }
        public async Task OpenChat(LivestreamModel livestreamModel, IViewAware fromScreen)
        {
            // guard against stream provider with unknown chat support
            if (!livestreamModel.ApiClient.HasChatSupport)
            {
                await fromScreen.ShowMessageAsync("Chat not supported",
                                                  $"No external chat support for stream provider '{livestreamModel.ApiClient.ApiName}'");

                return;
            }

            if (string.IsNullOrWhiteSpace(settingsHandler.Settings.ChatCommandLine))
            {
                await fromScreen.ShowMessageAsync("No chat command specified", "Chat command is not set in settings.");

                return;
            }

            // guard against chat command that contains no url token
            if (!settingsHandler.Settings.ChatCommandLine.Contains(Settings.CHAT_URL_REPLACEMENT_TOKEN))
            {
                await fromScreen.ShowMessageAsync("Missing url token in chat command",
                                                  $"Chat command is missing the url token {Settings.CHAT_URL_REPLACEMENT_TOKEN}.");

                return;
            }

            var command = settingsHandler.Settings.ChatCommandLine.Replace(Settings.CHAT_URL_REPLACEMENT_TOKEN, livestreamModel.ChatUrl);

            await Task.Run(async() =>
            {
                try
                {
                    var proc = new Process
                    {
                        StartInfo =
                        {
                            FileName               = "cmd.exe",
                            Arguments              = "/c " + command,
                            CreateNoWindow         = true,
                            UseShellExecute        = false,
                            RedirectStandardOutput = true,
                            RedirectStandardError  = true,
                        }
                    };

                    proc.Start();
                    string errorOutput = proc.StandardError.ReadToEnd();
                    proc.WaitForExit();

                    // check for exit code as well because sometimes processes emit warnings in the error output stream
                    if (proc.ExitCode != 0 && errorOutput != string.Empty)
                    {
                        await Execute.OnUIThreadAsync(async() => await fromScreen.ShowMessageAsync("Error launching chat", errorOutput));
                    }
                }
                catch (Exception ex)
                {
                    await Execute.OnUIThreadAsync(async() => await fromScreen.ShowMessageAsync("Error launching chat", ex.Message));
                }
            });
        }
Ejemplo n.º 3
0
        public async Task Authorize(IViewAware screen)
        {
            var messageDialogResult = await screen.ShowMessageAsync(title : "Authorization",
                                                                    message : $"Twitch requires authorization to connect to their services, have you set your oauth token in your {settingsHandler.Settings.LivestreamExeDisplayName} configuration file?",
                                                                    messageDialogStyle : MessageDialogStyle.AffirmativeAndNegative,
                                                                    dialogSettings : new MetroDialogSettings()
            {
                AffirmativeButtonText = "Yes",
                NegativeButtonText    = "No"
            });

            if (messageDialogResult == MessageDialogResult.Affirmative)
            {
                settingsHandler.Settings.TwitchAuthTokenInLivestreamerConfig = true;
                settingsHandler.SaveSettings();
                return;
            }

            messageDialogResult = await screen.ShowMessageAsync(title : "Authorization",
                                                                message : "Would you like to authorize this application now?",
                                                                messageDialogStyle : MessageDialogStyle.AffirmativeAndNegative,
                                                                dialogSettings : new MetroDialogSettings()
            {
                AffirmativeButtonText = "Yes",
                NegativeButtonText    = "No"
            });

            if (messageDialogResult == MessageDialogResult.Negative)
            {
                return;
            }

            RequestAuthorization();

            var input = await screen.ShowDialogAsync(title : "Authorization Token",
                                                     message :
                                                     "Once you've approved me, please copy the full redirect url to here so we can save your access token for future use." +
                                                     Environment.NewLine +
                                                     Environment.NewLine +
                                                     $"*Note* The url should start with '{RedirectUri}'");

            if (string.IsNullOrWhiteSpace(input))
            {
                await screen.ShowMessageAsync("Authorization cancelled", "Authorization process was cancelled.");

                return;
            }

            if (input.StartsWith(RedirectUri))
            {
                var match = Regex.Match(input, "#access_token=(?<token>.*)&");
                if (match.Groups["token"].Success)
                {
                    settingsHandler.Settings.TwitchAuthToken = match.Groups["token"].Value;
                    settingsHandler.SaveSettings();
                    return;
                }
            }

            await screen.ShowMessageAsync("Bad url provided",
                                          $"Please make sure you copy the full url, it should start with '{RedirectUri}'");
        }