Ejemplo n.º 1
0
        public MainWindow(MainViewModel viewModel, NotifyIconService notifyIconService)
        {
            InitializeComponent();

            this.viewModel   = viewModel;
            this.DataContext = this.viewModel;

            notifyIconService.Clicked        += (s, e) => this.ToggleWindow();
            notifyIconService.CloseRequested += (s, e) => this.Close();

            this.Loaded += (s, e) =>
            {
                var windowHandle = new WindowInteropHelper(this).Handle;
                Win32Interop.HideWindowFromAltTab(windowHandle);
                Win32Interop.PowerSchemeChanged += this.OnPowerPlanChanged;
                Win32Interop.RegisterForPowerSettingNotification(windowHandle);

                this.viewModel.UpdatePowerPlans();
            };

            this.Closing += (s, e) =>
            {
                var windowHandle = new WindowInteropHelper(this).Handle;
                Win32Interop.PowerSchemeChanged -= this.OnPowerPlanChanged;
                Win32Interop.UnregisterForPowerSettingNotification(windowHandle);
            };
        }
Ejemplo n.º 2
0
        private void Application_Startup(object sender, StartupEventArgs startupEventArgs)
        {
            var notifyIconService = new NotifyIconService();
            //var powerPlanService = new WmiPowerPlanService();
            var powerPlanService = new PowerPlanService();

            this.MainWindow = new MainWindow(new MainViewModel(powerPlanService, notifyIconService), notifyIconService);
            this.MainWindow.Show();

            IconEditorWindow editor = null;

            notifyIconService.IconEditorLaunchRequested += (s, e) =>
            {
                if (editor == null || !editor.IsVisible)
                {
                    editor       = new IconEditorWindow(new IconEditorViewModel(notifyIconService, powerPlanService));
                    editor.Owner = this.MainWindow;
                    editor.Show();
                }
                else
                {
                    editor.Activate();
                }
            };
        }
Ejemplo n.º 3
0
        public void Stop()
        {
            dt.Stop();
            IncrementMin = Timer.DurationMin;
            IncrementSec = 0;
            Timer.State  = TimerState.Stopped;

            NotifyIconService.SetStatusIcon("Stopped");
        }
Ejemplo n.º 4
0
        public PowerPlanViewModel(IPowerPlan model, NotifyIconService notifyIconService)
        {
            this.model             = model;
            this.notifyIconService = notifyIconService;

            if (this.IsActive)
            {
                this.UpdateIcon();
            }
        }
Ejemplo n.º 5
0
        public void Pause()
        {
            if (Timer.State == TimerState.Paused)
            {
                return;
            }
            dt.Stop();
            Timer.State = TimerState.Paused;

            NotifyIconService.SetStatusIcon("Paused");
        }
Ejemplo n.º 6
0
        public IconEditorViewModel(NotifyIconService notifyIconService, IPowerPlanService powerPlanService)
        {
            this.notifyIconService = notifyIconService;

            this.ApplyCommand         = new DelegateCommand(this.Apply);
            this.LoadDefaultsCommand  = new DelegateCommand(this.RevertToDefault);
            this.RevertChangesCommand = new DelegateCommand(this.RevertChanges);

            this.CreatePowerPlanViewModels(powerPlanService);
            this.LoadPreviousState();
            this.RevertChanges();
        }
Ejemplo n.º 7
0
        public void Start()
        {
            if (Timer.State == TimerState.Started)
            {
                return;
            }
            else if (Timer.State == TimerState.Stopped)
            {
                IncrementMin = Timer.DurationMin;
            }
            dt.Start();

            NotifyIconService.SetStatusIcon("Started");
        }
Ejemplo n.º 8
0
 public MainViewModel(IPowerPlanService powerPlanService, NotifyIconService notifyIconService)
 {
     this.powerPlanService  = powerPlanService;
     this.notifyIconService = notifyIconService;
 }
Ejemplo n.º 9
0
 public void Reset()
 {
     NotifyIconService.ResetStatusIcon();
     IsConnected = null;
 }
Ejemplo n.º 10
0
 public void Disconnect()
 {
     NotifyIconService.SetStatusIcon("disconnected");
     IsConnected = false;
 }
Ejemplo n.º 11
0
 public void Connect()
 {
     NotifyIconService.SetStatusIcon("connected");
     IsConnected = true;
 }