Пример #1
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;
        }
Пример #2
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());
        }
Пример #3
0
        protected override void Configure()
        {
            _Contracts = new AppContracts();
            _kernel.RegisterSingleton(this);
            _SettingsPersistor = new JsonPersister <AppSettings>(Path.Combine(_Contracts.SettingsLocation, _Contracts.SettingsFilename));
            _kernel.RegisterSingleton(_SettingsPersistor);
            _kernel.RegisterSingleton(_Contracts);
            _Settings = _SettingsPersistor.Instance;
            _kernel.RegisterSingleton(_Settings);

            _log = new ProductionLogger();
            _kernel.RegisterSingleton(_log);
            _kernel.RegisterSingleton <UpdateManager>();

            _kernel.RegisterSingleton(new AutorunService(_log, _Settings, _Contracts));
            _kernel.RegisterSingleton <IWindowManager>(new AppWindowManager(_Settings));
            _kernel.RegisterSingleton <ClipboardManager>();
            _kernel.Register <IEventAggregator, EventAggregator>();

            _kernel.RegisterSingleton <ISpotifyLocalApi, SpotifyLocalApi>();
            _kernel.RegisterSingleton <ISpotifyWebApi, SpotifyWebApi>();
            _kernel.RegisterSingleton <ISpotifyNativeApi, SpotifyNativeApi>();
            _kernel.RegisterSingleton <ISpotifyController, SpotifyController>();
            //new CoverService(
            _kernel.RegisterSingleton <ICoverService>(() => new CoverService(string.IsNullOrEmpty(_Settings.CacheFolder)
                ? _Contracts.SettingsLocation
                : _Settings.CacheFolder, _log, _kernel.GetInstance <ISpotifyWebApi>()));

            _kernel.RegisterSingleton <KeyManager>();

            var classes =
                Assembly.GetExecutingAssembly()
                .GetTypes()
                .Where(
                    type =>
                    type.IsPublic && (
                        type.Namespace == typeof(ShellViewModel).Namespace ||
                        type.Namespace == typeof(ShellView).Namespace))
                .ToList();

            foreach (var @class in classes)
            {
                _kernel.Register(@class);
            }
            base.Configure();
        }