Exemple #1
0
        public TaskBarIconViewModel(IDependencyResolver resolver,
                                    IUiApplication uiApplication,
                                    IDispatcher dispatcher,
                                    IEnvironmentParameters environmentParameters,
                                    WallpaperClientVersionService wallpaperClientVersionService)
        {
            _regKeyAutostart = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            _orchestrator    = new WallpaperOrchestrator(resolver);
            _state           = new NoConnection(_orchestrator, this);

            _uiApplication                 = uiApplication;
            _environmentParameters         = environmentParameters;
            _wallpaperClientVersionService = wallpaperClientVersionService;
            ExitCommand            = new RelayCommand(x => OnExit());
            LoginCommand           = new AsyncRelayCommand(() => _state.OnLogin());
            ChangeAutostartCommand = new RelayCommand(x => OnChangeAutostart());
            ResetViewCommand       = new RelayCommand(x => OnResetView());
            ExecuteUpdateCommand   = new AsyncRelayCommand(() => OnExecuteUpdateCommand(), x => _updateHandle != null && _updateHandle.HasNewVersion);

            dispatcher.Dispatch(() =>
            {
                _state.OnLogin();
            });
        }
        protected override void ActivateInternal()
        {
            var versionService = new WallpaperClientVersionService();
            var registration   = new SingletonRegistration <WallpaperClientVersionService>(versionService);

            ConfigurationResolver.AddRegistration(registration);

            var uiApp = Resolver.GetInstance <IUiApplication>();

            uiApp.ShutdownMode = ShutdownMode.OnExplicitShutdown;

            var resourceDictionaryManager = Resolver.GetInstance <IResourceDictionaryManager>();
            var dir = new ResourceDictionary {
                Source = new Uri("/Plugin.Application.Wallpaper.Client;component/WallpaperClientResourceDictionary.xaml", UriKind.RelativeOrAbsolute)
            };

            resourceDictionaryManager.AddToApplication(dir);

            var result = dir["WallpaperNotifyIcon"] as TaskbarIcon;

            if (result != null)
            {
                var viewModel = Resolver.CreateConcreteInstanceWithDependencies <TaskBarIconViewModel>();

                ConfigurationResolver.AddRegistration(new ServiceInstanceRegistration <IUserInteraction>(viewModel));

                result.DataContext = viewModel;
                result.Loaded     += (s, e) => viewModel.State.OnLogin();
            }

            //Workaround for bug in NotfiyIcon library
            var tt = new ToolTip();

            tt.IsOpen = true;
            tt.IsOpen = false;
        }