/// <summary> /// Main application /// </summary> public App() { // Check for updates in Release mode #if !DEBUG _OnlineUpdateProcedure(); #endif InitializeComponent(); // Hook startup / exit actions Startup += _Starting; Exit += _Exiting; SessionEnding += (sender, e) => _Exiting(null, null); // Initialize controller components _settings = (Settings)FindResource("Settings"); var c = (Panel)((Window)FindResource("HiddenWindow")).Content; var pm = c.Children.OfType <PowerManagement.PowerManagement>().First(); var ri = c.Children.OfType <RawInput.RawInput>().First(); var gh = c.Children.OfType <GlobalHotKey>().First(); _autoKeyboard = new AutoKeyboardBacklightController(pm, ri); _autoScreen = new AutoScreenBrightnessController(gh); _autoScreen.BrightnessChanged += (se, ev) => { _lastPoint = new DataPoint(ev.Intensity, ev.Brightness); // Update the calibration graph if it is open if (_calibration != null) { _calibration.CurrentPoint = new DataPoint(ev.Intensity, ev.Brightness); } }; _autoKeyboard.Activity += (se, ev) => { // Record changes in OnLevel, used next time application runs if (ev.Act == AutoKeyboardBacklightController.ActivityEventArgs.Activity.OnLevelChanged) { _settings.Keyboard_OnLevel = _autoKeyboard.OnLevel; } // Refresh screen brightness on power resume events if (ev.Act == AutoKeyboardBacklightController.ActivityEventArgs.Activity.PowerResume) { if (_autoScreen.Enabled) { _ = _autoScreen.Retrigger(); } } }; // Triggers loading of the icon & menu in tray FindResource("SysTrayMenu"); FindResource("SysTrayIcon"); }
// Show the screen brightness vs ambient light level calibration window private void _ShowCalibration(object sender, RoutedEventArgs e) { if (_calibration == null) { // Create new window from saved points if not already open _calibration = new Calibration(_settings.Screen_LearnedPoints.Select(p => new DataPoint(p.Item1, p.Item2)).ToList(), _settings.Screen_Curvature); if (_lastPoint != null) { _calibration.CurrentPoint = (DataPoint)_lastPoint; } var isEn = _autoScreen.Enabled; var isHkEn = _autoScreen.HotKeyEnabled; _autoScreen.Enabled = false; _autoScreen.HotKeyEnabled = false; var tempScreen = new AutoScreenBrightnessController(null); tempScreen.BrightnessChanged += (sen, eve) => { _calibration.CurrentPoint = new DataPoint(eve.Intensity, eve.Brightness); }; _calibration.Refresh += (sen, eve) => { tempScreen.LearnedPoints = eve.LearnedPoints; tempScreen.Curvature = eve.Curvature; _ = tempScreen.Retrigger(); }; _calibration.ManualScreenBrightness += (sen, eve) => { byte br = (byte)Math.Round(eve.ScreenBrightness * 100.0); tempScreen.SetBrightnessSlider(br); _lastPoint = new DataPoint(_calibration.CurrentPoint.X, eve.ScreenBrightness); _calibration.CurrentPoint = (DataPoint)_lastPoint; }; _calibration.Closed += (sen, eve) => { _calibration = null; _autoScreen.Enabled = isEn; _autoScreen.HotKeyEnabled = isHkEn; }; _calibration.Apply += (sen, eve) => { // Transfer points on Apply _settings.Screen_Curvature = _calibration.Curvature; _settings.Screen_LearnedPoints.Clear(); _settings.Screen_LearnedPoints.AddRange(_calibration.LearnedPoints.Select(p => new Tuple <double, double>(p.X, p.Y)).ToList()); _settings.Screen_LearnedPoints = _settings.Screen_LearnedPoints; _ = _autoScreen.Retrigger(); }; } _calibration.Show(); }