Beispiel #1
0
        public ShellViewModel(IWindowManager windowManager, ISpotifyController spotifyController, ICoverService coverService, IEventAggregator eventAggregator, AppSettings settings, Core.ILog logger, IUpdateService updateService, IUsageTrackerService usageTrackerService, IBroadcastService broadcastService)
        {
            _WindowManager       = windowManager;
            _SpotifyController   = spotifyController;
            _CoverService        = coverService;
            _EventAggregator     = eventAggregator;
            _Settings            = settings;
            _Logger              = logger;
            _UpdateService       = updateService;
            _UsageTrackerService = usageTrackerService;
            _BroadcastService    = broadcastService;
            _ApplicationSize     = _Settings.ApplicationSize;

            CoverImage = NoCoverUri;
            UpdateView();

            _SpotifyController.TrackChanged  += (o, e) => UpdateView();
            _SpotifyController.SpotifyOpened += (o, e) => SpotifyOpened();
            _SpotifyController.SpotifyExited += (o, e) => SpotifyExited();
            _UpdateService.UpdateReady       += UpdateReady;
            _UpdateService.StartBackgroundCheck();
            _UsageTrackerService.Track();

            _BroadcastService.BroadcastMessageReceived += BroadcastMessageReceived;
            _BroadcastService.StartListening();

            _Settings.PropertyChanged += (o, e) => {
                if (e.PropertyName == ApplicationSize.GetType().Name)
                {
                    ApplicationSize = _Settings.ApplicationSize;
                }
            };
        }
Beispiel #2
0
        public ShellViewModel(IWindowManager windowManager, ISpotifyController spotifyController,
                              ICoverService coverService, AppSettings settings, ILog logger, Container kernel, ClipboardManager clipboardManager,
                              AppContracts appContracts)
        {
            _WindowManager     = windowManager;
            _SpotifyController = spotifyController;
            _CoverService      = coverService;
            _Settings          = settings;
            _Logger            = logger;
            _kernel            = kernel;
            _clipboardManager  = clipboardManager;
            _appContracts      = appContracts;
            ApplicationSize    = _Settings.ApplicationSize;

            CoverImage = NoCoverUri;

#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void
            _SpotifyController.AttachTrackChangedHandler(async e => await UpdateView().ConfigureAwait(false));
            _SpotifyController.SpotifyOpened.Subscribe(async o => await SpotifyOpened().ConfigureAwait(false));
            _SpotifyController.SpotifyExited.Subscribe(async o => await SpotifyExited().ConfigureAwait(false));
            _SpotifyController.AttachTrackStatusChangedHandler(SpotifyControllerOnTrackStatusChanged);
#pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void

            //TODO more app sizes
            ApplicationSize             = ApplicationSize.Medium;
            SystemEvents.SessionSwitch += SystemEventsOnSessionSwitch;
        }
Beispiel #3
0
		public ShellViewModel(IWindowManager windowManager, ISpotifyController spotifyController, ICoverService coverService, IEventAggregator eventAggregator, AppSettings settings, Core.ILog logger, IUpdateService updateService, IUsageTrackerService usageTrackerService, IBroadcastService broadcastService) {
			_WindowManager = windowManager;
			_SpotifyController = spotifyController;
			_CoverService = coverService;
			_EventAggregator = eventAggregator;
			_Settings = settings;
			_Logger = logger;
			_UpdateService = updateService;
			_UsageTrackerService = usageTrackerService;
			_BroadcastService = broadcastService;
			_ApplicationSize = _Settings.ApplicationSize;

			CoverImage = NoCoverUri;
			UpdateView();

			_SpotifyController.TrackChanged += (o, e) => UpdateView();
			_SpotifyController.SpotifyOpened += (o, e) => SpotifyOpened();
			_SpotifyController.SpotifyExited += (o, e) => SpotifyExited();
			_UpdateService.UpdateReady += UpdateReady;
			_UpdateService.StartBackgroundCheck();
			_UsageTrackerService.Track();

			_BroadcastService.BroadcastMessageReceived += BroadcastMessageReceived;
			_BroadcastService.StartListening();

			_Settings.PropertyChanged += (o, e) => {
				                             if (e.PropertyName == ApplicationSize.GetType().Name)
					                             ApplicationSize = _Settings.ApplicationSize;
			                             };
		}
        public void TestVolumeFailedRequest(ISpotifyController controller, ISpotifyWebApi spotifyWebApi, double resultVolume)
        {
            _spotifyWebApi.SetVolume(0).ThrowsForAnyArgs <ArgumentException>();

            "Given spotify controller".x(() => controller = _spotifyController);
            "and web api api".x(() => spotifyWebApi       = _spotifyWebApi);
            "When i change volume and it fails".x(async() => resultVolume = await controller.SetSpotifyVolume(2));
            "Then the result is Nan".x(() => Assert.Equal(double.NaN, resultVolume));
        }
