Exemplo n.º 1
0
        private void currentPipe_DataIn(object sender, DuplexPipe.PipeReadEventArgs e)
        {
            owner.InvokeSafe(() => {
                switch (e.Key)
                {
                case "vol":
                    if (int.TryParse(e.Data, out int volume) && volume != Program.UserConfig.VideoPlayerVolume)
                    {
                        Program.UserConfig.VideoPlayerVolume = volume;
                        Program.UserConfig.Save();
                    }

                    break;

                case "download":
                    TwitterUtils.DownloadVideo(lastUrl, lastUsername);
                    break;

                case "rip":
                    currentPipe.Dispose();
                    currentPipe = null;

                    currentProcess.Dispose();
                    currentProcess = null;

                    isClosing = false;
                    TriggerProcessExitEventUnsafe();
                    break;
                }
            });
        }
Exemplo n.º 2
0
        private void pipe_DataIn(object sender, DuplexPipe.PipeReadEventArgs e)
        {
            owner.InvokeSafe(() => {
                switch (e.Key)
                {
                case "vol":
                    if (int.TryParse(e.Data, out int volume) && volume != Config.VideoPlayerVolume)
                    {
                        Config.VideoPlayerVolume = volume;
                        Config.Save();
                    }

                    break;

                case "download":
                    if (currentInstance != null)
                    {
                        owner.AnalyticsFile.DownloadedVideos.Trigger();
                        TwitterUtils.DownloadVideo(currentInstance.Url, currentInstance.Username);
                    }

                    break;

                case "rip":
                    currentInstance?.Dispose();
                    currentInstance = null;

                    isClosing = false;
                    TriggerProcessExitEventUnsafe();
                    break;
                }
            });
        }
Exemplo n.º 3
0
        public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            Control control = browserControl.AsControl();

            switch (commandId)
            {
            case MenuOpenLinkUrl:
                OpenBrowser(control, Context.LinkUrl);
                break;

            case MenuCopyLinkUrl:
                SetClipboardText(control, Context.UnsafeLinkUrl);
                break;

            case MenuCopyUsername: {
                string url   = Context.UnsafeLinkUrl;
                Match  match = TwitterUtils.RegexAccount.Match(url);

                SetClipboardText(control, match.Success ? match.Groups[1].Value : url);
                control.InvokeAsyncSafe(analytics.AnalyticsFile.CopiedUsernames.Trigger);
                break;
            }

            case MenuOpenMediaUrl:
                OpenBrowser(control, TwitterUtils.GetMediaLink(Context.MediaUrl, ImageQuality));
                break;

            case MenuCopyMediaUrl:
                SetClipboardText(control, TwitterUtils.GetMediaLink(Context.MediaUrl, ImageQuality));
                break;

            case MenuViewImage: {
                string url = Context.MediaUrl;

                control.InvokeAsyncSafe(() => {
                        TwitterUtils.ViewImage(url, ImageQuality);
                        analytics.AnalyticsFile.ViewedImages.Trigger();
                    });

                break;
            }

            case MenuSaveMedia: {
                bool   isVideo  = Context.Types.HasFlag(ContextInfo.ContextType.Video);
                string url      = Context.MediaUrl;
                string username = Context.Chirp.Authors.LastOrDefault();

                control.InvokeAsyncSafe(() => {
                        if (isVideo)
                        {
                            TwitterUtils.DownloadVideo(url, username);
                            analytics.AnalyticsFile.DownloadedVideos.Trigger();
                        }
                        else
                        {
                            TwitterUtils.DownloadImage(url, username, ImageQuality);
                            analytics.AnalyticsFile.DownloadedImages.Trigger();
                        }
                    });

                break;
            }

            case MenuSaveTweetImages: {
                string[] urls     = Context.Chirp.Images;
                string   username = Context.Chirp.Authors.LastOrDefault();

                control.InvokeAsyncSafe(() => {
                        TwitterUtils.DownloadImages(urls, username, ImageQuality);
                        analytics.AnalyticsFile.DownloadedImages.Trigger();
                    });

                break;
            }

            case MenuReadApplyROT13:
                string selection = parameters.SelectionText;
                control.InvokeAsyncSafe(() => FormMessage.Information("ROT13", StringUtils.ConvertRot13(selection), FormMessage.OK));
                control.InvokeAsyncSafe(analytics.AnalyticsFile.UsedROT13.Trigger);
                return(true);

            case MenuSearchInBrowser:
                string query = parameters.SelectionText;
                control.InvokeAsyncSafe(() => BrowserUtils.OpenExternalSearch(query));
                DeselectAll(frame);
                break;

            case MenuOpenDevTools:
                browserControl.ShowDevTools();
                break;
            }

            return(false);
        }
Exemplo n.º 4
0
        public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            switch (commandId)
            {
            case MenuOpenLinkUrl:
                OpenBrowser(browserControl.AsControl(), IsLink ? ContextInfo.Value : parameters.LinkUrl);
                break;

            case MenuCopyLinkUrl:
                SetClipboardText(browserControl.AsControl(), IsLink ? ContextInfo.Value : parameters.UnfilteredLinkUrl);
                break;

            case MenuCopyUsername:
                Match match = TwitterUtils.RegexAccount.Match(parameters.UnfilteredLinkUrl);
                SetClipboardText(browserControl.AsControl(), match.Success ? match.Groups[1].Value : parameters.UnfilteredLinkUrl);
                break;

            case MenuOpenMediaUrl:
                OpenBrowser(browserControl.AsControl(), TwitterUtils.GetMediaLink(GetMediaLink(parameters), ImageQuality));
                break;

            case MenuCopyMediaUrl:
                SetClipboardText(browserControl.AsControl(), TwitterUtils.GetMediaLink(GetMediaLink(parameters), ImageQuality));
                break;

            case MenuViewImage:
                string url  = GetMediaLink(parameters);
                string file = Path.Combine(BrowserCache.CacheFolder, TwitterUtils.GetImageFileName(url));

                void ViewFile()
                {
                    string ext = Path.GetExtension(file);

                    if (TwitterUtils.ValidImageExtensions.Contains(ext))
                    {
                        WindowsUtils.OpenAssociatedProgram(file);
                    }
                    else
                    {
                        FormMessage.Error("Image Download", "Invalid file extension " + ext, FormMessage.OK);
                    }
                }

                if (File.Exists(file))
                {
                    ViewFile();
                }
                else
                {
                    BrowserUtils.DownloadFileAsync(TwitterUtils.GetMediaLink(url, ImageQuality), file, ViewFile, ex => {
                        FormMessage.Error("Image Download", "An error occurred while downloading the image: " + ex.Message, FormMessage.OK);
                    });
                }

                break;

            case MenuSaveMedia:
                if (IsVideo)
                {
                    TwitterUtils.DownloadVideo(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault());
                }
                else
                {
                    TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
                }

                break;

            case MenuSaveTweetImages:
                TwitterUtils.DownloadImages(lastHighlightedTweetImageList, lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
                break;

            case MenuOpenDevTools:
                browserControl.ShowDevTools();
                break;
            }

            return(false);
        }