From c4cd246fb057c72225aad6da1e6e4c6fa7877a2c Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Thu, 26 Sep 2024 17:48:18 -0400 Subject: [PATCH] Initial code --- App.config | 27 +++++++ App.xaml | 7 ++ App.xaml.cs | 38 ++++++++++ Properties/AssemblyInfo.cs | 59 +++++++++++++++ Properties/Resources.Designer.cs | 73 ++++++++++++++++++ Properties/Resources.resx | 124 +++++++++++++++++++++++++++++++ Properties/Settings.Designer.cs | 74 ++++++++++++++++++ Properties/Settings.settings | 18 +++++ Resources/Application.ico | Bin 0 -> 10134 bytes TimeZoneEntry.cs | 7 ++ WindowSource.cs | 122 ++++++++++++++++++++++++++++++ WorldClockStatusWindow.csproj | 31 ++++++++ WorldClockStatusWindow.sln | 25 +++++++ 13 files changed, 605 insertions(+) create mode 100644 App.config create mode 100644 App.xaml create mode 100644 App.xaml.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 Properties/Resources.Designer.cs create mode 100644 Properties/Resources.resx create mode 100644 Properties/Settings.Designer.cs create mode 100644 Properties/Settings.settings create mode 100644 Resources/Application.ico create mode 100644 TimeZoneEntry.cs create mode 100644 WindowSource.cs create mode 100644 WorldClockStatusWindow.csproj create mode 100644 WorldClockStatusWindow.sln diff --git a/App.config b/App.config new file mode 100644 index 0000000..24584f9 --- /dev/null +++ b/App.config @@ -0,0 +1,27 @@ + + + + +
+ + + + + + + + + + + + True + + + ddd hh:mm:ss tt + + + [] + + + + \ No newline at end of file diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..89af37a --- /dev/null +++ b/App.xaml @@ -0,0 +1,7 @@ + + + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..9ec292f --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,38 @@ +using ChrisKaczor.Wpf.Windows.FloatingStatusWindow; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Windows; +using Settings = WorldClockStatusWindow.Properties.Settings; + +namespace WorldClockStatusWindow; + +public partial class App +{ + private List _windowSourceList; + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + StartManager.ManageAutoStart = true; + StartManager.AutoStartEnabled = !Debugger.IsAttached && Settings.Default.AutoStart; + StartManager.AutoStartChanged += (value => + { + Settings.Default.AutoStart = value; + Settings.Default.Save(); + }); + + _windowSourceList = + [ + new WindowSource() + ]; + } + + protected override void OnExit(ExitEventArgs e) + { + _windowSourceList.ForEach(ws => ws.Dispose()); + + base.OnExit(e); + } +} \ No newline at end of file diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6160fb9 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,59 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WorldClockStatusWindow")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WorldClockStatusWindow")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: SupportedOSPlatform("windows7.0")] +[assembly: NeutralResourcesLanguage("en-US")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..920a087 --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WorldClockStatusWindow.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WorldClockStatusWindow.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon ApplicationIcon { + get { + object obj = ResourceManager.GetObject("ApplicationIcon", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..14ab4ad --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\Application.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..8f5d4c5 --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WorldClockStatusWindow.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string WindowSettings { + get { + return ((string)(this["WindowSettings"])); + } + set { + this["WindowSettings"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool AutoStart { + get { + return ((bool)(this["AutoStart"])); + } + set { + this["AutoStart"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("ddd hh:mm:ss tt")] + public string TimeFormat { + get { + return ((string)(this["TimeFormat"])); + } + set { + this["TimeFormat"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("[]")] + public string TimeZones { + get { + return ((string)(this["TimeZones"])); + } + set { + this["TimeZones"] = value; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..dd70d6c --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,18 @@ + + + + + + + + + True + + + ddd hh:mm:ss tt + + + [] + + + \ No newline at end of file diff --git a/Resources/Application.ico b/Resources/Application.ico new file mode 100644 index 0000000000000000000000000000000000000000..498c8b8f846377d1c626b65bdcc4c7610244d986 GIT binary patch literal 10134 zcmeHNzi%T&6n^VCSv#Da=!%rY5{kGADBR~17wImDD&>Wf&^4S)LrfJ*poDIf@=zoS zuDFV;@2V7B9sUCvKy)!A7jLAKhVPr*XOGwGtbgo@1N`FInK$pp_vX!bJv$o_PnM)s zTSZ-zKMEqBiOA||#NY8m?kx!90(nWEmPEcRQXcUS7e(H!sJtdm(SLYb#B$$S_$oI|(>U^5pImM>0{Vx3J=pK=UF_6j z|3RZ=x@%$V5Bl|ku)AkWPrnqJux*01Sl=|ZgXR~Pn|m71+U;-G*8bX!@Zo=BgTbml zM8bIC-{QkRIzn_cG=3(aFZaVvD{OpIugCE<&8rVh{i4y>R(*`sT-NIcaXcXtaO9Va z%_sabIh|$@a=08Xlk@8RNGvuxiyIq}HS)c0bM41s&PPPn8W$VgcvEZFfVF-tvJU(e zgp_Alhrdmf0~7@8nNSwY>we6J>wFcZhNA1djdnVbt1Kd zxtc<_87ZYm(bZF^R()@X{A#stJ|soQpuCcx$>n_vx*E3kyju&Nw{XkzAWW4nS4ySI z@@RRHj*F0w@V`jG;z)U!;!34F(%vgnDg_KP3QuiWE{-V#-mFBQCk@9<@+yZYr4)qDDuae25d zGX}-8%Gfgu@)6sMw`iq^Unw=|`92TUEJm9T(sRnp0G@U4qx^zmaw_NW)6N8j0`xx4 z2{SGB%ou=e$BnZ9gL8sh3Vp?6I?u|1jy*4I^`m|##mCu)nWg+!@O2znbuw3~KWqNg z56+_u&aHaul5O^>ocL+&yzp@@X4eDuqlSfe>`TLRW6292=XFEtk$o<{I|tgI7e3Ak zhw#~_I4*YHTI0%V{Pc&j(;g1nilO+*=RJP)%Nl311M6O8E~eYg zbNq^xR%_n1R-IY#)!(G`96$OE&m;euOLq?3K5eJf|0F)n4|M;Lc>t<$>KNRyX0_GE ztzB&R{{BtwKU`e4C&gxLd5wP>?7Z-&#ZJRd<}{0+1v|#K`)~Tm!b-|##g6g$?9=XPha%8iE@Bq_ _timeZoneEntries; + + internal WindowSource() + { + _floatingStatusWindow = new FloatingStatusWindow(this); + _floatingStatusWindow.SetText("Loading..."); + + _dispatcher = Dispatcher.CurrentDispatcher; + + Load(); + + _timer = new Timer(1000); + _timer.Elapsed += HandleTimerElapsed; + _timer.Enabled = true; + } + + private void Load() + { + _timeZoneEntries = JsonSerializer.Deserialize>(Properties.Settings.Default.TimeZones); + + if (_timeZoneEntries.Any()) + return; + + _timeZoneEntries.Add(new TimeZoneEntry { Label = "UTC", TimeZoneId = "UTC" }); + _timeZoneEntries.Add(new TimeZoneEntry { Label = "IST", TimeZoneId = "India Standard Time" }); + _timeZoneEntries.Add(new TimeZoneEntry { Label = "CET", TimeZoneId = "Central Europe Standard Time" }); + _timeZoneEntries.Add(new TimeZoneEntry { Label = "Local", TimeZoneId = string.Empty }); + + Save(); + } + + private void Save() + { + Properties.Settings.Default.TimeZones = JsonSerializer.Serialize(_timeZoneEntries); + Properties.Settings.Default.Save(); + } + + private void HandleTimerElapsed(object sender, ElapsedEventArgs e) + { + var text = new StringBuilder(); + + var now = DateTimeOffset.Now; + + var labelLength = _timeZoneEntries.Max(x => x.Label.Length); + + foreach (var timeZoneEntry in _timeZoneEntries) + { + var timeZone = timeZoneEntry.TimeZoneId == string.Empty ? TimeZoneInfo.Local : TimeZoneInfo.FindSystemTimeZoneById(timeZoneEntry.TimeZoneId); + + if (text.Length > 0) + text.AppendLine(); + + text.Append($"{timeZoneEntry.Label.PadLeft(labelLength)}: {TimeZoneInfo.ConvertTime(now, timeZone).ToString(Properties.Settings.Default.TimeFormat)}"); + } + + _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(text.ToString())); + } + + public void Dispose() + { + _timer.Enabled = false; + _timer.Dispose(); + + _floatingStatusWindow.Save(); + _floatingStatusWindow.Dispose(); + } + + public Guid Id => Guid.Parse("29DF6CFD-6783-406F-AE12-4723EB7741EA"); + + public string Name => "World Clock"; + + public System.Drawing.Icon Icon => Properties.Resources.ApplicationIcon; + + public bool HasSettingsMenu => true; + + public bool HasAboutMenu => false; + + public void ShowAbout() + { + _floatingStatusWindow.SetText(Assembly.GetEntryAssembly()!.GetName().Version!.ToString()); + } + + public void ShowSettings() + { + + Save(); + } + + public bool HasRefreshMenu => false; + + public void Refresh() + { + } + + public string WindowSettings + { + get => Properties.Settings.Default.WindowSettings; + set + { + Properties.Settings.Default.WindowSettings = value; + Properties.Settings.Default.Save(); + } + } +} \ No newline at end of file diff --git a/WorldClockStatusWindow.csproj b/WorldClockStatusWindow.csproj new file mode 100644 index 0000000..12132b0 --- /dev/null +++ b/WorldClockStatusWindow.csproj @@ -0,0 +1,31 @@ + + + net8.0-windows7.0 + WinExe + false + true + true + + + + + + + + + + + + + True + True + Settings.settings + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + \ No newline at end of file diff --git a/WorldClockStatusWindow.sln b/WorldClockStatusWindow.sln new file mode 100644 index 0000000..f6d8e6e --- /dev/null +++ b/WorldClockStatusWindow.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35312.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorldClockStatusWindow", "WorldClockStatusWindow.csproj", "{B4A9FB98-C873-487F-AC4B-9B4356491DE3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4A9FB98-C873-487F-AC4B-9B4356491DE3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0F74AA40-5495-496E-8131-A5FEFFFA9097} + EndGlobalSection +EndGlobal