Example #1
0
        public async void ShowSelectWindow()
        {
            this.ShowWindow();

            var songinfo = (SongInfo)(await this.ShowBaseMetroDialog(new ClientSelectionDialog(this)));

            if (songinfo != null && !await Task.Factory.StartNew <bool>(new Func <bool>(() => TwitterCommunicator.Instance.Publish(songinfo))))
            {
                MainWindow.Instance.PublishError();
            }

            SongInfo.AllClear();
            this.SetButtonState(true);

            DecchiCore.Sync();
            if (DecchiCore.IsRunOnBackground)
            {
                WindowState = WindowState.Minimized;
            }
        }
Example #2
0
        private static void RunPriv()
        {
            App.Debug("Run");
            App.Debug("Invoke");

            // 쓰레드 동기화
            if (Interlocked.CompareExchange(ref m_isRunning, 1, 0) == 1)
            {
                return;
            }

            MainWindow.Instance.Dispatcher.Invoke(new Action <bool>(MainWindow.Instance.SetButtonState), false);

            App.Debug("Get");
            var infos = SongInfo.GetCurrentPlayingSong();

            bool success = false;

            if (infos.Count >= 2)
            {
                // 두 개 이상의 곡이 재생중인 경우
                if (!Globals.Instance.AutoSelect)
                {
                    MainWindow.Instance.Dispatcher.Invoke(new Action(MainWindow.Instance.ShowSelectWindow));
                    return;
                }

                App.Debug("AutoSelect");

                var topHwnd = NativeMethods.GetTopMostWindow(infos.Select(e => e.Handle).ToArray());
                App.Debug("topHwnd : " + topHwnd.ToString("X8"));

                var top = infos.Where(e => e.Handle == topHwnd).ToArray();
                App.Debug("topWindow Count : " + top.ToString());

                if (top.Length == 1)
                {
                    success = TwitterCommunicator.Instance.Publish(top[0]);
                }
                else
                {
                    // 가장 위에 있는 창이 여러개면 그건 웹브라우저다!! (아마도)
                    // 메인 창을 찾는다

                    var main = top.Where(e => e.MainTab).ToArray();
                    if (main.Length == 1)
                    {
                        success = TwitterCommunicator.Instance.Publish(main[0]);
                    }
                    else
                    {
                        // 설마 이런경우가 있겠어?
                        success = TwitterCommunicator.Instance.Publish(top[0]);
                    }
                }
            }
            else
            {
                if (infos.Count == 0)
                {
                    // 재생중인 곡이 없는 경우
                    success = true;
                }
                else
                {
                    // 하나의 곡이 재생중인 경우
                    success = TwitterCommunicator.Instance.Publish(infos[0]);
                }
            }

            SongInfo.AllClear();

            MainWindow.Instance.Dispatcher.Invoke(new Action <bool>(MainWindow.Instance.SetButtonState), true);

            if (!success)
            {
                MainWindow.Instance.Dispatcher.Invoke(new Action(MainWindow.Instance.PublishError));
            }

            Interlocked.CompareExchange(ref DecchiCore.m_isRunning, 0, 1);
        }