Skip to content

Commit a98a033

Browse files
committed
Improve code quality
1 parent 2cd1683 commit a98a033

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,13 @@ public static bool WM_EXITSIZEMOVE(int msg)
313313

314314
#region Window Handle
315315

316-
internal static HWND GetWindowHandle(Window window)
316+
internal static HWND GetWindowHandle(Window window, bool ensure = false)
317317
{
318318
var windowHelper = new WindowInteropHelper(window);
319-
windowHelper.EnsureHandle();
319+
if (ensure)
320+
{
321+
windowHelper.EnsureHandle();
322+
}
320323
return new(windowHelper.Handle);
321324
}
322325

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Windows.Input;
66
using System.Windows.Media.Animation;
77
using System.Windows.Controls;
8-
using System.Windows.Forms;
98
using Flow.Launcher.Core.Plugin;
109
using Flow.Launcher.Core.Resource;
1110
using Flow.Launcher.Infrastructure.UserSettings;
@@ -63,13 +62,6 @@ public MainWindow(Settings settings, MainViewModel mainVM)
6362

6463
InitSoundEffects();
6564
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
66-
67-
Loaded += (_, _) =>
68-
{
69-
var handle = new WindowInteropHelper(this).Handle;
70-
var win = HwndSource.FromHwnd(handle);
71-
win.AddHook(WndProc);
72-
};
7365
}
7466

7567
private int _initialWidth;
@@ -143,13 +135,13 @@ private void OnCopy(object sender, ExecutedRoutedEventArgs e)
143135

144136
private void OnPaste(object sender, DataObjectPastingEventArgs e)
145137
{
146-
var isText = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.UnicodeText, true);
138+
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
147139
if (isText)
148140
{
149-
var text = e.SourceDataObject.GetData(System.Windows.DataFormats.UnicodeText) as string;
141+
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
150142
text = text.Replace(Environment.NewLine, " ");
151143
DataObject data = new DataObject();
152-
data.SetData(System.Windows.DataFormats.UnicodeText, text);
144+
data.SetData(DataFormats.UnicodeText, text);
153145
e.DataObject = data;
154146
}
155147
}
@@ -166,6 +158,9 @@ private async void OnClosing(object sender, CancelEventArgs e)
166158

167159
private void OnSourceInitialized(object sender, EventArgs e)
168160
{
161+
var handle = Win32Helper.GetWindowHandle(this, true);
162+
var win = HwndSource.FromHwnd(handle);
163+
win.AddHook(WndProc);
169164
Win32Helper.HideFromAltTab(this);
170165
Win32Helper.DisableControlBox(this);
171166
}
@@ -392,10 +387,10 @@ private void InitializeNotifyIcon()
392387
{
393388
switch (e.Button)
394389
{
395-
case MouseButtons.Left:
390+
case System.Windows.Forms.MouseButtons.Left:
396391
_viewModel.ToggleFlowLauncher();
397392
break;
398-
case MouseButtons.Right:
393+
case System.Windows.Forms.MouseButtons.Right:
399394

400395
contextMenu.IsOpen = true;
401396
// Get context menu handle and bring it to the foreground
@@ -713,7 +708,7 @@ private void UpdateClockPanelVisibility()
713708
{
714709
_isClockPanelAnimating = true;
715710

716-
System.Windows.Application.Current.Dispatcher.Invoke(() =>
711+
Application.Current.Dispatcher.Invoke(() =>
717712
{
718713
ClockPanel.Visibility = Visibility.Visible; // ✅ Visibility를 먼저 Visible로 설정
719714

@@ -969,7 +964,7 @@ private void OnKeyUp(object sender, KeyEventArgs e)
969964
}
970965
}
971966

972-
private void MainPreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
967+
private void MainPreviewMouseMove(object sender, MouseEventArgs e)
973968
{
974969
if (isArrowKeyPressed)
975970
{
@@ -1005,7 +1000,7 @@ private void QueryTextBox_KeyUp(object sender, KeyEventArgs e)
10051000
{
10061001
if (_viewModel.QueryText != QueryTextBox.Text)
10071002
{
1008-
BindingExpression be = QueryTextBox.GetBindingExpression(System.Windows.Controls.TextBox.TextProperty);
1003+
BindingExpression be = QueryTextBox.GetBindingExpression(TextBox.TextProperty);
10091004
be.UpdateSource();
10101005
}
10111006
}

0 commit comments

Comments
 (0)