diff --git a/SnapIt.Common/Applications/ApplicationInstance.cs b/SnapIt.Common/Applications/AppInstance.cs similarity index 91% rename from SnapIt.Common/Applications/ApplicationInstance.cs rename to SnapIt.Common/Applications/AppInstance.cs index 687dbf8..0e60b19 100644 --- a/SnapIt.Common/Applications/ApplicationInstance.cs +++ b/SnapIt.Common/Applications/AppInstance.cs @@ -1,6 +1,6 @@ namespace SnapIt.Common.Applications; -public class ApplicationInstance +public class AppInstance { private static readonly Mutex mutex = new Mutex(true, "{FF1FFB1E-5D42-4B8F-B42A-52DA1A1964B7}"); diff --git a/SnapIt.Common/Applications/AppLauncher.cs b/SnapIt.Common/Applications/AppLauncher.cs new file mode 100644 index 0000000..163f847 --- /dev/null +++ b/SnapIt.Common/Applications/AppLauncher.cs @@ -0,0 +1,41 @@ +namespace SnapIt.Common.Applications; + +public class AppLauncher +{ + public static void RunAsAdmin() + { + Run("runas", true); + } + + public static void RunBypassSingleInstance() + { + Run("nosingle"); + } + + public static bool IsAdmin(string[] startupArgs) + { + return startupArgs.Any(arg => arg.Contains("runas")); + } + + public static bool BypassSingleInstance(string[] startupArgs) + { + return startupArgs.Any(arg => arg.Contains("nosingle")); + } + + private static void Run(string argument = null, bool useShellExecute = false) + { + var info = new ProcessStartInfo + { + UseShellExecute = useShellExecute, + FileName = Process.GetCurrentProcess().ProcessName // Application.ExecutablePath; // localAppDataPath + @"\microsoft\windowsapps\SnapIt.exe" // path to the appExecutionAlias + }; + + if (!string.IsNullOrEmpty(argument)) + { + info.Verb = argument; + info.Arguments = $"-{argument}"; + } + + Process.Start(info); + } +} \ No newline at end of file diff --git a/SnapIt.Common/Applications/RunAsAdministrator.cs b/SnapIt.Common/Applications/RunAsAdministrator.cs deleted file mode 100644 index 0fe4965..0000000 --- a/SnapIt.Common/Applications/RunAsAdministrator.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace SnapIt.Common.Applications; - -public class RunAsAdministrator -{ - public static void Run() - { - var info = new ProcessStartInfo - { - Verb = "runas", - Arguments = "-runas", - UseShellExecute = true, - FileName = Environment.ProcessPath // Application.ExecutablePath; // localAppDataPath + @"\microsoft\windowsapps\SnapIt.exe" // path to the appExecutionAlias - }; - Process.Start(info); - } - - public static bool IsAdmin(string[] startupArgs) - { - return startupArgs.Any(arg => arg.Contains("runas")); - } -} \ No newline at end of file diff --git a/SnapIt.Common/Dev.cs b/SnapIt.Common/Dev.cs index cbd6a9b..3585279 100644 --- a/SnapIt.Common/Dev.cs +++ b/SnapIt.Common/Dev.cs @@ -18,7 +18,7 @@ public static class Dev public const bool SkipLicense = false; public const bool TestTrialEnded = false; public const bool TestInTrial = false; - public const bool SkipRunAsAdmin = true; + public const bool SkipRunAsAdmin = false; #else public const bool IsActive = false; public const bool ShowSnapWindowOnStartup = false; diff --git a/SnapIt.Services/KeyboardService.cs b/SnapIt.Services/KeyboardService.cs index f083c0a..37f4345 100644 --- a/SnapIt.Services/KeyboardService.cs +++ b/SnapIt.Services/KeyboardService.cs @@ -84,12 +84,15 @@ public async Task InitializeAsync() public void SetSnappingStopped() { - var map = new Dictionary + if (settingService.Settings != null) { - { Combination.FromString(settingService.Settings.StartStopShortcut.Replace(" ", string.Empty).Replace("Win", "LWin")), StartStopSnapping } - }; + var map = new Dictionary + { + { Combination.FromString(settingService.Settings.StartStopShortcut.Replace(" ", string.Empty).Replace("Win", "LWin")), StartStopSnapping } + }; - globalHook?.OnCombination(map); + globalHook?.OnCombination(map); + } } public void Dispose() diff --git a/SnapIt.Test/App.xaml b/SnapIt.Test/App.xaml index 23894d7..ed86ea2 100644 --- a/SnapIt.Test/App.xaml +++ b/SnapIt.Test/App.xaml @@ -1,11 +1,11 @@  + StartupUri="Window3.xaml"> diff --git a/SnapIt.Test/SnapIt.Test.csproj b/SnapIt.Test/SnapIt.Test.csproj index e0f8562..37b91a5 100644 --- a/SnapIt.Test/SnapIt.Test.csproj +++ b/SnapIt.Test/SnapIt.Test.csproj @@ -31,9 +31,10 @@ - + + diff --git a/SnapIt.Test/Window3.xaml b/SnapIt.Test/Window3.xaml new file mode 100644 index 0000000..04b8c3d --- /dev/null +++ b/SnapIt.Test/Window3.xaml @@ -0,0 +1,16 @@ + + +