Exemplo 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);
            };
        }
Exemplo 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();
                }
            };
        }
Exemplo n.º 3
0
        public void Stop()
        {
            dt.Stop();
            IncrementMin = Timer.DurationMin;
            IncrementSec = 0;
            Timer.State  = TimerState.Stopped;

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

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

            NotifyIconService.SetStatusIcon("Paused");
        }
Exemplo 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();
        }
Exemplo 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");
        }
Exemplo n.º 8
0
 public MainViewModel(IPowerPlanService powerPlanService, NotifyIconService notifyIconService)
 {
     this.powerPlanService  = powerPlanService;
     this.notifyIconService = notifyIconService;
 }
Exemplo n.º 9
0
 public void Reset()
 {
     NotifyIconService.ResetStatusIcon();
     IsConnected = null;
 }
Exemplo n.º 10
0
 public void Disconnect()
 {
     NotifyIconService.SetStatusIcon("disconnected");
     IsConnected = false;
 }
Exemplo n.º 11
0
 public void Connect()
 {
     NotifyIconService.SetStatusIcon("connected");
     IsConnected = true;
 }