Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(bar): convert clock time/date to string using formatting from user config

Lars Bergerca1f41ab9120
diff --git a/GlazeWM.Bar/Components/ClockComponentViewModel.cs b/GlazeWM.Bar/Components/ClockComponentViewModel.cs
index 2aa20341..4fdfdfd3 100644
--- a/GlazeWM.Bar/Components/ClockComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/ClockComponentViewModel.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.Reactive.Linq;
using GlazeWM.Domain.UserConfigs;
@@ -6,13 +7,17 @@ namespace GlazeWM.Bar.Components
{
public class ClockComponentViewModel : ComponentViewModel
{
- private new readonly ClockComponentConfig _config;
+ private ClockComponentConfig _config => _baseConfig as ClockComponentConfig;
+ private string _timeFormatting => _config.TimeFormatting;
- public string FormattedTime =>
- $"{DateTime.Now.ToShortTimeString()} {DateTime.Now.ToShortDateString()}";
+ /// <summary>
+ /// Format the current time with the user's formatting config.
+ /// </summary>
+ public string FormattedTime => DateTime.Now.ToString(_timeFormatting, CultureInfo.InvariantCulture);
public ClockComponentViewModel(BarViewModel parentViewModel, ClockComponentConfig config) : base(parentViewModel, config)
{
+ // Update the displayed time every second.
var updateInterval = TimeSpan.FromSeconds(1);
Observable.Interval(updateInterval)
diff --git a/GlazeWM.Bar/Components/ComponentViewModel.cs b/GlazeWM.Bar/Components/ComponentViewModel.cs
index d10a547a..50e29c96 100644
--- a/GlazeWM.Bar/Components/ComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/ComponentViewModel.cs
@@ -6,7 +6,7 @@ namespace GlazeWM.Bar.Components
public class ComponentViewModel : ViewModelBase
{
protected readonly BarViewModel _parentViewModel;
- protected readonly BarComponentConfig _config;
+ protected readonly BarComponentConfig _baseConfig;
public ComponentViewModel(BarViewModel parentViewModel, BarComponentConfig config)
{
diff --git a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
index 80f282d1..2025a5df 100644
--- a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs
@@ -16,7 +16,7 @@ namespace GlazeWM.Bar.Components
{
public class WorkspacesComponentViewModel : ComponentViewModel
{
- private new readonly WorkspacesComponentConfig _config;
+ private WorkspacesComponentConfig _config => _baseConfig as WorkspacesComponentConfig;
private Bus _bus = ServiceLocator.Provider.GetRequiredService<Bus>();
private Dispatcher _dispatcher => _parentViewModel.Dispatcher;
private Monitor _monitor => _parentViewModel.Monitor;