diff --git a/src/modules/launcher/PowerLauncher/ActionKeywords.xaml b/src/modules/launcher/PowerLauncher/ActionKeywords.xaml
index ffe1b5400b..4ef88c08d8 100644
--- a/src/modules/launcher/PowerLauncher/ActionKeywords.xaml
+++ b/src/modules/launcher/PowerLauncher/ActionKeywords.xaml
@@ -37,7 +37,7 @@
-
diff --git a/src/modules/launcher/PowerLauncher/ActionKeywords.xaml.cs b/src/modules/launcher/PowerLauncher/ActionKeywords.xaml.cs
index ac9fdbd0b3..a3954876e7 100644
--- a/src/modules/launcher/PowerLauncher/ActionKeywords.xaml.cs
+++ b/src/modules/launcher/PowerLauncher/ActionKeywords.xaml.cs
@@ -40,7 +40,7 @@ namespace Wox
Close();
}
- private void btnDone_OnClick(object sender, RoutedEventArgs _)
+ private void BtnDone_OnClick(object sender, RoutedEventArgs e)
{
var oldActionKeyword = _plugin.Metadata.ActionKeywords[0];
var newActionKeyword = tbAction.Text.Trim();
diff --git a/src/modules/launcher/PowerLauncher/Helper/DataWebRequestFactory.cs b/src/modules/launcher/PowerLauncher/Helper/DataWebRequestFactory.cs
index b96598e4cb..a9c3e92e9e 100644
--- a/src/modules/launcher/PowerLauncher/Helper/DataWebRequestFactory.cs
+++ b/src/modules/launcher/PowerLauncher/Helper/DataWebRequestFactory.cs
@@ -12,23 +12,23 @@ namespace PowerLauncher.Helper
{
private class DataWebRequest : WebRequest
{
- private readonly Uri m_uri;
+ private readonly Uri _uri;
public DataWebRequest(Uri uri)
{
- m_uri = uri;
+ _uri = uri;
}
public override WebResponse GetResponse()
{
- return new DataWebResponse(m_uri);
+ return new DataWebResponse(_uri);
}
}
private class DataWebResponse : WebResponse
{
- private readonly string m_contentType;
- private readonly byte[] m_data;
+ private readonly string _contentType;
+ private readonly byte[] _data;
public DataWebResponse(Uri uri)
{
@@ -36,16 +36,16 @@ namespace PowerLauncher.Helper
int commaIndex = uriString.IndexOf(',', StringComparison.InvariantCultureIgnoreCase);
var headers = uriString.Substring(0, commaIndex).Split(';');
- m_contentType = headers[0];
+ _contentType = headers[0];
string dataString = uriString.Substring(commaIndex + 1);
- m_data = Convert.FromBase64String(dataString);
+ _data = Convert.FromBase64String(dataString);
}
public override string ContentType
{
get
{
- return m_contentType;
+ return _contentType;
}
set
@@ -58,7 +58,7 @@ namespace PowerLauncher.Helper
{
get
{
- return m_data.Length;
+ return _data.Length;
}
set
@@ -69,7 +69,7 @@ namespace PowerLauncher.Helper
public override Stream GetResponseStream()
{
- return new MemoryStream(m_data);
+ return new MemoryStream(_data);
}
}
diff --git a/src/modules/launcher/PowerLauncher/Helper/NativeMethods.cs b/src/modules/launcher/PowerLauncher/Helper/NativeMethods.cs
new file mode 100644
index 0000000000..44fe5d35d9
--- /dev/null
+++ b/src/modules/launcher/PowerLauncher/Helper/NativeMethods.cs
@@ -0,0 +1,199 @@
+// Copyright (c) Microsoft Corporation
+// The Microsoft Corporation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Text;
+using static PowerLauncher.Helper.WindowsInteropHelper;
+
+// http://blogs.microsoft.co.il/arik/2010/05/28/wpf-single-instance-application/
+// modified to allow single instance restart
+namespace PowerLauncher.Helper
+{
+ [SuppressUnmanagedCodeSecurity]
+ internal static class NativeMethods
+ {
+ ///
+ /// Delegate declaration that matches WndProc signatures.
+ ///
+ public delegate IntPtr MessageHandler(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled);
+
+ [DllImport("shell32.dll", EntryPoint = "CommandLineToArgvW", CharSet = CharSet.Unicode)]
+ private static extern IntPtr Shell32CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string cmdLine, out int numArgs);
+
+ [DllImport("kernel32.dll", EntryPoint = "LocalFree", SetLastError = true)]
+ internal static extern IntPtr Kernel32LocalFree(IntPtr hMem);
+
+ [DllImport("user32.dll")]
+ internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
+
+ [DllImport("user32.dll", SetLastError = true)]
+ internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
+
+ [DllImport("user32.dll")]
+ internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
+
+ [DllImport("user32.dll")]
+ internal static extern IntPtr GetForegroundWindow();
+
+ [DllImport("user32.dll")]
+ internal static extern IntPtr GetDesktopWindow();
+
+ [DllImport("user32.dll")]
+ internal static extern IntPtr GetShellWindow();
+
+ [DllImport("user32.dll", SetLastError = true)]
+ internal static extern int GetWindowRect(IntPtr hwnd, out RECT rc);
+
+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
+ internal static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
+
+ [DllImport("user32.DLL", CharSet = CharSet.Unicode)]
+ internal static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
+
+ public static string[] CommandLineToArgvW(string cmdLine)
+ {
+ IntPtr argv = IntPtr.Zero;
+ try
+ {
+ argv = Shell32CommandLineToArgvW(cmdLine, out int numArgs);
+ if (argv == IntPtr.Zero)
+ {
+ throw new Win32Exception();
+ }
+
+ var result = new string[numArgs];
+
+ for (int i = 0; i < numArgs; i++)
+ {
+ IntPtr currArg = Marshal.ReadIntPtr(argv, i * Marshal.SizeOf(typeof(IntPtr)));
+ result[i] = Marshal.PtrToStringUni(currArg);
+ }
+
+ return result;
+ }
+ finally
+ {
+ _ = Kernel32LocalFree(argv);
+
+ // Otherwise LocalFree failed.
+ // Assert.AreEqual(IntPtr.Zero, p);
+ }
+ }
+ }
+
+ internal enum WM
+ {
+ NULL = 0x0000,
+ CREATE = 0x0001,
+ DESTROY = 0x0002,
+ MOVE = 0x0003,
+ SIZE = 0x0005,
+ ACTIVATE = 0x0006,
+ SETFOCUS = 0x0007,
+ KILLFOCUS = 0x0008,
+ ENABLE = 0x000A,
+ SETREDRAW = 0x000B,
+ SETTEXT = 0x000C,
+ GETTEXT = 0x000D,
+ GETTEXTLENGTH = 0x000E,
+ PAINT = 0x000F,
+ CLOSE = 0x0010,
+ QUERYENDSESSION = 0x0011,
+ QUIT = 0x0012,
+ QUERYOPEN = 0x0013,
+ ERASEBKGND = 0x0014,
+ SYSCOLORCHANGE = 0x0015,
+ SHOWWINDOW = 0x0018,
+ ACTIVATEAPP = 0x001C,
+ SETCURSOR = 0x0020,
+ MOUSEACTIVATE = 0x0021,
+ CHILDACTIVATE = 0x0022,
+ QUEUESYNC = 0x0023,
+ GETMINMAXINFO = 0x0024,
+
+ WINDOWPOSCHANGING = 0x0046,
+ WINDOWPOSCHANGED = 0x0047,
+
+ CONTEXTMENU = 0x007B,
+ STYLECHANGING = 0x007C,
+ STYLECHANGED = 0x007D,
+ DISPLAYCHANGE = 0x007E,
+ GETICON = 0x007F,
+ SETICON = 0x0080,
+ NCCREATE = 0x0081,
+ NCDESTROY = 0x0082,
+ NCCALCSIZE = 0x0083,
+ NCHITTEST = 0x0084,
+ NCPAINT = 0x0085,
+ NCACTIVATE = 0x0086,
+ GETDLGCODE = 0x0087,
+ SYNCPAINT = 0x0088,
+ NCMOUSEMOVE = 0x00A0,
+ NCLBUTTONDOWN = 0x00A1,
+ NCLBUTTONUP = 0x00A2,
+ NCLBUTTONDBLCLK = 0x00A3,
+ NCRBUTTONDOWN = 0x00A4,
+ NCRBUTTONUP = 0x00A5,
+ NCRBUTTONDBLCLK = 0x00A6,
+ NCMBUTTONDOWN = 0x00A7,
+ NCMBUTTONUP = 0x00A8,
+ NCMBUTTONDBLCLK = 0x00A9,
+
+ SYSKEYDOWN = 0x0104,
+ SYSKEYUP = 0x0105,
+ SYSCHAR = 0x0106,
+ SYSDEADCHAR = 0x0107,
+ COMMAND = 0x0111,
+ SYSCOMMAND = 0x0112,
+
+ MOUSEMOVE = 0x0200,
+ LBUTTONDOWN = 0x0201,
+ LBUTTONUP = 0x0202,
+ LBUTTONDBLCLK = 0x0203,
+ RBUTTONDOWN = 0x0204,
+ RBUTTONUP = 0x0205,
+ RBUTTONDBLCLK = 0x0206,
+ MBUTTONDOWN = 0x0207,
+ MBUTTONUP = 0x0208,
+ MBUTTONDBLCLK = 0x0209,
+ MOUSEWHEEL = 0x020A,
+ XBUTTONDOWN = 0x020B,
+ XBUTTONUP = 0x020C,
+ XBUTTONDBLCLK = 0x020D,
+ MOUSEHWHEEL = 0x020E,
+
+ CAPTURECHANGED = 0x0215,
+
+ ENTERSIZEMOVE = 0x0231,
+ EXITSIZEMOVE = 0x0232,
+
+ IME_SETCONTEXT = 0x0281,
+ IME_NOTIFY = 0x0282,
+ IME_CONTROL = 0x0283,
+ IME_COMPOSITIONFULL = 0x0284,
+ IME_SELECT = 0x0285,
+ IME_CHAR = 0x0286,
+ IME_REQUEST = 0x0288,
+ IME_KEYDOWN = 0x0290,
+ IME_KEYUP = 0x0291,
+
+ NCMOUSELEAVE = 0x02A2,
+
+ DWMCOMPOSITIONCHANGED = 0x031E,
+ DWMNCRENDERINGCHANGED = 0x031F,
+ DWMCOLORIZATIONCOLORCHANGED = 0x0320,
+ DWMWINDOWMAXIMIZEDCHANGE = 0x0321,
+ DWMSENDICONICTHUMBNAIL = 0x0323,
+ DWMSENDICONICLIVEPREVIEWBITMAP = 0x0326,
+ USER = 0x0400,
+
+ // This is the hard-coded message value used by WinForms for Shell_NotifyIcon.
+ // It's relatively safe to reuse.
+ TRAYMOUSEMESSAGE = 0x800, // WM_USER + 1024
+ APP = 0x8000,
+ }
+}
diff --git a/src/modules/launcher/PowerLauncher/Helper/ResultCollection.cs b/src/modules/launcher/PowerLauncher/Helper/ResultCollection.cs
index 7f4ca7d0d1..b610ddae6b 100644
--- a/src/modules/launcher/PowerLauncher/Helper/ResultCollection.cs
+++ b/src/modules/launcher/PowerLauncher/Helper/ResultCollection.cs
@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Collections.Specialized;
-using System.Linq;
using PowerLauncher.ViewModel;
namespace PowerLauncher.Helper
diff --git a/src/modules/launcher/PowerLauncher/Helper/SingleInstance.cs b/src/modules/launcher/PowerLauncher/Helper/SingleInstance`1.cs
similarity index 52%
rename from src/modules/launcher/PowerLauncher/Helper/SingleInstance.cs
rename to src/modules/launcher/PowerLauncher/Helper/SingleInstance`1.cs
index 757834b07f..d5e94e680b 100644
--- a/src/modules/launcher/PowerLauncher/Helper/SingleInstance.cs
+++ b/src/modules/launcher/PowerLauncher/Helper/SingleInstance`1.cs
@@ -4,212 +4,17 @@
using System;
using System.Collections.Generic;
-using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
-using System.Runtime.InteropServices;
-using System.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
-using static PowerLauncher.Helper.WindowsInteropHelper;
// http://blogs.microsoft.co.il/arik/2010/05/28/wpf-single-instance-application/
// modified to allow single instance restart
namespace PowerLauncher.Helper
{
- internal enum WM
- {
- NULL = 0x0000,
- CREATE = 0x0001,
- DESTROY = 0x0002,
- MOVE = 0x0003,
- SIZE = 0x0005,
- ACTIVATE = 0x0006,
- SETFOCUS = 0x0007,
- KILLFOCUS = 0x0008,
- ENABLE = 0x000A,
- SETREDRAW = 0x000B,
- SETTEXT = 0x000C,
- GETTEXT = 0x000D,
- GETTEXTLENGTH = 0x000E,
- PAINT = 0x000F,
- CLOSE = 0x0010,
- QUERYENDSESSION = 0x0011,
- QUIT = 0x0012,
- QUERYOPEN = 0x0013,
- ERASEBKGND = 0x0014,
- SYSCOLORCHANGE = 0x0015,
- SHOWWINDOW = 0x0018,
- ACTIVATEAPP = 0x001C,
- SETCURSOR = 0x0020,
- MOUSEACTIVATE = 0x0021,
- CHILDACTIVATE = 0x0022,
- QUEUESYNC = 0x0023,
- GETMINMAXINFO = 0x0024,
-
- WINDOWPOSCHANGING = 0x0046,
- WINDOWPOSCHANGED = 0x0047,
-
- CONTEXTMENU = 0x007B,
- STYLECHANGING = 0x007C,
- STYLECHANGED = 0x007D,
- DISPLAYCHANGE = 0x007E,
- GETICON = 0x007F,
- SETICON = 0x0080,
- NCCREATE = 0x0081,
- NCDESTROY = 0x0082,
- NCCALCSIZE = 0x0083,
- NCHITTEST = 0x0084,
- NCPAINT = 0x0085,
- NCACTIVATE = 0x0086,
- GETDLGCODE = 0x0087,
- SYNCPAINT = 0x0088,
- NCMOUSEMOVE = 0x00A0,
- NCLBUTTONDOWN = 0x00A1,
- NCLBUTTONUP = 0x00A2,
- NCLBUTTONDBLCLK = 0x00A3,
- NCRBUTTONDOWN = 0x00A4,
- NCRBUTTONUP = 0x00A5,
- NCRBUTTONDBLCLK = 0x00A6,
- NCMBUTTONDOWN = 0x00A7,
- NCMBUTTONUP = 0x00A8,
- NCMBUTTONDBLCLK = 0x00A9,
-
- SYSKEYDOWN = 0x0104,
- SYSKEYUP = 0x0105,
- SYSCHAR = 0x0106,
- SYSDEADCHAR = 0x0107,
- COMMAND = 0x0111,
- SYSCOMMAND = 0x0112,
-
- MOUSEMOVE = 0x0200,
- LBUTTONDOWN = 0x0201,
- LBUTTONUP = 0x0202,
- LBUTTONDBLCLK = 0x0203,
- RBUTTONDOWN = 0x0204,
- RBUTTONUP = 0x0205,
- RBUTTONDBLCLK = 0x0206,
- MBUTTONDOWN = 0x0207,
- MBUTTONUP = 0x0208,
- MBUTTONDBLCLK = 0x0209,
- MOUSEWHEEL = 0x020A,
- XBUTTONDOWN = 0x020B,
- XBUTTONUP = 0x020C,
- XBUTTONDBLCLK = 0x020D,
- MOUSEHWHEEL = 0x020E,
-
- CAPTURECHANGED = 0x0215,
-
- ENTERSIZEMOVE = 0x0231,
- EXITSIZEMOVE = 0x0232,
-
- IME_SETCONTEXT = 0x0281,
- IME_NOTIFY = 0x0282,
- IME_CONTROL = 0x0283,
- IME_COMPOSITIONFULL = 0x0284,
- IME_SELECT = 0x0285,
- IME_CHAR = 0x0286,
- IME_REQUEST = 0x0288,
- IME_KEYDOWN = 0x0290,
- IME_KEYUP = 0x0291,
-
- NCMOUSELEAVE = 0x02A2,
-
- DWMCOMPOSITIONCHANGED = 0x031E,
- DWMNCRENDERINGCHANGED = 0x031F,
- DWMCOLORIZATIONCOLORCHANGED = 0x0320,
- DWMWINDOWMAXIMIZEDCHANGE = 0x0321,
- DWMSENDICONICTHUMBNAIL = 0x0323,
- DWMSENDICONICLIVEPREVIEWBITMAP = 0x0326,
- USER = 0x0400,
-
- // This is the hard-coded message value used by WinForms for Shell_NotifyIcon.
- // It's relatively safe to reuse.
- TRAYMOUSEMESSAGE = 0x800, // WM_USER + 1024
- APP = 0x8000,
- }
-
- [SuppressUnmanagedCodeSecurity]
- internal static class NativeMethods
- {
- ///
- /// Delegate declaration that matches WndProc signatures.
- ///
- public delegate IntPtr MessageHandler(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled);
-
- [DllImport("shell32.dll", EntryPoint = "CommandLineToArgvW", CharSet = CharSet.Unicode)]
- private static extern IntPtr _CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string cmdLine, out int numArgs);
-
- [DllImport("kernel32.dll", EntryPoint = "LocalFree", SetLastError = true)]
- internal static extern IntPtr _LocalFree(IntPtr hMem);
-
- [DllImport("user32.dll")]
- internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
-
- [DllImport("user32.dll", SetLastError = true)]
- internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
-
- [DllImport("user32.dll")]
- internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
-
- [DllImport("user32.dll")]
- internal static extern IntPtr GetForegroundWindow();
-
- [DllImport("user32.dll")]
- internal static extern IntPtr GetDesktopWindow();
-
- [DllImport("user32.dll")]
- internal static extern IntPtr GetShellWindow();
-
- [DllImport("user32.dll", SetLastError = true)]
- internal static extern int GetWindowRect(IntPtr hwnd, out RECT rc);
-
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
-
- [DllImport("user32.DLL", CharSet = CharSet.Unicode)]
- internal static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
-
- public static string[] CommandLineToArgvW(string cmdLine)
- {
- IntPtr argv = IntPtr.Zero;
- try
- {
- int numArgs = 0;
-
- argv = _CommandLineToArgvW(cmdLine, out numArgs);
- if (argv == IntPtr.Zero)
- {
- throw new Win32Exception();
- }
-
- var result = new string[numArgs];
-
- for (int i = 0; i < numArgs; i++)
- {
- IntPtr currArg = Marshal.ReadIntPtr(argv, i * Marshal.SizeOf(typeof(IntPtr)));
- result[i] = Marshal.PtrToStringUni(currArg);
- }
-
- return result;
- }
- finally
- {
- IntPtr p = _LocalFree(argv);
-
- // Otherwise LocalFree failed.
- // Assert.AreEqual(IntPtr.Zero, p);
- }
- }
- }
-
- public interface ISingleInstanceApp
- {
- void OnSecondAppStarted();
- }
-
///
/// This class checks to make sure that only one instance of
/// this application is running at a time.
@@ -235,9 +40,9 @@ namespace PowerLauncher.Helper
private const string ChannelNameSuffix = "SingeInstanceIPCChannel";
///
- /// Application mutex.
+ /// Gets or sets application mutex.
///
- internal static Mutex singleInstanceMutex;
+ internal static Mutex SingleInstanceMutex { get; set; }
///
/// Checks if the instance of the application attempting to start is the first instance.
@@ -252,8 +57,7 @@ namespace PowerLauncher.Helper
string channelName = string.Concat(applicationIdentifier, Delimiter, ChannelNameSuffix);
// Create mutex based on unique application Id to check if this is the first instance of the application.
- bool firstInstance;
- singleInstanceMutex = new Mutex(true, applicationIdentifier, out firstInstance);
+ SingleInstanceMutex = new Mutex(true, applicationIdentifier, out bool firstInstance);
if (firstInstance)
{
_ = CreateRemoteService(channelName);
@@ -271,7 +75,7 @@ namespace PowerLauncher.Helper
///
internal static void Cleanup()
{
- singleInstanceMutex?.ReleaseMutex();
+ SingleInstanceMutex?.ReleaseMutex();
}
///
@@ -352,7 +156,6 @@ namespace PowerLauncher.Helper
/// Creates a client pipe and sends a signal to server to launch first instance
///
/// Application's IPC channel name.
- ///
/// Command line arguments for the second instance, passed to the first instance to take appropriate action.
///
private static async Task SignalFirstInstance(string channelName)
@@ -365,17 +168,6 @@ namespace PowerLauncher.Helper
}
}
- ///
- /// Callback for activating first instance of the application.
- ///
- /// Callback argument.
- /// Always null.
- private static object ActivateFirstInstanceCallback(object _)
- {
- ActivateFirstInstance();
- return null;
- }
-
///
/// Activates the first instance of the application with arguments from a second instance.
///
@@ -391,4 +183,9 @@ namespace PowerLauncher.Helper
((TApplication)Application.Current).OnSecondAppStarted();
}
}
+
+ public interface ISingleInstanceApp
+ {
+ void OnSecondAppStarted();
+ }
}
diff --git a/src/modules/launcher/PowerLauncher/Helper/WindowsInteropHelper.cs b/src/modules/launcher/PowerLauncher/Helper/WindowsInteropHelper.cs
index 613079257b..e00fb7b0ce 100644
--- a/src/modules/launcher/PowerLauncher/Helper/WindowsInteropHelper.cs
+++ b/src/modules/launcher/PowerLauncher/Helper/WindowsInteropHelper.cs
@@ -123,8 +123,7 @@ namespace PowerLauncher.Helper
return false;
}
- RECT appBounds;
- _ = NativeMethods.GetWindowRect(hWnd, out appBounds);
+ _ = NativeMethods.GetWindowRect(hWnd, out RECT appBounds);
// for console (ConsoleWindowClass), we have to check for negative dimensions
if (windowClass == WINDOW_CLASS_CONSOLE)
@@ -181,7 +180,7 @@ namespace PowerLauncher.Helper
}
else
{
- using (var src = new HwndSource(default(HwndSourceParameters)))
+ using (var src = new HwndSource(default))
{
matrix = src.CompositionTarget.TransformFromDevice;
}
diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs
index d87807da1d..757fc35a71 100644
--- a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs
+++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs
@@ -73,13 +73,13 @@ namespace PowerLauncher
Activate();
}
- private void OnLoaded(object sender, RoutedEventArgs _)
+ private void OnLoaded(object sender, RoutedEventArgs e)
{
WindowsInteropHelper.DisableControlBox(this);
InitializePosition();
SearchBox.QueryTextBox.DataContext = _viewModel;
- SearchBox.QueryTextBox.PreviewKeyDown += _launcher_KeyDown;
+ SearchBox.QueryTextBox.PreviewKeyDown += Launcher_KeyDown;
SearchBox.QueryTextBox.TextChanged += QueryTextBox_TextChanged;
// Set initial language flow direction
@@ -103,10 +103,8 @@ namespace PowerLauncher
var result = ((FrameworkElement)e.OriginalSource).DataContext;
if (result != null)
{
- var resultVM = result as ResultViewModel;
-
// This may be null if the tapped item was one of the context buttons (run as admin etc).
- if (resultVM != null)
+ if (result is ResultViewModel resultVM)
{
_viewModel.Results.SelectedItem = resultVM;
_viewModel.OpenResultCommand.Execute(null);
@@ -222,7 +220,7 @@ namespace PowerLauncher
return top;
}
- private void _launcher_KeyDown(object sender, KeyEventArgs e)
+ private void Launcher_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab && Keyboard.IsKeyDown(Key.LeftShift))
{
diff --git a/src/modules/launcher/PowerLauncher/SettingsWatcher.cs b/src/modules/launcher/PowerLauncher/SettingsWatcher.cs
index 5b4220e46c..3ed7d9f6a7 100644
--- a/src/modules/launcher/PowerLauncher/SettingsWatcher.cs
+++ b/src/modules/launcher/PowerLauncher/SettingsWatcher.cs
@@ -18,7 +18,7 @@ namespace PowerLauncher
// Watch for /Local/Microsoft/PowerToys/Launcher/Settings.json changes
public class SettingsWatcher : BaseModel
{
- private static int MAX_RETRIES = 10;
+ private static int _maxRetries = 10;
private static object _watcherSyncObject = new object();
private FileSystemWatcher _watcher;
private Settings _settings;
@@ -96,7 +96,7 @@ namespace PowerLauncher
// This should be changed to properly synch with the settings app instead of retrying.
catch (IOException e)
{
- if (retryCount > MAX_RETRIES)
+ if (retryCount > _maxRetries)
{
retry = false;
}
diff --git a/src/modules/launcher/PowerLauncher/Storage/Record.cs b/src/modules/launcher/PowerLauncher/Storage/Record.cs
new file mode 100644
index 0000000000..ea01cbe967
--- /dev/null
+++ b/src/modules/launcher/PowerLauncher/Storage/Record.cs
@@ -0,0 +1,15 @@
+// Copyright (c) Microsoft Corporation
+// The Microsoft Corporation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace PowerLauncher.Storage
+{
+ public class Record
+ {
+ public string Title { get; set; }
+
+ public string SubTitle { get; set; }
+
+ public string PluginID { get; set; }
+ }
+}
diff --git a/src/modules/launcher/PowerLauncher/Storage/TopMostRecord.cs b/src/modules/launcher/PowerLauncher/Storage/TopMostRecord.cs
index 857bcafcee..f1aa08b425 100644
--- a/src/modules/launcher/PowerLauncher/Storage/TopMostRecord.cs
+++ b/src/modules/launcher/PowerLauncher/Storage/TopMostRecord.cs
@@ -50,13 +50,4 @@ namespace PowerLauncher.Storage
records = dictionary;
}
}
-
- public class Record
- {
- public string Title { get; set; }
-
- public string SubTitle { get; set; }
-
- public string PluginID { get; set; }
- }
}
diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs
index baeb4d4581..a178fd3c9c 100644
--- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs
+++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs
@@ -45,7 +45,7 @@ namespace PowerLauncher.ViewModel
private Query _currentQuery;
private string _queryTextBeforeLeaveResults;
- private CancellationTokenSource _updateSource { get; set; }
+ private CancellationTokenSource _updateSource;
private CancellationToken _updateToken;
private bool _saved;
@@ -626,12 +626,14 @@ namespace PowerLauncher.ViewModel
string hotkeyStr = hotkeyModel.ToString();
try
{
- Hotkey hotkey = new Hotkey();
- hotkey.Alt = hotkeyModel.Alt;
- hotkey.Shift = hotkeyModel.Shift;
- hotkey.Ctrl = hotkeyModel.Ctrl;
- hotkey.Win = hotkeyModel.Win;
- hotkey.Key = (byte)KeyInterop.VirtualKeyFromKey(hotkeyModel.CharKey);
+ Hotkey hotkey = new Hotkey
+ {
+ Alt = hotkeyModel.Alt,
+ Shift = hotkeyModel.Shift,
+ Ctrl = hotkeyModel.Ctrl,
+ Win = hotkeyModel.Win,
+ Key = (byte)KeyInterop.VirtualKeyFromKey(hotkeyModel.CharKey)
+ };
_hotkeyHandle = _hotkeyManager.RegisterHotkey(hotkey, action);
}
diff --git a/src/modules/launcher/PowerLauncher/ViewModel/SettingWindowViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/SettingWindowViewModel.cs
index 5a95738731..af4e86c9ee 100644
--- a/src/modules/launcher/PowerLauncher/ViewModel/SettingWindowViewModel.cs
+++ b/src/modules/launcher/PowerLauncher/ViewModel/SettingWindowViewModel.cs
@@ -34,8 +34,8 @@ namespace PowerLauncher.ViewModel
_storage.Save();
}
- private static Internationalization _translater => InternationalizationManager.Instance;
+ private static Internationalization Translater => InternationalizationManager.Instance;
- public string ActivatedTimes => string.Format(CultureInfo.InvariantCulture, _translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
+ public string ActivatedTimes => string.Format(CultureInfo.InvariantCulture, Translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
}
}