Beispiel #5
0
        public void TestVolumeFailedRequest(ISpotifyController controller, ISpotifyLocalApi localApi, double resultVolume)
        {
            _localApi.SendLocalStatusRequest(false, false, CancellationToken.None).ThrowsForAnyArgs <ArgumentException>();

            "Given spotify controller".x(() => controller = _spotifyController);
            "and local api".x(() => localApi = _localApi);
            "When i change volume and it fails".x(async() => resultVolume = await controller.SetSpotifyVolume(2));
            "Then the result is Nan".x(() => Assert.Equal(double.NaN, resultVolume));
        }
Beispiel #6
0
        public SettingsViewModelTest()
        {
            _coverService         = Substitute.For <ICoverService>();
            _logger               = Substitute.For <ILog>();
            _appSettings          = Substitute.For <AppSettings>();
            _hotkeyViewModel      = Substitute.For <HotKeyViewModel>(null, _appSettings);
            _spotifyController    = Substitute.For <ISpotifyController>();
            _autorunService       = Substitute.For <AutorunService>(null, null, null);
            _appSettingsPersistor = Substitute.For <JsonPersister <AppSettings> >();
            _appSettingsPersistor.Instance.Returns(_appSettings);

            _settingsViewModel = new SettingsViewModel(new AppContracts(),
                                                       _coverService, _logger, _hotkeyViewModel, _spotifyController, _autorunService, _appSettingsPersistor);
        }
Beispiel #7
0
 public KeyManager(ISpotifyController spotifyController, ILog log)
 {
     _spotifyController = spotifyController;
     _next = new HotKey(Key.None, KeyModifier.None,
                        key => _spotifyController.NextTrack());
     _previous = new HotKey(Key.None, KeyModifier.None,
                            key => _spotifyController.PreviousTrack());
     _playPause = new HotKey(Key.None, KeyModifier.None,
                             key => _spotifyController.PausePlay());
     _volumeDown = new HotKey(Key.None, KeyModifier.None,
                              key => _spotifyController.VolumeDown());
     _volumeUp = new HotKey(Key.None, KeyModifier.None,
                            key => _spotifyController.VolumeUp());
     _log = log;
 }
Beispiel #8
0
        public SettingsViewModel(AppContracts contracts,
                                 ICoverService coverService, ILog logger, HotKeyViewModel hotKeyViewModel,
                                 ISpotifyController spotifyController, AutorunService autorunService, JsonPersister <AppSettings> persister)
        {
            _settings          = persister.Instance;
            _contracts         = contracts;
            _coverService      = coverService;
            _logger            = logger;
            _spotifyController = spotifyController;
            _autorunService    = autorunService;
            _persister         = persister;

            HotKeyViewModel = hotKeyViewModel;
            DisplayName     = $"Settings - {_contracts.ApplicationName}";
            CacheSize       = Helper.MakeNiceSize(_coverService.CacheSize());
        }
Beispiel #9
0
        public void TestVolumeUpRequest(ISpotifyController controller, ISpotifyLocalApi localApi, double resultVolume)
        {
            _localApi.SendLocalStatusRequest(false, false, CancellationToken.None).ReturnsForAnyArgs(new Status {
                volume = 0
            }, new Status {
                volume = 1
            }, new Status {
                volume = 2
            });

            "Given spotify controller".x(() => controller = _spotifyController);
            "and local api".x(() => localApi = _localApi);
            "When i change volume to 2".x(async() => resultVolume = await controller.SetSpotifyVolume(2));
            "Then the return value is 2".x(() => Assert.Equal(2, resultVolume));
            "And VolumeUp is called 2 times".x(() => _nativeApi.ReceivedWithAnyArgs(2).VolumeUp());
        }
        public void TestVolumeDownRequest(ISpotifyController controller, ISpotifyLocalApi localApi, double resultVolume)
        {
            _spotifyController.SpotifyProcess = Process.GetCurrentProcess();
            _localApi.SendLocalStatusRequest(false, false, CancellationToken.None).ReturnsForAnyArgs(new Status {
                volume = 2
            }, new Status {
                volume = 1
            }, new Status {
                volume = 0
            });

            "Given spotify controller".x(() => controller = _spotifyController);
            "and local api".x(() => localApi = _localApi);
            "When i change volume to 0".x(async() => resultVolume = await controller.SetSpotifyVolume(0));
            "Then the return value is 0".x(() => Assert.Equal(0, resultVolume));
            "And VolumeDown is called 1 time".x(() => _spotifyWebApi.ReceivedWithAnyArgs(1).SetVolume(0));
        }