Skip to content

Commit 944393c

Browse files
committed
Improve code quality
1 parent 9cb31c8 commit 944393c

File tree

2 files changed

+44
-58
lines changed

2 files changed

+44
-58
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,13 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs
388388

389389
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
390390
{
391-
if (Win32Helper.WM_ENTERSIZEMOVE((uint)msg))
391+
if (msg == Win32Helper.WM_ENTERSIZEMOVE)
392392
{
393393
_initialWidth = (int)Width;
394394
_initialHeight = (int)Height;
395395
handled = true;
396396
}
397-
else if (Win32Helper.WM_EXITSIZEMOVE((uint)msg))
397+
else if (msg == Win32Helper.WM_EXITSIZEMOVE)
398398
{
399399
if (_initialHeight != (int)Height)
400400
{

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ private void RegisterResultsUpdatedEvent()
240240
}
241241
}
242242

243+
private async Task RegisterClockAndDateUpdateAsync()
244+
{
245+
var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
246+
// ReSharper disable once MethodSupportsCancellation
247+
while (await timer.WaitForNextTickAsync().ConfigureAwait(false))
248+
{
249+
if (Settings.UseClock)
250+
ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture);
251+
if (Settings.UseDate)
252+
DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
253+
}
254+
}
255+
243256
[RelayCommand]
244257
private async Task ReloadPluginDataAsync()
245258
{
@@ -284,7 +297,7 @@ public void ReverseHistory()
284297
{
285298
if (_history.Items.Count > 0)
286299
{
287-
ChangeQueryText(_history.Items[_history.Items.Count - lastHistoryIndex].Query.ToString());
300+
ChangeQueryText(_history.Items[^lastHistoryIndex].Query.ToString());
288301
if (lastHistoryIndex < _history.Items.Count)
289302
{
290303
lastHistoryIndex++;
@@ -297,7 +310,7 @@ public void ForwardHistory()
297310
{
298311
if (_history.Items.Count > 0)
299312
{
300-
ChangeQueryText(_history.Items[_history.Items.Count - lastHistoryIndex].Query.ToString());
313+
ChangeQueryText(_history.Items[^lastHistoryIndex].Query.ToString());
301314
if (lastHistoryIndex > 1)
302315
{
303316
lastHistoryIndex--;
@@ -348,12 +361,12 @@ private void AutocompleteQuery()
348361
}
349362
else if (!string.IsNullOrEmpty(SelectedResults.SelectedItem?.QuerySuggestionText))
350363
{
351-
var defaultSuggestion = SelectedResults.SelectedItem.QuerySuggestionText;
352-
// check if result.actionkeywordassigned is empty
353-
if (!string.IsNullOrEmpty(result.ActionKeywordAssigned))
354-
{
355-
autoCompleteText = $"{result.ActionKeywordAssigned} {defaultSuggestion}";
356-
}
364+
//var defaultSuggestion = SelectedResults.SelectedItem.QuerySuggestionText;
365+
//// check if result.actionkeywordassigned is empty
366+
//if (!string.IsNullOrEmpty(result.ActionKeywordAssigned))
367+
//{
368+
// autoCompleteText = $"{result.ActionKeywordAssigned} {defaultSuggestion}";
369+
//}
357370

358371
autoCompleteText = SelectedResults.SelectedItem.QuerySuggestionText;
359372
}
@@ -532,19 +545,6 @@ public void CopyAlternative()
532545
public string ClockText { get; private set; }
533546
public string DateText { get; private set; }
534547

535-
private async Task RegisterClockAndDateUpdateAsync()
536-
{
537-
var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
538-
// ReSharper disable once MethodSupportsCancellation
539-
while (await timer.WaitForNextTickAsync().ConfigureAwait(false))
540-
{
541-
if (Settings.UseClock)
542-
ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture);
543-
if (Settings.UseDate)
544-
DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
545-
}
546-
}
547-
548548
public ResultsViewModel Results { get; private set; }
549549

550550
public ResultsViewModel ContextMenu { get; private set; }
@@ -751,7 +751,7 @@ public double ResultSubItemFontSize
751751

752752
public string OpenResultCommandModifiers => Settings.OpenResultModifiers;
753753

754-
public string VerifyOrSetDefaultHotkey(string hotkey, string defaultHotkey)
754+
private static string VerifyOrSetDefaultHotkey(string hotkey, string defaultHotkey)
755755
{
756756
try
757757
{
@@ -780,8 +780,6 @@ public string VerifyOrSetDefaultHotkey(string hotkey, string defaultHotkey)
780780
public string CycleHistoryUpHotkey => VerifyOrSetDefaultHotkey(Settings.CycleHistoryUpHotkey, "Alt+Up");
781781
public string CycleHistoryDownHotkey => VerifyOrSetDefaultHotkey(Settings.CycleHistoryDownHotkey, "Alt+Down");
782782

783-
public string Image => Constant.QueryTextBoxIconImagePath;
784-
785783
public bool StartWithEnglishMode => Settings.AlwaysStartEn;
786784

787785
#endregion
@@ -866,18 +864,6 @@ private void TogglePreview()
866864
}
867865
}
868866

869-
private void ToggleInternalPreview()
870-
{
871-
if (!InternalPreviewVisible)
872-
{
873-
ShowInternalPreview();
874-
}
875-
else
876-
{
877-
HideInternalPreview();
878-
}
879-
}
880-
881867
private void OpenExternalPreview(string path, bool sendFailToast = true)
882868
{
883869
_ = PluginManager.OpenExternalPreviewAsync(path, sendFailToast).ConfigureAwait(false);
@@ -1368,27 +1354,27 @@ public void ToggleFlowLauncher()
13681354
}
13691355

13701356
public void Show()
1371-
{
1372-
Application.Current.Dispatcher.Invoke(() =>
1373-
{
1374-
if (Application.Current.MainWindow is MainWindow mainWindow)
13751357
{
1376-
// 📌 Remove DWM Cloak (Make the window visible normally)
1377-
Win32Helper.DWMSetCloakForWindow(mainWindow, false);
1358+
Application.Current.Dispatcher.Invoke(() =>
1359+
{
1360+
if (Application.Current.MainWindow is MainWindow mainWindow)
1361+
{
1362+
// 📌 Remove DWM Cloak (Make the window visible normally)
1363+
Win32Helper.DWMSetCloakForWindow(mainWindow, false);
13781364

1379-
// 📌 Restore UI elements
1380-
mainWindow.ClockPanel.Visibility = Visibility.Visible;
1381-
//mainWindow.SearchIcon.Visibility = Visibility.Visible;
1382-
SearchIconVisibility = Visibility.Visible;
1383-
}
1365+
// 📌 Restore UI elements
1366+
mainWindow.ClockPanel.Visibility = Visibility.Visible;
1367+
//mainWindow.SearchIcon.Visibility = Visibility.Visible;
1368+
SearchIconVisibility = Visibility.Visible;
1369+
}
13841370

1385-
// Update WPF properties
1386-
MainWindowVisibility = Visibility.Visible;
1387-
MainWindowOpacity = 1;
1388-
MainWindowVisibilityStatus = true;
1389-
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
1390-
});
1391-
}
1371+
// Update WPF properties
1372+
MainWindowVisibility = Visibility.Visible;
1373+
MainWindowOpacity = 1;
1374+
MainWindowVisibilityStatus = true;
1375+
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
1376+
});
1377+
}
13921378

13931379
#pragma warning disable VSTHRD100 // Avoid async void methods
13941380

@@ -1456,15 +1442,15 @@ public async void Hide()
14561442
Win32Helper.DWMSetCloakForWindow(mainWindow, true);
14571443
}
14581444

1459-
await Task.Delay(50);
1445+
await Task.Delay(50);
1446+
14601447
// Update WPF properties
14611448
//MainWindowOpacity = 0;
14621449
MainWindowVisibilityStatus = false;
14631450
MainWindowVisibility = Visibility.Collapsed;
14641451
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = false });
14651452
}
14661453

1467-
14681454
#pragma warning restore VSTHRD100 // Avoid async void methods
14691455

14701456
/// <summary>

0 commit comments

Comments
 (0)