Esempio n. 1
0
        // Must be run within UI thread
        public static void InitUI(bool firstTime)
        {
#if !NOAWE
            WebBgMusicForm              = new MuteFm.UiPackage.WebBgMusicForm();
            WebBgMusicForm.FormClosing += new FormClosingEventHandler(WebBgMusicForm_FormClosing);
            WebBgMusicForm.Resize      += new EventHandler(WebBgMusicForm_Resize);
            //WebBgMusicForm.Show();
#endif

            _notificationType = new NotificationType("MUTEFM_NOTIFICATION", "mute.fm notification");

            _growl = new GrowlConnector();
            _growl.NotificationCallback += new GrowlConnector.CallbackEventHandler(growl_notification_callback);
            _growl.EncryptionAlgorithm   = Cryptography.SymmetricAlgorithmType.PlainText; // set to ease debugging

            // OLDNOTIFY TopForm.Instance.Show();
            //UiPackage.UiCommands.SetNotification(Constants.ProgramName + " started (expires " + Constants.GetExpirationDateString() + ")", false);
            UiPackage.UiCommands.SetNotification(Constants.ProgramName + " started", false);

            if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.Hotkeys == null)
            {
                MuteFmConfigUtil.LoadDefaultHotkeys(SmartVolManagerPackage.BgMusicManager.MuteFmConfig);
            }


            if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.SoundPollIntervalInS == 0)
            {
                SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.SoundPollIntervalInS = MuteFmConfig.SoundPollIntervalDefault;
            }

            RegisterHotkeys();

            UiPackage.UiCommands.UpdateUiForState(MuteFm.SmartVolManagerPackage.BgMusicManager.GetValidOperation(), false, false, true);

            mPlayerForm             = new PlayerForm();
            mPlayerForm.FormClosed += new FormClosedEventHandler(mPlayer_FormClosed);
            mPlayerForm.Init(false);

//            MuteApp.UiPackage.UiCommands.ShowPlayer();
            if (firstTime)
            {
                System.ComponentModel.BackgroundWorker firstTimeWorker = new BackgroundWorker();
                firstTimeWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(DoFirstTimeWork);
                firstTimeWorker.RunWorkerAsync();

#if !NOAWE
                UiPackage.UiCommands.ShowGettingStartedWizard();
#endif
                mPlayerForm.ToggleTopmost(true);
            }
            else
            {
                if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.PlayMusicOnStartup)
                {
                    System.ComponentModel.BackgroundWorker firstTimeWorker = new BackgroundWorker();
                    firstTimeWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate
                    {
                        SoundPlayerInfo playerInfo = (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GetActiveBgMusic());

                        System.Threading.Thread.Sleep(2000);
                        OnOperation(Operation.Play, playerInfo.AutoPlaysOnStartup, false);

                        if (playerInfo.AutoPlaysOnStartup == false)
                        {
                            System.ComponentModel.BackgroundWorker firstTimeWorker2 = new BackgroundWorker();
                            firstTimeWorker2.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate
                            {
                                //System.Threading.Thread.Sleep(5000); //todo
                                OnOperation(Operation.Play);
                            });
                            firstTimeWorker2.RunWorkerAsync();
                        }
                        System.Threading.Thread.Sleep(1000);
                        OnOperation(Operation.Minimize);
                    });
                    firstTimeWorker.RunWorkerAsync();
                }
            }

            System.Windows.Forms.Application.Run(MuteFm.UiPackage.WinSoundServerSysTray.Instance);
        }