[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 EventWaitHandle _eventHandle;
private Thread _exitWaitThread;
public static bool DebugMode public static bool DebugMode
{ {
get get
@ -61,17 +63,8 @@ namespace FancyZonesEditor
Overlay = new Overlay(); Overlay = new Overlay();
MainWindowSettings = new MainWindowSettingsModel(); MainWindowSettings = new MainWindowSettingsModel();
new Thread(() => _exitWaitThread = new Thread(App_WaitExit);
{ _exitWaitThread.Start();
_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");
} }
private void OnStartup(object sender, StartupEventArgs e) private void OnStartup(object sender, StartupEventArgs e)
@ -132,14 +125,28 @@ namespace FancyZonesEditor
private void OnExit(object sender, ExitEventArgs e) private void OnExit(object sender, ExitEventArgs e)
{ {
Dispose();
if (_eventHandle != null) if (_eventHandle != null)
{ {
_eventHandle.Set(); _eventHandle.Set();
} }
_exitWaitThread.Join();
Logger.LogInfo("FancyZones Editor exited"); 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) 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) 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 methodName = stackTrace.GetFrame(3)?.GetMethod();
var className = methodName?.DeclaringType.Name; var className = methodName?.DeclaringType.Name;
return className + " :: " + methodName?.Name; return className + "::" + methodName?.Name;
} }
} }
} }

View file

@ -4,8 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Automation; using System.Windows.Automation;
using System.Windows.Automation.Peers; using System.Windows.Automation.Peers;
@ -43,20 +41,7 @@ namespace FancyZonesEditor
DataContext = _settings; DataContext = _settings;
KeyUp += MainWindow_KeyUp; KeyUp += MainWindow_KeyUp;
PreviewKeyDown += MainWindow_PreviewKeyDown;
// 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;
}
}
};
if (spanZonesAcrossMonitors) 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) private void LayoutItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{ {
CloseDialog(sender); CloseDialog(sender);
@ -256,7 +255,7 @@ namespace FancyZonesEditor
private void Announce(string name, string message) private void Announce(string name, string message)
{ {
if (AutomationPeer.ListenerExists(AutomationEvents.MenuOpened)) if (AutomationPeer.ListenerExists(AutomationEvents.MenuOpened) && _createLayoutAnnounce != null)
{ {
var peer = UIElementAutomationPeer.FromElement(_createLayoutAnnounce); var peer = UIElementAutomationPeer.FromElement(_createLayoutAnnounce);
AutomationProperties.SetName(_createLayoutAnnounce, name + " " + message); AutomationProperties.SetName(_createLayoutAnnounce, name + " " + message);
@ -516,7 +515,10 @@ namespace FancyZonesEditor
private void TextBox_GotKeyboardFocus(object sender, RoutedEventArgs e) private void TextBox_GotKeyboardFocus(object sender, RoutedEventArgs e)
{ {
TextBox tb = sender as TextBox; TextBox tb = sender as TextBox;
tb.SelectionStart = tb.Text.Length; if (tb != null)
{
tb.SelectionStart = tb.Text.Length;
}
} }
private void CancelLayoutChanges() private void CancelLayoutChanges()