diff --git a/NeedABreak/App.config b/NeedABreak/App.config index 8c59b60..088cf4f 100644 --- a/NeedABreak/App.config +++ b/NeedABreak/App.config @@ -44,6 +44,12 @@ DEBUG 3600 + + 00:00:00 + + + + diff --git a/NeedABreak/App.xaml.cs b/NeedABreak/App.xaml.cs index 0b35fdc..8d26f8c 100644 --- a/NeedABreak/App.xaml.cs +++ b/NeedABreak/App.xaml.cs @@ -69,6 +69,16 @@ static App() //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en"); //System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en"); ConfigureLog4Net(); + +#if DEBUG + Logger.Debug($"User settings path = {ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath}"); +#endif + + if (NeedABreak.Properties.Settings.Default.DayStart == DateTime.Today) + { + _cumulativeScreenTime = NeedABreak.Properties.Settings.Default.TodayScreenTime; + } + _dayStart = DateTime.Today; _startShowingScreen = DateTime.Now; } @@ -107,9 +117,19 @@ public App() StartTimer(); Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; + Exit += App_Exit; + Logger.Debug("App ctor end"); } + private void App_Exit(object sender, ExitEventArgs e) + { + // Store today screen time to restore it when app is launched + NeedABreak.Properties.Settings.Default.TodayScreenTime = GetTodayScreenTime(); + NeedABreak.Properties.Settings.Default.DayStart = _dayStart; + NeedABreak.Properties.Settings.Default.Save(); + } + private async void UpdateToolTipTimer_Elapsed(object sender, ElapsedEventArgs e) { await Current.Dispatcher.InvokeAsync(() => diff --git a/NeedABreak/NeedABreak.csproj b/NeedABreak/NeedABreak.csproj index cdad236..6685724 100644 --- a/NeedABreak/NeedABreak.csproj +++ b/NeedABreak/NeedABreak.csproj @@ -134,6 +134,11 @@ True Resources.resx + + True + True + Settings.settings + @@ -141,6 +146,12 @@ Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + diff --git a/NeedABreak/Properties/Settings.Designer.cs b/NeedABreak/Properties/Settings.Designer.cs index 7f005a9..947c685 100644 --- a/NeedABreak/Properties/Settings.Designer.cs +++ b/NeedABreak/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace NeedABreak.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.2.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -58,5 +58,28 @@ public int Delay { this["Delay"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("00:00:00")] + public global::System.TimeSpan TodayScreenTime { + get { + return ((global::System.TimeSpan)(this["TodayScreenTime"])); + } + set { + this["TodayScreenTime"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.DateTime DayStart { + get { + return ((global::System.DateTime)(this["DayStart"])); + } + set { + this["DayStart"] = value; + } + } } } diff --git a/NeedABreak/Properties/Settings.settings b/NeedABreak/Properties/Settings.settings index ca55dd3..5141fba 100644 --- a/NeedABreak/Properties/Settings.settings +++ b/NeedABreak/Properties/Settings.settings @@ -11,5 +11,11 @@ 3600 + + 00:00:00 + + + + \ No newline at end of file