Esempio n. 1
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();
                }
            };
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public LockUnlockPowerProfileApplicationContext()
        {
            _pluginService = new PluginService();

            foreach (IPlugin plugin in _pluginService.GetEnabledPlugins())
            {
                plugin.OnStart();
                LoggerService.Instance.AddLog($"Plugin loaded {plugin.Name}");
            }

            _rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

            _startUp = new MenuItem("Run on startup", RunOnStartUp);

            _settingsService             = new SettingsService(_pluginService);
            Application.ApplicationExit += Exit;
            // Initialize Tray Icon
            ContextMenu contextMenu = new ContextMenu(new MenuItem[]
            {
                _startUp,
                new MenuItem("Exit", Exit)
            });

            _trayIcon = new NotifyIcon()
            {
                Icon        = Resources.logo,
                Text        = Application.ProductName,
                ContextMenu = contextMenu,
                Visible     = true
            };
            _trayIcon.DoubleClick += ShowSettings;

            SystemEvents.SessionSwitch += SystemEventsSessionSwitch;

            _startUp.Checked = _rk?.GetValue(Application.ProductName) != null;

            _powerPlanService = new PowerPlanService(_settingsService, _pluginService);
        }