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 0000000..498c8b8 Binary files /dev/null and b/Resources/Application.ico differ diff --git a/TimeZoneEntry.cs b/TimeZoneEntry.cs new file mode 100644 index 0000000..1402625 --- /dev/null +++ b/TimeZoneEntry.cs @@ -0,0 +1,7 @@ +namespace WorldClockStatusWindow; + +public class TimeZoneEntry +{ + public string Label { get; set; } + public string TimeZoneId { get; set; } +} \ No newline at end of file diff --git a/WindowSource.cs b/WindowSource.cs new file mode 100644 index 0000000..a7490da --- /dev/null +++ b/WindowSource.cs @@ -0,0 +1,122 @@ +using ChrisKaczor.Wpf.Windows.FloatingStatusWindow; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.Json; +using System.Timers; +using System.Windows.Threading; + +namespace WorldClockStatusWindow; + +internal class WindowSource : IWindowSource, IDisposable +{ + private readonly FloatingStatusWindow _floatingStatusWindow; + private readonly Timer _timer; + private readonly Dispatcher _dispatcher; + + private List _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