[FancyZones Editor] Crash fix (#13930)

This commit is contained in:
Seraphima Zykova 2021-10-25 13:05:44 +03:00 committed by GitHub
parent 91ed50d993
commit ce942b0585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 30 deletions

View File

@ -37,6 +37,8 @@ namespace FancyZonesEditor
private EventWaitHandle _eventHandle;
private Thread _exitWaitThread;
public static bool DebugMode
{
get
@ -61,17 +63,8 @@ namespace FancyZonesEditor
Overlay = new Overlay();
MainWindowSettings = new MainWindowSettingsModel();
new Thread(() =>
{
_eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, interop.Constants.FZEExitEvent());
if (_eventHandle.WaitOne())
{
Logger.LogInfo("FancyZones disabled, exit");
Environment.Exit(0);
}
}).Start();
Logger.LogInfo("FancyZones Editor started");
_exitWaitThread = new Thread(App_WaitExit);
_exitWaitThread.Start();
}
private void OnStartup(object sender, StartupEventArgs e)
@ -132,14 +125,28 @@ namespace FancyZonesEditor
private void OnExit(object sender, ExitEventArgs e)
{
Dispose();
if (_eventHandle != null)
{
_eventHandle.Set();
}
_exitWaitThread.Join();
Logger.LogInfo("FancyZones Editor exited");
}
private void App_WaitExit()
{
_eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, interop.Constants.FZEExitEvent());
if (_eventHandle.WaitOne())
{
Logger.LogInfo("Exit event triggered");
Environment.Exit(0);
}
}
public void App_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.LeftShift || e.Key == System.Windows.Input.Key.RightShift)

View File

@ -95,7 +95,7 @@ namespace FancyZonesEditor.Logs
var methodName = stackTrace.GetFrame(3)?.GetMethod();
var className = methodName?.DeclaringType.Name;
return className + " :: " + methodName?.Name;
return className + "::" + methodName?.Name;
}
}
}

View File

@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
@ -43,20 +41,7 @@ namespace FancyZonesEditor
DataContext = _settings;
KeyUp += MainWindow_KeyUp;
// Prevent closing the dialog with enter
PreviewKeyDown += (object sender, KeyEventArgs e) =>
{
if (e.Key == Key.Enter && _openedDialog != null && _openedDialog.IsVisible)
{
var source = e.OriginalSource as RadioButton;
if (source != null && source.IsChecked != true)
{
source.IsChecked = true;
e.Handled = true;
}
}
};
PreviewKeyDown += MainWindow_PreviewKeyDown;
if (spanZonesAcrossMonitors)
{
@ -86,6 +71,20 @@ namespace FancyZonesEditor
}
}
// Prevent closing the dialog with enter
private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && _openedDialog != null && _openedDialog.IsVisible)
{
var source = e.OriginalSource as RadioButton;
if (source != null && source.IsChecked != true)
{
source.IsChecked = true;
e.Handled = true;
}
}
}
private void LayoutItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
CloseDialog(sender);
@ -256,7 +255,7 @@ namespace FancyZonesEditor
private void Announce(string name, string message)
{
if (AutomationPeer.ListenerExists(AutomationEvents.MenuOpened))
if (AutomationPeer.ListenerExists(AutomationEvents.MenuOpened) && _createLayoutAnnounce != null)
{
var peer = UIElementAutomationPeer.FromElement(_createLayoutAnnounce);
AutomationProperties.SetName(_createLayoutAnnounce, name + " " + message);
@ -516,7 +515,10 @@ namespace FancyZonesEditor
private void TextBox_GotKeyboardFocus(object sender, RoutedEventArgs e)
{
TextBox tb = sender as TextBox;
tb.SelectionStart = tb.Text.Length;
if (tb != null)
{
tb.SelectionStart = tb.Text.Length;
}
}
private void CancelLayoutChanges()