Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store todays screen time #126

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading