private void BrightnessHotkeyEvent(bool IsUp) { (FindResource("hideMe") as Storyboard).Begin(this); IniData data = SettingsController.GetCurrentSettings(); int StepSize = 5; if (int.TryParse(data["Hotkeys"]["StepSize"], out int StepSizeValue)) { StepSize = StepSizeValue; } try { double StepDouble = (double)StepSize / 100; DisplayConfiguration.PHYSICAL_MONITOR Handle = DisplayConfiguration.GetPhysicalMonitors(DisplayConfiguration.GetCurrentMonitor())[0]; /*Task.Run(() => { try { DisplayConfiguration.SetBrightnessOffset(Handle, IsUp ? StepDouble : -StepDouble); } catch { } });*/ if (HotkeyPopupWindow.IsVisible) { int HotkeyPopupBrightness = int.Parse(HotkeyPopupWindow.PercentText.Text); int NewBrightness = HotkeyPopupBrightness + (IsUp ? StepSize : -StepSize); if (NewBrightness > 100) { NewBrightness = 100; } else if (NewBrightness < 0) { NewBrightness = 0; } Task.Run(() => { try { DisplayConfiguration.SetMonitorBrightness(Handle, (double)NewBrightness / 100, HotkeyPopupWindow.dwMinimumBrightness, HotkeyPopupWindow.dwMaximumBrightness); } catch { } }); HotkeyPopupWindow.PercentText.Text = NewBrightness.ToString(); HotkeyPopupWindow.ShowMe(data["Misc"]["HotkeyPopupPosition"]); } else { DisplayConfiguration.MonitorExtremums MonExtems = DisplayConfiguration.GetMonitorExtremums(Handle); double CurrentBrightness = (double)(MonExtems.Current - MonExtems.Min) / (double)(MonExtems.Max - MonExtems.Min); Task.Run(() => { try { DisplayConfiguration.SetBrightnessOffset(Handle, IsUp ? StepDouble : -StepDouble, CurrentBrightness, MonExtems.Min, MonExtems.Max); } catch { } }); HotkeyPopupWindow.dwMinimumBrightness = MonExtems.Min; HotkeyPopupWindow.dwMaximumBrightness = MonExtems.Max; HotkeyPopupWindow.dwCurrentBrightness = MonExtems.Current; HotkeyPopupWindow.PercentText.Text = ((CurrentBrightness * 100) + (IsUp ? StepSize : -StepSize)).ToString(); HotkeyPopupWindow.ShowMe(data["Misc"]["HotkeyPopupPosition"]); } } catch { } }
public void LoadSettings() { SettingsController.LoadSettings(); IniData data = SettingsController.GetCurrentSettings(); if (data["Hotkeys"]["HotkeysEnable"] == "1") { SetHotkeysByStrings(data["Hotkeys"]["HotkeyUp"], data["Hotkeys"]["HotkeyDown"]); } if (data["Misc"]["Blur"] == "1" && Environment.OSVersion.Version.Major == 10) { Background = null; AcrylicWindow.SetEnabled(this, true); } UpdateCheckTimer.Tick += (sender, e) => { CheckForUpdates(false); }; if (data["Updates"]["DisableCheckEveryDay"] != "1") { UpdateCheckTimer.Start(); } if (data["Updates"]["DisableCheckOnStartup"] != "1") { CheckForUpdates(false); } //AutoBrightness if (data["AutoBrightness"]["Enabled"] == "1") { CheckForSunriset.Start(); } SetupAutoBrightnessTimer(); TrayIcon.TrayBalloonTipClicked += (senderB, eB) => new Update().Window_Loaded(); }
private void AutoBrightnessOnPowerChange(object s, PowerModeChangedEventArgs e) { IniData data = SettingsController.GetCurrentSettings(); switch (e.Mode) { case PowerModes.Resume: if (data["AutoBrightness"]["Enabled"] == "1") { CheckForSunriset.Start(); Task.Run(() => { System.Threading.Thread.Sleep(4000); SetAutoBrightness(1); }); } break; case PowerModes.Suspend: CheckForSunriset.Stop(); break; } }
public void CheckForUpdatesAsync() { IniData data = SettingsController.GetCurrentSettings(); WebClient client = new WebClient(); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; client.Headers.Add("user-agent", "request"); client.DownloadStringAsync(new Uri("https://api.github.com/repos/nik9play/tinyBrightness/releases/latest")); client.DownloadStringCompleted += (sender, e) => { try { JObject json_res = JObject.Parse(e.Result); Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; int CurrentVersionMinor = version.Minor; NewVersionMinor = int.Parse(json_res["tag_name"].ToString().Split('.')[1]); NewVersionString = json_res["tag_name"].ToString(); //1 is exe and 0 is zip DownloadUrl = json_res["assets"][1]["browser_download_url"].ToString(); Description = json_res["name"].ToString(); ChangeLogUrl = json_res["html_url"].ToString(); if ((NewVersionMinor > CurrentVersionMinor) && (data["Updates"]["SkipVersion"] != json_res["tag_name"].ToString())) { OnCheckingCompleted(true); } else { OnCheckingCompleted(false); } } catch { OnCheckingCompleted(false); } }; }