diff --git a/ChronoFagTimer/Config.cs b/ChronoFagTimer/Config.cs index 9d74aa9..9926ee0 100644 --- a/ChronoFagTimer/Config.cs +++ b/ChronoFagTimer/Config.cs @@ -16,6 +16,7 @@ */ using Hjson; +using Microsoft.Win32; using NLog; using System; using System.Collections.Generic; @@ -220,7 +221,67 @@ private Color FromHex(string hex) int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber)); } + #region Registy + string regKey = @"SOFTWARE\ChronoFagTimer"; + public void SaveCurrentState(int counter, int currentRound, DateTime lastActiveTime) + { + var key = Registry.CurrentUser.CreateSubKey(regKey); + if (key != null) + { + key.SetValue("Counter", counter); + key.SetValue("CurrentRound", currentRound); + key.SetValue("LastActiveTime", lastActiveTime); + key.Close(); + } + } + + public int LoadCounterState() + { + var key = Registry.CurrentUser.CreateSubKey(regKey); + int value = 0; + if (key != null) + { + var obj = key.GetValue("Counter"); + if (obj != null) + { + int.TryParse(obj.ToString(), out value); + } + } + key.Close(); + return value; + } + public int LoadCurrentRoundState() + { + var key = Registry.CurrentUser.CreateSubKey(regKey); + int value = 0; + if (key != null) + { + var obj = key.GetValue("CurrentRound"); + if (obj != null) + { + int.TryParse(obj.ToString(), out value); + } + } + key.Close(); + return value; + } + public DateTime LoadLastActiveTimeState() + { + var key = Registry.CurrentUser.CreateSubKey(regKey); + DateTime value = DateTime.Now; + if (key != null) + { + var obj = key.GetValue("LastActiveTime"); + if (obj != null) + { + DateTime.TryParse(obj.ToString(), out value); + } + } + key.Close(); + return value; + } + #endregion } } diff --git a/ChronoFagTimer/Properties/AssemblyInfo.cs b/ChronoFagTimer/Properties/AssemblyInfo.cs index f883f26..fdf3c15 100644 --- a/ChronoFagTimer/Properties/AssemblyInfo.cs +++ b/ChronoFagTimer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.3.0")] -[assembly: AssemblyFileVersion("0.1.3.0")] +[assembly: AssemblyVersion("0.1.4.0")] +[assembly: AssemblyFileVersion("0.1.4.0")] diff --git a/ChronoFagTimer/TomatoForm.cs b/ChronoFagTimer/TomatoForm.cs index 62d6767..42d5d6d 100644 --- a/ChronoFagTimer/TomatoForm.cs +++ b/ChronoFagTimer/TomatoForm.cs @@ -261,6 +261,8 @@ private void MenuStart_Click(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e) { + Logger.Info("Initialization..."); + timeUnitTimer = new Timer() { Interval = 1000, @@ -281,12 +283,15 @@ private void Form1_Load(object sender, EventArgs e) lblPomodoroTime.Font = new Font(FontFamily.GenericSerif, Helper.GetTimerFontSize()); lblPomodoroTime.ForeColor = config.Face.PomodoroForeground; - - startPomodoro(); this.WindowState = FormWindowState.Normal; - updateTomatoPosition(); - updateElementsPosition(); + + // load state from registry + CurrentRound = config.LoadCurrentRoundState(); + Counter = config.LoadCounterState(); + lastActiveTime = config.LoadLastActiveTimeState(); + + Logger.Info("Initialized"); } private void MenuAutostart_Click(object sender, EventArgs e) @@ -597,20 +602,18 @@ private void _timeUnitTimer_Elapsed(object sender, EventArgs e) updateTomatoPosition(); } updateElementsPosition(); + + config.SaveCurrentState(Counter, CurrentRound, lastActiveTime); } /// /// Last timer active time /// - DateTime? lastActiveTime = null; + DateTime lastActiveTime; private void handleSleepLeap() { var now = DateTime.Now; - if (lastActiveTime == null) - { - // first assign - lastActiveTime = now; - } + var diff = (int)(now - (DateTime)lastActiveTime).TotalSeconds; // if was leap @@ -761,7 +764,7 @@ private void updateElementsPosition() lblDownTitle.Left = this.Width / 2 - lblDownTitle.Width / 2; lblDownTitle.Top = this.Height - (this.Height - lblBreakTime.Top) / 4; - btnExtraTime.Width = btnExtraTime.Height = 100; + btnExtraTime.Width = btnExtraTime.Height = this.Height / 12; btnExtraTime.Left = this.Height - lblDownTitle.Top - btnExtraTime.Height; btnExtraTime.Top = lblDownTitle.Top; } @@ -848,7 +851,7 @@ private bool mouseShowPomodoro() } - #region show/hide animation +#region show/hide animation /// /// Show form with fade animation @@ -922,7 +925,7 @@ public void FadeOut(bool immediate = false) - #endregion +#endregion /// @@ -983,11 +986,14 @@ private bool AllowMouseEventForCurrentProcess() /// private int getExtraBreakTime() { - return (int)Math.Floor((double)CurrentTimeUnit.CounterLimit / (getPrevTime(typeof(Pomodoro)).CounterLimit / config.ExtraTime)); + var a = (double)CurrentTimeUnit.CounterLimit; + var b = (double)getPrevTime(typeof(Pomodoro)).CounterLimit / config.ExtraTime; + int result = (int)Math.Floor(a / b); + return result; } - #region User Timers +#region User Timers /// @@ -1107,6 +1113,6 @@ public void RemoveCustomTimer(string key) } - #endregion +#endregion } } diff --git a/ChronoFagTimer/config.hjson b/ChronoFagTimer/config.hjson index 9fa83cf..9cfdf4e 100644 --- a/ChronoFagTimer/config.hjson +++ b/ChronoFagTimer/config.hjson @@ -136,7 +136,7 @@ "breaktimer": { # lock keyboard during a break without a possibility to exit, also disable menu items "stop" and "exit" (true | false) - "lockmode": true, + "lockmode": false, "sound": "sound/break.mp3", @@ -168,7 +168,7 @@ "idletitle": "IDLE MODE", "extramodetitle": "EXTRA MODE", "stopmodetitle": "STOP MODE", - "addextratime": "I need {0} more minutes to work right now.\n(Next break time will be increased to {1} minute(s))", + "addextratime": "Give me {0} more minutes to work right now.\n(next break time will be increased to {1} minute(s))", "lockmodesubtitle": "Workspace locked up, you have to rest", "freemodesubtitle": "Let's go away from keyboard for awhile", "start": "Start", @@ -176,7 +176,7 @@ "autostart": "Autostart", "about": "About...", "quit": "Quit", - "locked": "(locked)", + "quitlocked": "(locked)", "addtimer": "Add Timer...", "removetimer": "Remove Timer", "timercaption": "Caption",