Skip to content

Commit

Permalink
Store todays screen time (#126)
Browse files Browse the repository at this point in the history
* store today screen time
  • Loading branch information
bNobo authored Apr 19, 2024
1 parent 5791040 commit 85c9ba1
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions NeedABreak/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ DEBUG
<setting name="Delay" serializeAs="String">
<value>3600</value>
</setting>
<setting name="TodayScreenTime" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="DayStart" serializeAs="String">
<value />
</setting>
</NeedABreak.Properties.Settings>
</userSettings>
<runtime>
Expand Down
20 changes: 20 additions & 0 deletions NeedABreak/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(() =>
Expand Down
11 changes: 11 additions & 0 deletions NeedABreak/NeedABreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,24 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<Target Name="MATPrerequisite" BeforeTargets="PrepareForBuild" Condition="!Exists('$(MSBuildExtensionsPath)\Microsoft\Multilingual App Toolkit\Microsoft.Multilingual.ResxResources.targets')" Label="MultilingualAppToolkit">
<Warning Text="$(MSBuildProjectFile) is Multilingual build enabled, but the Multilingual App Toolkit is unavailable during the build. If building with Visual Studio, please check to ensure that toolkit is properly installed." />
</Target>
Expand Down
25 changes: 24 additions & 1 deletion NeedABreak/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions NeedABreak/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@
<Setting Name="Delay" Type="System.Int32" Scope="User">
<Value Profile="(Default)">3600</Value>
</Setting>
<Setting Name="TodayScreenTime" Type="System.TimeSpan" Scope="User">
<Value Profile="(Default)">00:00:00</Value>
</Setting>
<Setting Name="DayStart" Type="System.DateTime" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 85c9ba1

Please sign in to comment.