예제 #1
0
        public static PopupMessageForm PopUp(string message, int totalMessagesCount, TimeSpan showingTime, Action onClick)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var form = new PopupMessageForm(message, totalMessagesCount, showingTime, onClick);

            form.Show();

            return(form);
        }
예제 #2
0
        private async void FeedUpdateTimer_Tick(object sender, EventArgs e)
        {
            FhFeedObject[] feed;

            try
            {
                feed = await fhCient.GetFeed();
            }
            catch (FhRequestException exception)
            {
                var requestsLimitCount = int.Parse(exception.Error.OwnerResponse.Message.Headers.GetValues("X-Ratelimit-Remaining").First()); // отладка
                return;
            }
            catch (Exception exception) // ignore
            {
                return;
            }

            var newFeed = feed
                          .Where(feedObject => feedObject.IsNew)
                          .OrderByDescending(feedObject => feedObject.CreatedAt);

            GenerateFeed(feed, newFeed.ToArray());

            if (newFeed.Count() == 0)
            {
                return;
            }

            if (newFeed.First().OwnerDataObject.Id == Settings.Default.LastShownMessageId)
            {
                return;
            }

            if (Visible)
            {
                return;
            }

            ActivePopupMessage = PopupMessageForm.PopUp(newFeed.First().Message, newFeed.Count(),
                                                        TimeSpan.FromSeconds(Settings.Default.MessageShowingSeconds),
                                                        onClick: async() =>
            {
                await fhCient.MarkFeedAsRead();
                Invoke(new Action(Show));
            });

            Settings.Default.LastShownMessageId = newFeed.First().OwnerDataObject.Id;
            Settings.Default.Save();
        }
예제 #3
0
        private async void AppNotifyIcon_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (ActivePopupMessage != null)
            {
                ActivePopupMessage.Close();
                ActivePopupMessage = null;
            }

            Show();
            TopMost = true;
            TopMost = false;

            try
            {
                await fhCient.MarkFeedAsRead();
            }
            catch (Exception exception) { } // ignore
        }