From 27a88de0f83be959a461358908e5ecff8a077692 Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Tue, 16 Jul 2024 00:20:04 -0500 Subject: [PATCH] almost done --- DesktopClock/App.xaml.cs | 15 +------------ DesktopClock/MainWindow.xaml.cs | 34 +++++------------------------ DesktopClock/Properties/Settings.cs | 10 +++++++-- DesktopClock/SettingsWindow.xaml | 15 ++++++------- 4 files changed, 21 insertions(+), 53 deletions(-) diff --git a/DesktopClock/App.xaml.cs b/DesktopClock/App.xaml.cs index 618c50f..4e4ce6b 100644 --- a/DesktopClock/App.xaml.cs +++ b/DesktopClock/App.xaml.cs @@ -2,7 +2,6 @@ using System.Diagnostics; using System.IO; using System.Windows; -using DesktopClock.Properties; using Microsoft.Win32; namespace DesktopClock; @@ -14,18 +13,6 @@ public partial class App : Application { public static FileInfo MainFileInfo = new(Process.GetCurrentProcess().MainModule.FileName); - /// - /// Gets the time zone selected in settings, or local by default. - /// - public static TimeZoneInfo GetTimeZone() => - DateTimeUtil.TryFindSystemTimeZoneById(Settings.Default.TimeZone, out var timeZoneInfo) ? timeZoneInfo : TimeZoneInfo.Local; - - /// - /// Sets the time zone to be used. - /// - public static void SetTimeZone(TimeZoneInfo timeZone) => - Settings.Default.TimeZone = timeZone.Id; - /// /// Sets or deletes a value in the registry which enables the current executable to run on system startup. /// @@ -50,4 +37,4 @@ static string GetSha256Hash(string text) else key?.DeleteValue(keyName, false); } -} \ No newline at end of file +} diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index f109f0f..54d5744 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -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)); @@ -101,29 +101,14 @@ public void HideForNow() public void SetFormat(string format) => Settings.Default.Format = format; /// - /// 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. /// [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); } - /// - /// Sets the time zone ID in settings to the given time zone ID. - /// - [RelayCommand] - public void SetTimeZone(TimeZoneInfo tzi) => App.SetTimeZone(tzi); - /// /// Creates a new clock executable and starts it. /// @@ -150,15 +135,6 @@ public void NewClock() Process.Start(newExePath); } - /// - /// Opens the setting configuration window. - /// - [RelayCommand] - public void OpenSettings() - { - SettingsWindow.ShowSingletonSettingsWindow(this); - } - /// /// Opens the GitHub Releases page. /// @@ -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; diff --git a/DesktopClock/Properties/Settings.cs b/DesktopClock/Properties/Settings.cs index b4ee5c4..98a4b3f 100644 --- a/DesktopClock/Properties/Settings.cs +++ b/DesktopClock/Properties/Settings.cs @@ -81,7 +81,7 @@ private Settings() public string Format { get; set; } = "{ddd}, {MMM dd}, {h:mm:ss tt}"; /// - /// Format string shown on the clock in countdown mode. + /// Format string for the countdown mode. If left blank, it will be dynamic. /// /// /// See: Custom TimeSpan format strings. @@ -129,7 +129,7 @@ private Settings() public double BackgroundCornerRadius { get; set; } = 1; /// - /// 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. /// public string BackgroundImagePath { get; set; } = string.Empty; @@ -325,6 +325,12 @@ public void ScaleHeight(double steps) Height = (int)exp; } + /// + /// Gets the time zone selected in settings, or local by default. + /// + 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. diff --git a/DesktopClock/SettingsWindow.xaml b/DesktopClock/SettingsWindow.xaml index 95c8c8a..13756e7 100644 --- a/DesktopClock/SettingsWindow.xaml +++ b/DesktopClock/SettingsWindow.xaml @@ -12,7 +12,7 @@ ResizeMode="CanMinimize" SizeToContent="Height" WindowStartupLocation="CenterScreen"> - + @@ -24,7 +24,7 @@ - @@ -53,18 +53,17 @@ FontStyle="Italic" FontSize="10" Margin="0,0,0,12" /> + + + + - - - - - @@ -117,7 +116,7 @@ Click="BrowseBackgroundImagePath" Grid.Column="1" /> -