示例#1
0
 private void _poe_ProcessChanged(object sender, ProcessChangedEventArgs e)
 {
     if (e.ChangedType != ProcessChangedType.Opened)
     {
         return;
     }
     DispatcherHelper.Access(_runScanning);
     _poe.ProcessChanged -= _poe_ProcessChanged;
 }
示例#2
0
 private void _poe_StateChanged(object sender, StateChangedEventArgs e)
 {
     if (!e.IsForeground || !_isNewMessage)
     {
         return;
     }
     DispatcherHelper.Access(_messageReaded);
     _poe.Stop();
 }
示例#3
0
        private void _client_Append(object sender, ClientChangedEventArgs e)
        {
            DispatcherHelper.Access(() => {
                // Filter messages from user
                if (e.MessageItem.Direction == MessageDirection.To)
                {
                    return;
                }

                // Filter
                if (!e.MessageItem.IsDisconnect && !_isMessageValid(e.MessageItem))
                {
                    return;
                }

                // Chat List
                lbxChat.Items.Add(e.MessageItem);
                lbxChat.ScrollIntoView(lbxChat.Items[lbxChat.Items.Count - 1]);

                if (!Config.Instance.IsNotifyWhenPoeChatNotifyIsActive && IsActive)
                {
                    return;
                }

                // Notification
                if (!Config.Instance.IsNotificationsEnabled)
                {
                    return;
                }
                if (e.MessageItem.IsDisconnect && !Config.Instance.IsNotifyWhenDisconnect)
                {
                    return;
                }
                if (Config.Instance.IsNotifyOnlyWhenPoEIsInactive && User32.IsPoeInForeground())
                {
                    return;
                }

                // Tray Icon Notify
                _isNewMessage = true;
                _updateTrayIcon();
                _poe.Scan();

                string title;
                if (!e.MessageItem.IsDisconnect)
                {
                    title = $"{e.MessageItem.Type.GetDescription()}" +
                            $"{(!string.IsNullOrEmpty(e.MessageItem.GuildName) ? e.MessageItem.GuildName + " " : "")}" +
                            $"{e.MessageItem.UserName}";
                }
                else
                {
                    title = $"{e.MessageItem.UserName}";
                }

                var balloon = new PoeBalloon {
                    Title        = title,
                    Message      = e.MessageItem.Message,
                    IsDisconnect = e.MessageItem.IsDisconnect
                };
                balloon.Click += (o, args) => {
                    if (Config.Instance.ClickShowProgram == 0)
                    {
                        User32.BringPoeToForeground();
                    }
                    else if (Config.Instance.ClickShowProgram == 1)
                    {
                        _toggleWindow();
                    }

                    _copyToClipboard(e.MessageItem, Config.Instance.ClickCopyToClipboard);

                    balloon.Close();
                };

                int?dur = null;
                if (Config.Instance.NotificationDuration != 0)
                {
                    dur = Config.Instance.NotificationDuration < 500 ? 500 : Config.Instance.NotificationDuration;
                }
                tbiTaskbarIcon.ShowCustomBalloon(balloon, PopupAnimation.Slide, dur);

                // Play Sound
                if (!e.MessageItem.IsDisconnect)
                {
                    if (!Config.Instance.IsPlaySoundOnMessage)
                    {
                        return;
                    }
                }
                else
                {
                    if (!Config.Instance.IsPlaySoundOnDisconnect)
                    {
                        return;
                    }
                }
                if (Config.Instance.IsCustomSound && File.Exists(Config.Instance.CustomSoundPath))
                {
                    try {
                        _media.Open(new Uri(Config.Instance.CustomSoundPath));
                        _media.Volume = Config.Instance.CustomSoundVolume;
                        _media.Play();
                    } catch (Exception) {
                        /*custom boop*/
                    }
                }
                else
                {
                    try {
                        if (!e.MessageItem.IsDisconnect)
                        {
                            new SoundPlayer {
                                Stream = Properties.Resources.NotifySound
                            }.Play();
                        }
                        else
                        {
                            new SoundPlayer {
                                Stream = Properties.Resources.NotifySoundError
                            }.Play();
                        }
                    } catch (Exception) {
                        /*boop*/
                    }
                }
            });
        }