Skip to content

Commit

Permalink
almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalmers committed Jul 16, 2024
1 parent 462bb39 commit 27a88de
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 53 deletions.
15 changes: 1 addition & 14 deletions DesktopClock/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Diagnostics;
using System.IO;
using System.Windows;
using DesktopClock.Properties;
using Microsoft.Win32;

namespace DesktopClock;
Expand All @@ -14,18 +13,6 @@ public partial class App : Application
{
public static FileInfo MainFileInfo = new(Process.GetCurrentProcess().MainModule.FileName);

/// <summary>
/// Gets the time zone selected in settings, or local by default.
/// </summary>
public static TimeZoneInfo GetTimeZone() =>
DateTimeUtil.TryFindSystemTimeZoneById(Settings.Default.TimeZone, out var timeZoneInfo) ? timeZoneInfo : TimeZoneInfo.Local;

/// <summary>
/// Sets the time zone to be used.
/// </summary>
public static void SetTimeZone(TimeZoneInfo timeZone) =>
Settings.Default.TimeZone = timeZone.Id;

/// <summary>
/// Sets or deletes a value in the registry which enables the current executable to run on system startup.
/// </summary>
Expand All @@ -50,4 +37,4 @@ static string GetSha256Hash(string text)
else
key?.DeleteValue(keyName, false);
}
}
}
34 changes: 5 additions & 29 deletions DesktopClock/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public MainWindow()
InitializeComponent();
DataContext = this;

_timeZone = App.GetTimeZone();
_timeZone = Settings.Default.GetTimeZoneInfo();
UpdateCountdownEnabled();

Settings.Default.PropertyChanged += (s, e) => Dispatcher.Invoke(() => Settings_PropertyChanged(s, e));
Expand Down Expand Up @@ -101,29 +101,14 @@ public void HideForNow()
public void SetFormat(string format) => Settings.Default.Format = format;

/// <summary>
/// Explains how to write a format, then asks the user if they want to view a website and advanced settings to do so.
/// Opens the setting configuration window.
/// </summary>
[RelayCommand]
public void FormatWizard()
public void OpenSettings()
{
var result = MessageBox.Show(this,
$"In advanced settings: edit \"{nameof(Settings.Default.Format)}\" using special \"Custom date and time format strings\", then save." +
"\n\nOpen advanced settings and a tutorial now?",
Title, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.OK);

if (result != MessageBoxResult.OK)
return;

Process.Start("https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings");
OpenSettings();
SettingsWindow.ShowSingletonSettingsWindow(this);
}

/// <summary>
/// Sets the time zone ID in settings to the given time zone ID.
/// </summary>
[RelayCommand]
public void SetTimeZone(TimeZoneInfo tzi) => App.SetTimeZone(tzi);

/// <summary>
/// Creates a new clock executable and starts it.
/// </summary>
Expand All @@ -150,15 +135,6 @@ public void NewClock()
Process.Start(newExePath);
}

/// <summary>
/// Opens the setting configuration window.
/// </summary>
[RelayCommand]
public void OpenSettings()
{
SettingsWindow.ShowSingletonSettingsWindow(this);
}

/// <summary>
/// Opens the GitHub Releases page.
/// </summary>
Expand Down Expand Up @@ -227,7 +203,7 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
switch (e.PropertyName)
{
case nameof(Settings.Default.TimeZone):
_timeZone = App.GetTimeZone();
_timeZone = Settings.Default.GetTimeZoneInfo();
UpdateTimeString();
break;

Expand Down
10 changes: 8 additions & 2 deletions DesktopClock/Properties/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private Settings()
public string Format { get; set; } = "{ddd}, {MMM dd}, {h:mm:ss tt}";

/// <summary>
/// Format string shown on the clock in countdown mode.
/// Format string for the countdown mode. If left blank, it will be dynamic.
/// </summary>
/// <remarks>
/// See: <see href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-timespan-format-strings">Custom TimeSpan format strings</see>.
Expand Down Expand Up @@ -129,7 +129,7 @@ private Settings()
public double BackgroundCornerRadius { get; set; } = 1;

/// <summary>
/// Path to the background image. If left blank, a solid color will be used.
/// Path to the background image. If left blank, solid color will be used.
/// </summary>
public string BackgroundImagePath { get; set; } = string.Empty;

Expand Down Expand Up @@ -325,6 +325,12 @@ public void ScaleHeight(double steps)
Height = (int)exp;
}

/// <summary>
/// Gets the time zone selected in settings, or local by default.
/// </summary>
public TimeZoneInfo GetTimeZoneInfo() =>
DateTimeUtil.TryFindSystemTimeZoneById(TimeZone, out var timeZoneInfo) ? timeZoneInfo : TimeZoneInfo.Local;

public void Dispose()
{
// We don't dispose of the watcher anymore because it would actually hang indefinitely if you had multiple instances of the same clock open.
Expand Down
15 changes: 7 additions & 8 deletions DesktopClock/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ResizeMode="CanMinimize"
SizeToContent="Height"
WindowStartupLocation="CenterScreen">
<TabControl Padding="12,12,12,0" TabIndex="{Binding Settings.SettingsTabIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<TabControl Padding="12,12,12,0" SelectedIndex="{Binding Settings.SettingsTabIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<TabItem Header="Format">
<StackPanel>
<TextBlock Text="Date and Time Format:" />
Expand All @@ -24,7 +24,7 @@

<TextBlock Text="Countdown Format:" />
<TextBox Text="{Binding Settings.CountdownFormat, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Text="Format string shown on the clock display when in countdown mode."
<TextBlock Text="Format string for the countdown mode. If left blank, it will be dynamic."
FontStyle="Italic"
FontSize="10"
Margin="0,0,0,12" />
Expand Down Expand Up @@ -53,18 +53,17 @@
FontStyle="Italic"
FontSize="10"
Margin="0,0,0,12" />
</StackPanel>
</TabItem>

<TabItem Header="Appearance">
<StackPanel>
<TextBlock Text="Font Family:" />
<ComboBox ItemsSource="{Binding FontFamilies}" SelectedItem="{Binding Settings.FontFamily, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Text="Font used for the clock's text."
FontStyle="Italic"
FontSize="10"
Margin="0,0,0,12" />
</StackPanel>
</TabItem>

<TabItem Header="Appearance">
<StackPanel>

<TextBlock Text="Text Color:" />
<TextBox Text="{Binding Settings.TextColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
Expand Down Expand Up @@ -117,7 +116,7 @@
Click="BrowseBackgroundImagePath"
Grid.Column="1" />
</Grid>
<TextBlock Text="Path to the background image. If left blank, a solid color will be used."
<TextBlock Text="Path to the background image. If left blank, solid color will be used."
FontStyle="Italic"
FontSize="10"
Margin="0,0,0,12" />
Expand Down

0 comments on commit 27a88de

Please sign in to comment.