private void TmCheckPower_Tick(object sender, EventArgs e) { var idleTimeMin = PcIdle.GetIdleTimeMin(); // Refresh Form data. ShowPowerStatus(); TbIdleTime.Text = idleTimeMin.ToString("D"); if (NotifyVoice && NotifyWind) { // Check if activate Voice notification for idle time. IdleVoiceNotify = !NotifyWind || idleTimeMin >= PcIdle.MaxIdleTime; } if (!Battery.CheckPowerLevel()) { Battery.AuxAlert = false; return; } BtnSpeak.Enabled = false; if (Battery.AuxAlert && (Voice.AuxNotVolume += 10) > 100) { Voice.AuxNotVolume = 100; } NewNotification($"{Settings.Default.PcName}. {Battery.Msg}"); TmCheckPower.Stop(); TmWaitForResp.Start(); GbNextNot.Enabled = true; Application.DoEvents(); }
private void NotificationsToolStripMenuItem_Click(object sender, EventArgs e) { var frmNotSetTime = new FrmNotSetTime(_timeBattChk, _auxTimeBattChk, PcInnactivity.MaxIdleTime, Battery.LowBattLevel, Battery.HighBattLevel); frmNotSetTime.ShowDialog(); if (!frmNotSetTime.Changes) { return; } //Stop timers. TmCheckPower.Stop(); TmWaitForResp.Stop(); //Get frmNotSetTime values. _timeBattChk = frmNotSetTime.TimeBattChk; _auxTimeBattChk = frmNotSetTime.AuxTimeBattChk; Battery.ChangeLowBattLevel(frmNotSetTime.LowBattery); Battery.ChangeHighBattLevel(frmNotSetTime.HighBattery); PcInnactivity.ChangeMaxIdleTime(frmNotSetTime.IdleTime); //Save in properties Settings.Default.BatteryHigh = Battery.HighBattLevel; Settings.Default.BatteryLow = Battery.LowBattLevel; Settings.Default.PcIdleTime = PcInnactivity.MaxIdleTime; Settings.Default.TimeBattChk = _timeBattChk; Settings.Default.TimeAuxBattChk = _auxTimeBattChk; Settings.Default.Save(); //Changes timer intervals. TmCheckPower.Interval = (int)_timeBattChk * 1000; TmWaitForResp.Interval = (int)_auxTimeBattChk * 60000; //Restart timers. TmCheckPower.Start(); TmWaitForResp.Start(); }
//TODO: Check the constant trigger event. private void PowerModeChanged(object sender, PowerModeChangedEventArgs e) { //ShowPowerStatus(); switch (e.Mode) { case PowerModes.Resume: Battery.AuxAlert = false; break; case PowerModes.StatusChange: switch (Battery.ChargeStatus) { case BatteryChargeStatus.NoSystemBattery: TmCheckPower.Stop(); TmWaitForResp.Stop(); // var notifyIcon = Resources.ico_WithoutBatt; NotifyIcon.Icon = notifyIcon; Icon = notifyIcon; break; case BatteryChargeStatus.Charging: if (!TmWaitForResp.Enabled) { break; } TmWaitForResp.Stop(); TmCheckPower.Start(); break; // ReSharper disable RedundantCaseLabel case BatteryChargeStatus.Unknown: case BatteryChargeStatus.High: case BatteryChargeStatus.Low: case BatteryChargeStatus.Critical: // ReSharper restore RedundantCaseLabel default: // //notifyIcon = Battery.IsCharging ? Resources.ico_chargingNormal : Resources.ico_DisconnectNormal; // if (!TmWaitForResp.Enabled) { break; } TmWaitForResp.Stop(); TmCheckPower.Start(); AlertChecked(false); break; } break; case PowerModes.Suspend: Voice.Checked(); break; default: throw new NotImplementedException(); } }
private void SettingsToolStripMenuItem_Click(object sender, EventArgs e) { //TODO: Fix the way to pass parameters. using (var formSettings = new FormSettings(TimeBatteryCheck, AuxTimeBatteryCheck, PcIdle.MaxIdleTime, Battery.LowBatteryLvl, Battery.HighBatteryLvl, Voice, NotifyWind, NotifyVoice, Battery.AlertStatus)) { //Recall for check if there is an installed voice. Voice.GetVoices(); // SHOW Form formSettings.ShowDialog(); // Check if the user make any change. if (!formSettings.HasChanges) { return; } #region Notification //Stop timers. // Save the Status of the Timer. //var isTmCheckPowerEnabled = TmCheckPower.Enabled; AlertChecked(false); TmCheckPower.Stop(); TmWaitForResp.Stop(); // Battery.ChangeAlertStatus(new[] { formSettings.ChBoxLowBat, formSettings.ChBoxHighBat }); Battery.ChangePrevAlert(Any); Battery.ResetAlert(); //Get formSettings values. NotifyWind = formSettings.NotifyWind; NotifyVoice = formSettings.NotifyVoice; TimeBatteryCheck = formSettings.TimeBatChk; AuxTimeBatteryCheck = formSettings.AuxTimeBatChk; Battery.ChangeLowBatteryLvl(formSettings.LowBattery); Battery.ChangeHighBatteryLvl(formSettings.HighBattery); PcIdle.ChangeMaxIdleTime(formSettings.IdleTime); //Save in properties Settings.Default.BatteryHigh = Battery.HighBatteryLvl; Settings.Default.BatteryLow = Battery.LowBatteryLvl; Settings.Default.PcIdleTime = PcIdle.MaxIdleTime; Settings.Default.TimeBattChk = TimeBatteryCheck; Settings.Default.TimeAuxBattChk = AuxTimeBatteryCheck; Settings.Default.NotifyWind = NotifyWind; Settings.Default.NotifyVoice = NotifyVoice; Settings.Default.AlertStatus = string.Join(",", Battery.AlertStatus); //Changes timer intervals. TmCheckPower.Interval = (int)TimeBatteryCheck * 1000; AuxAlertTime = (int)(AuxTimeBatteryCheck * 60); ProgBarNextAlert.Maximum = AuxAlertTime; //Restart timers. //TmCheckPower.Enabled = isTmCheckPowerEnabled; TmCheckPower.Start(); #endregion #region Voz try { Settings.Default.VoiceName = formSettings.CurrentVoice; Settings.Default.VolNot = formSettings.NotifyVolume; Voice.ChangeCurrentVoice(formSettings.CurrentVoice); Voice.ChangeNotVolume(formSettings.NotifyVolume); } catch (Exception exc) { MessageBox.Show(exc.Message, @"Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion Voice?.ChangePcName(formSettings.PcName); Settings.Default.PcName = formSettings.PcName; Settings.Default.Save(); } }