Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            #region Hide
            WindowState   = WindowState.Minimized;
            Visibility    = Visibility.Hidden;
            ShowInTaskbar = false;
            #endregion

            #region Events Subscription
            Closing += OnClosing;
            #endregion

            var jsonConfigFile = new JsonConfigFileHandler();
            _taskRepository = new ExecutableTaskRepository(jsonConfigFile);
            _taskHandler    = new TaskHandler(_taskRepository);
            _taskHandler.TasksGlobalStatusChanged += AppStatusChanged;
            _taskHandler.AppWorkingStatusChanged  += AppWorkingStatusChanged;

            _viewModel = new TasksManagerViewModel(_taskRepository);

            var fullPath         = Assembly.GetExecutingAssembly().Location;
            var autostartManager = new AutoStartManager(AppName, fullPath);
            _sysTrayWrapper = new SysTrayWrapper(autostartManager);
            _sysTrayWrapper.LeftCLickOnTrayIconOccured += LeftClickOnTray;
            _sysTrayWrapper.CloseAction += CloseAction;

            _taskHandler.StartAnalysing();
        }
        public MainWindow()
        {
            InitializeComponent();

            var fullPath = Assembly.GetExecutingAssembly().Location;

            _autoStartManager = new AutoStartManager("SpotifySleepModeStopper", fullPath);

            #region Events Subscription
            Closing += OnClosing;
            #endregion

            #region Init Tray Icon
            WindowState   = WindowState.Minimized;
            Visibility    = Visibility.Hidden;
            ShowInTaskbar = false;

            _notifyIcon = new NotifyIcon();
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifySleepModeStopperGui.music.ico"))
            {
                _notPlayingIcon = new Icon(stream);
            }
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifySleepModeStopperGui.music_playing.ico"))
            {
                _playingIcon = new Icon(stream);
            }
            SetNotPlaying();
            _notifyIcon.Visible = true;

            var contextMenu  = new ContextMenu();
            var exitMenuItem = new MenuItem();
            exitMenuItem.Index  = 1;
            exitMenuItem.Text   = "Exit";
            exitMenuItem.Click += exit_Click;

            _autoStartMenuItem       = new MenuItem();
            _autoStartMenuItem.Index = 0;

            if (_autoStartManager.IsAutoStartSet())
            {
                _autoStartMenuItem.Text = AppStartingOnStartupMess; //"Auto Startup";
            }
            else
            {
                _autoStartMenuItem.Text = AppNotStartingOnStartupMess;
            }

            _autoStartMenuItem.Click += changeAutoStart_Click;

            contextMenu.MenuItems.AddRange(new[] { _autoStartMenuItem, exitMenuItem });
            _notifyIcon.ContextMenu = contextMenu;
            #endregion

            #region Poor Man DI
            var iconChanger      = new AppStateReporting(SetPlaying, SetNotPlaying);
            var messageDisplayer = new DummyMessageDisplayer();
            var powerHandler     = new PowerRequestContextHandler();
            var soundAnalyser    = new CsCoreSoundAnalyser(messageDisplayer);
            #endregion

            _analyser = new SpotifySaveModeStopper(messageDisplayer, powerHandler, soundAnalyser, iconChanger);
            _analyser.StartListening();
        }
        public MainWindow()
        {
            InitializeComponent();

            #region Poor Man DI
            var iconChanger      = new AppStateReporting(SetPlayingGui, SetNotPlayingGui);
            var messageDisplayer = new DummyMessageDisplayer();
            var powerHandler     = new PowerRequestContextHandler();
            var soundAnalyser    = new CsCoreSoundAnalyser(messageDisplayer);
            var processAnalyser  = new ProcessAnalyser();

            var fullPath         = Assembly.GetExecutingAssembly().Location;
            var autoStartManager = new AutoStartManager(AppName, fullPath);

            var settingsManager = new SettingsManager <AppSettings>(AppName, new AppSettings {
                IsScreenSleepEnabled = false
            });
            #endregion

            _facade = new SpotifySaveModeStopperFacade(messageDisplayer, powerHandler, soundAnalyser, processAnalyser, iconChanger, autoStartManager, settingsManager);

            #region Events Subscription
            Closing += OnClosing;
            #endregion

            #region Init Tray Icon
            WindowState   = WindowState.Minimized;
            Visibility    = Visibility.Hidden;
            ShowInTaskbar = false;

            _notifyIcon = new NotifyIcon();
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifySleepModeStopperGui.music.ico"))
            {
                _notPlayingIcon = new Icon(stream);
            }
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpotifySleepModeStopperGui.music_playing.ico"))
            {
                _playingIcon = new Icon(stream);
            }
            SetNotPlayingGui();
            _notifyIcon.Visible = true;

            var contextMenu  = new ContextMenu();
            var exitMenuItem = new MenuItem();
            exitMenuItem.Index  = 2;
            exitMenuItem.Text   = ExitMess;
            exitMenuItem.Click += exit_Click;

            _screenBehaviorMenuItem       = new MenuItem();
            _screenBehaviorMenuItem.Index = 1;

            if (_facade.IsScreenSleepEnabled())
            {
                _screenBehaviorMenuItem.Text = ScreenSleepEnabledMess;
            }
            else
            {
                _screenBehaviorMenuItem.Text = ScreenSleepDisabledMess;
            }

            _screenBehaviorMenuItem.Click += ScreenBehaviorMenuItemOnClick;

            _autoStartMenuItem       = new MenuItem();
            _autoStartMenuItem.Index = 0;

            if (_facade.IsAutoStartEnabled())
            {
                _autoStartMenuItem.Text = AppStartingOnStartupMess; //"Auto Startup";
            }
            else
            {
                _autoStartMenuItem.Text = AppNotStartingOnStartupMess;
            }

            _autoStartMenuItem.Click += AutoStartMenuItemOnClick;

            contextMenu.MenuItems.AddRange(new[] { _autoStartMenuItem, _screenBehaviorMenuItem, exitMenuItem });
            _notifyIcon.ContextMenu = contextMenu;
            #endregion

            _facade.StartListening();
        }