Skip to content

Commit 0e6fbf2

Browse files
Avoid new CultureInfo every second
1 parent 9051e3e commit 0e6fbf2

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ public MainViewModel(Settings settings)
6767
{
6868
if (args.PropertyName == nameof(Settings.WindowSize))
6969
{
70-
OnPropertyChanged(nameof(MainWindowWidth));
70+
}
71+
switch (args.PropertyName) {
72+
case nameof(Settings.WindowSize):
73+
OnPropertyChanged(nameof(MainWindowWidth));
74+
break;
75+
case nameof(Settings.Language):
76+
Culture = new CultureInfo(Settings.Language);
77+
break;
7178
}
7279
};
7380

@@ -99,6 +106,8 @@ public MainViewModel(Settings settings)
99106
RegisterClockAndDateUpdateAsync();
100107

101108
SetOpenResultModifiers();
109+
110+
Culture = new CultureInfo(Settings.Language);
102111
}
103112

104113
private void RegisterViewUpdate()
@@ -334,20 +343,21 @@ private void Esc()
334343
public Settings Settings { get; }
335344
public string ClockText { get; private set; }
336345
public string DateText { get; private set; }
346+
public CultureInfo Culture { get; set; }
337347

338-
public CultureInfo cultureInfo => new CultureInfo(Settings.Language);
339348
private async Task RegisterClockAndDateUpdateAsync()
340349
{
341350
var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
342351
// ReSharper disable once MethodSupportsCancellation
343352
while (await timer.WaitForNextTickAsync().ConfigureAwait(false))
344353
{
345354
if (Settings.UseClock)
346-
ClockText = DateTime.Now.ToString(Settings.TimeFormat, cultureInfo);
355+
ClockText = DateTime.Now.ToString(Settings.TimeFormat, Culture);
347356
if (Settings.UseDate)
348-
DateText = DateTime.Now.ToString(Settings.DateFormat, cultureInfo);
357+
DateText = DateTime.Now.ToString(Settings.DateFormat, Culture);
349358
}
350359
}
360+
351361
public ResultsViewModel Results { get; private set; }
352362

353363
public ResultsViewModel ContextMenu { get; private set; }

0 commit comments

Comments
 (0)