コード例 #1
0
        public MainWindow(SovndClient client, ChannelDirectory channels, IPlayerFactory playerFactory, ISettingsProvider settings, Scrobbler scrobbler)
        {
            InitializeComponent();

            toast = new Toast();
            toast.Show();

            _scrobbler     = scrobbler;
            _client        = client;
            _playerFactory = playerFactory;
            _settings      = settings.GetSettings();

            AllowDrop = true;
            channelbox.ItemsSource = channels.channels;

            PreviewDragOver  += OnPreviewDragEnter;
            PreviewDragEnter += OnPreviewDragEnter;
            DragEnter        += OnPreviewDragEnter;
            DragOver         += OnPreviewDragEnter;

            Drop += OnDrop;

            Loaded += (_, __) =>
            {
                BindingOperations.EnableCollectionSynchronization(channels.channels, channels.channels);
                App.WindowHandle = new WindowInteropHelper(this).Handle;
                synchronization  = SynchronizationContext.Current;

                _client.Run();

                if (!string.IsNullOrWhiteSpace(_settings.LastChannel))
                {
                    _player = _playerFactory.CreatePlayer(_settings.LastChannel);
                    _client.SubscribeToChannel(_settings.LastChannel);
                    SetupChannel();
                    Logging.Event("Switched to previously set channel");
                }
            };

            Closed += (_, __) =>
            {
                _client.Disconnect();
                Spotify.ShutDown();
                Process.GetCurrentProcess().Kill(); // TODO That's really inelegant
            };
        }
コード例 #2
0
        private void Channelbox_SelectionChanged(object sender, RoutedEventArgs e)
        {
            var channel = channelbox.SelectedItem as Channel;

            if (channel != null)
            {
                DropChannel();

                _settings.LastChannel = channel.Name;
                _settings.Save();

                _player = _playerFactory.CreatePlayer(channel.Name);
                _client.SubscribeToChannel(channel.Name);
                SetupChannel();
                Logging.Event("Switched channels");
            }
        }