コード例 #1
0
ファイル: HotKey.cs プロジェクト: lurume84/jirafy-toastify
 protected bool Equals(Hotkey other)
 {
     return(base.Equals(other) &&
            this.Equals((IHotkey)other));
 }
コード例 #2
0
ファイル: HotKey.cs プロジェクト: Vankog/toastify
        private static void HotkeyActionCallback([NotNull] Hotkey hotkey)
        {
            if (ToastView.Current?.IsInitComplete != true)
            {
                return;
            }

            // Ignore this keypress if it's been less than WAIT_BETWEEN_HOTKEY_PRESS since the last press
            if (DateTime.Now.Subtract(hotkey.LastPressTime).TotalMilliseconds < WAIT_BETWEEN_HOTKEY_PRESS)
            {
                return;
            }

            hotkey.LastPressTime = DateTime.Now;
            LastHotkey           = hotkey;

            if (logger.IsDebugEnabled)
            {
                logger.Debug($"HotkeyActionCallback: {hotkey.Action}");
            }

            try
            {
#if DEBUG
                if (hotkey.Action == ToastifyAction.ShowDebugView && DebugView.Current == null)
                {
                    DebugView.Launch();
                }
#endif

                if (hotkey.Action == ToastifyAction.CopyTrackInfo && Spotify.Instance.CurrentSong != null)
                {
                    Analytics.TrackEvent(Analytics.ToastifyEventCategory.Action, Analytics.ToastifyEvent.Action.CopyTrackInfo);
                    Clipboard.SetText(Spotify.Instance.CurrentSong.GetClipboardText(Settings.Current.ClipboardTemplate));
                }
                else if (hotkey.Action == ToastifyAction.PasteTrackInfo && Spotify.Instance.CurrentSong != null)
                {
                    Analytics.TrackEvent(Analytics.ToastifyEventCategory.Action, Analytics.ToastifyEvent.Action.PasteTrackInfo);
                    Clipboard.SetText(Spotify.Instance.CurrentSong.GetClipboardText(Settings.Current.ClipboardTemplate));
                    Windows.SendPasteKey();
                }
                else
                {
                    Spotify.Instance.SendAction(hotkey.Action);
                }

                ToastView.Current.DisplayAction(hotkey.Action);
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }

                logger.Error("Exception with hooked key.", ex);
                ActionCallbackFailed?.Invoke(typeof(Hotkey), new HotkeyActionCallbackFailedEventArgs(hotkey, ex));

                Analytics.TrackException(ex);
            }
        }