diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs
index a3ad20f77..b9ac6afb3 100644
--- a/Flow.Launcher/Helper/HotKeyMapper.cs
+++ b/Flow.Launcher/Helper/HotKeyMapper.cs
@@ -17,7 +17,7 @@ namespace Flow.Launcher.Helper
internal static void Initialize(MainViewModel mainVM)
{
mainViewModel = mainVM;
- settings = mainViewModel._settings;
+ settings = mainViewModel.Settings;
SetHotkey(settings.Hotkey, OnToggleHotkey);
LoadCustomPluginHotkey();
diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml
index 68a4c2c23..3b57e7a70 100644
--- a/Flow.Launcher/MainWindow.xaml
+++ b/Flow.Launcher/MainWindow.xaml
@@ -1,5 +1,4 @@
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+
-
-
+
-
-
-
-
+
+
+
-
-
+
+
-
-
-
+
+
+
-
+
\ No newline at end of file
diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs
index 3646f1c87..1ae7f43bd 100644
--- a/Flow.Launcher/MainWindow.xaml.cs
+++ b/Flow.Launcher/MainWindow.xaml.cs
@@ -48,17 +48,7 @@ namespace Flow.Launcher
DataContext = mainVM;
_viewModel = mainVM;
_settings = settings;
-
-
- var timer = new Timer
- {
- Interval = 1000,
- };
- timer.Tick += (s, evt) =>
- {
- ClockDisplay();
- };
- timer.Start();
+
InitializeComponent();
InitializePosition();
animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
@@ -69,28 +59,7 @@ namespace Flow.Launcher
InitializeComponent();
}
- public void ClockDisplay()
- {
- if (_settings.UseClock == true)
- {
- ClockBox.Visibility = Visibility.Visible;
- ClockBox.Text = System.DateTime.Now.ToString(_settings.TimeFormat);
- }
- else if (_settings.UseClock == false)
- {
- ClockBox.Visibility = Visibility.Collapsed;
- }
- if (_settings.UseDate == true)
- {
- DateBox.Visibility = Visibility.Visible;
- DateBox.Text = System.DateTime.Now.ToString(_settings.DateFormat);
- }
- else if (_settings.UseDate == false)
- {
- DateBox.Visibility = Visibility.Collapsed;
- }
-
- }
+
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
{
if (QueryTextBox.SelectionLength == 0)
@@ -213,12 +182,6 @@ namespace Flow.Launcher
case nameof(Settings.Hotkey):
UpdateNotifyIconText();
break;
- case nameof(Settings.UseClock):
- ClockDisplay();
- break;
- case nameof(Settings.UseDate):
- ClockDisplay();
- break;
}
};
}
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index e62899261..aba9bc010 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -37,7 +37,6 @@ namespace Flow.Launcher.ViewModel
private readonly FlowLauncherJsonStorage _historyItemsStorage;
private readonly FlowLauncherJsonStorage _userSelectedRecordStorage;
private readonly FlowLauncherJsonStorage _topMostRecordStorage;
- internal readonly Settings _settings;
private readonly History _history;
private readonly UserSelectedRecord _userSelectedRecord;
private readonly TopMostRecord _topMostRecord;
@@ -60,8 +59,8 @@ namespace Flow.Launcher.ViewModel
_queryText = "";
_lastQuery = new Query();
- _settings = settings;
- _settings.PropertyChanged += (_, args) =>
+ Settings = settings;
+ Settings.PropertyChanged += (_, args) =>
{
if (args.PropertyName == nameof(Settings.WindowSize))
{
@@ -76,14 +75,15 @@ namespace Flow.Launcher.ViewModel
_userSelectedRecord = _userSelectedRecordStorage.Load();
_topMostRecord = _topMostRecordStorage.Load();
- ContextMenu = new ResultsViewModel(_settings);
- Results = new ResultsViewModel(_settings);
- History = new ResultsViewModel(_settings);
+ ContextMenu = new ResultsViewModel(Settings);
+ Results = new ResultsViewModel(Settings);
+ History = new ResultsViewModel(Settings);
_selectedResults = Results;
InitializeKeyCommands();
RegisterViewUpdate();
RegisterResultsUpdatedEvent();
+ RegisterClockAndDateUpdateAsync();
SetOpenResultModifiers();
}
@@ -307,7 +307,7 @@ namespace Flow.Launcher.ViewModel
Notification.Show(
InternationalizationManager.Instance.GetTranslation("success"),
InternationalizationManager.Instance.GetTranslation("completedSuccessfully")
- );
+ );
}), TaskScheduler.Default)
.ConfigureAwait(false);
});
@@ -317,10 +317,26 @@ namespace Flow.Launcher.ViewModel
#region ViewModel Properties
+ public Settings Settings { get; }
+ public object ClockText { get; private set; }
+ public string DateText { get; private set; }
+
+ private async Task RegisterClockAndDateUpdateAsync()
+ {
+ var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
+ // ReSharper disable once MethodSupportsCancellation
+ while (await timer.WaitForNextTickAsync().ConfigureAwait(false))
+ {
+ if (Settings.UseClock)
+ ClockText = DateTime.Now.ToString(Settings.TimeFormat);
+ if (Settings.UseDate)
+ DateText = DateTime.Now.ToString(Settings.DateFormat);
+ }
+ }
public ResultsViewModel Results { get; private set; }
-
+
public ResultsViewModel ContextMenu { get; private set; }
-
+
public ResultsViewModel History { get; private set; }
public bool GameModeStatus { get; set; }
@@ -411,7 +427,7 @@ namespace Flow.Launcher.ViewModel
public Visibility SearchIconVisibility { get; set; }
- public double MainWindowWidth => _settings.WindowSize;
+ public double MainWindowWidth => Settings.WindowSize;
public string PluginIconPath { get; set; } = null;
@@ -592,7 +608,7 @@ namespace Flow.Launcher.ViewModel
PluginIconPath = null;
SearchIconVisibility = Visibility.Visible;
}
-
+
if (query.ActionKeyword == Plugin.Query.GlobalPluginWildcardSign)
{
@@ -759,7 +775,7 @@ namespace Flow.Launcher.ViewModel
private void SetOpenResultModifiers()
{
- OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers;
+ OpenResultCommandModifiers = Settings.OpenResultModifiers ?? DefaultOpenResultModifiers;
}
public void ToggleFlowLauncher()
@@ -788,24 +804,24 @@ namespace Flow.Launcher.ViewModel
// Trick for no delay
MainWindowOpacity = 0;
- switch (_settings.LastQueryMode)
+ switch (Settings.LastQueryMode)
{
case LastQueryMode.Empty:
ChangeQueryText(string.Empty);
await Task.Delay(100); //Time for change to opacity
break;
case LastQueryMode.Preserved:
- if (_settings.UseAnimation)
+ if (Settings.UseAnimation)
await Task.Delay(100);
LastQuerySelected = true;
break;
case LastQueryMode.Selected:
- if (_settings.UseAnimation)
+ if (Settings.UseAnimation)
await Task.Delay(100);
LastQuerySelected = false;
break;
default:
- throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>");
+ throw new ArgumentException($"wrong LastQueryMode: <{Settings.LastQueryMode}>");
}
MainWindowVisibilityStatus = false;
@@ -820,7 +836,7 @@ namespace Flow.Launcher.ViewModel
///
public bool ShouldIgnoreHotkeys()
{
- return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
+ return Settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
}
@@ -903,18 +919,18 @@ namespace Flow.Launcher.ViewModel
Clipboard.SetFileDropList(paths);
App.API.ShowMsg(
- App.API.GetTranslation("copy")
- +" "
- + (isFile? App.API.GetTranslation("fileTitle") : App.API.GetTranslation("folderTitle")),
+ App.API.GetTranslation("copy")
+ + " "
+ + (isFile ? App.API.GetTranslation("fileTitle") : App.API.GetTranslation("folderTitle")),
App.API.GetTranslation("completedSuccessfully"));
}
else
{
Clipboard.SetDataObject(copyText.ToString());
App.API.ShowMsg(
- App.API.GetTranslation("copy")
- + " "
- + App.API.GetTranslation("textTitle"),
+ App.API.GetTranslation("copy")
+ + " "
+ + App.API.GetTranslation("textTitle"),
App.API.GetTranslation("completedSuccessfully"));
}
}