From 66bf6d320c0a703816e5883be9fc6ca04a2e635d Mon Sep 17 00:00:00 2001 From: Gerhard Olsson Date: Sat, 1 Apr 2023 16:48:23 +0200 Subject: [PATCH] Restore from minimized: Configurable avoid async Git Add an experimental setting to not run git-ls-files when the window is minimized on activation, as async commands when minimized seem to block the app from being restored. Rename configuration added in #10119 to deactivate at upgrade as this setting may give a negative experience after #10802 mostly fixes the problem. --- GitCommands/Settings/AppSettings.cs | 9 +++++++-- GitUI/CommandsDialogs/FormBrowse.cs | 3 ++- GitUI/UserControls/InteractiveGitActionControl.cs | 12 ++++++++---- ResourceManager/GitExtensionsFormBase.cs | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/GitCommands/Settings/AppSettings.cs b/GitCommands/Settings/AppSettings.cs index 32794e61417..cebbd7a6eaa 100644 --- a/GitCommands/Settings/AppSettings.cs +++ b/GitCommands/Settings/AppSettings.cs @@ -2005,9 +2005,14 @@ public static bool WriteErrorLog } // Set manually in settings file - public static bool WorkaroundRestoreFromMinimize + public static bool WorkaroundActivateFromMinimize { - get => GetBool("WorkaroundRestoreFromMinimize", false); + get => GetBool("WorkaroundActivateFromMinimize", false); + } + + public static bool GitAsyncWhenMinimized + { + get => GetBool("GitAsyncWhenMinimized", true); } private static IEnumerable<(string name, string value)> GetSettingsFromRegistry() diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index 860c1af4c9c..31ab356b629 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -1059,7 +1059,8 @@ private void OnActivate() notificationBarBisectInProgress.RefreshBisect(); // check if we are in the middle of an action (merge/rebase/etc.) - notificationBarGitActionInProgress.RefreshGitAction(); + notificationBarGitActionInProgress.RefreshGitAction( + checkForConflicts: AppSettings.GitAsyncWhenMinimized || (WindowState != FormWindowState.Minimized)); } private void UpdateStashCount() diff --git a/GitUI/UserControls/InteractiveGitActionControl.cs b/GitUI/UserControls/InteractiveGitActionControl.cs index 192cf15ee3a..8093a6e9373 100644 --- a/GitUI/UserControls/InteractiveGitActionControl.cs +++ b/GitUI/UserControls/InteractiveGitActionControl.cs @@ -59,7 +59,11 @@ public void RefreshBisect() SetGitAction(GitAction.None, false); } - public void RefreshGitAction() + /// + /// Refresh the banner in the revision grid after reactivation. + /// + /// Allow running Git command to check for conflicts. + public void RefreshGitAction(bool checkForConflicts) { // get the current state of the repo @@ -72,9 +76,9 @@ public void RefreshGitAction() try { // This command can be executed seemingly in the background (selecting Browse), - // do not notify the user (this can occur if Git is upgraded) - // The command also occasionally fails when "reactivating" WSL Git. - hasConflicts = Module.InTheMiddleOfConflictedMerge(throwOnErrorExit: false); + // do not notify the user (this can occur if Git is upgraded). + // Running Git commands async when restoring may fail. + hasConflicts = checkForConflicts && Module.InTheMiddleOfConflictedMerge(throwOnErrorExit: false); } catch (Win32Exception) { diff --git a/ResourceManager/GitExtensionsFormBase.cs b/ResourceManager/GitExtensionsFormBase.cs index bd5037a15f2..4a42133a8fa 100644 --- a/ResourceManager/GitExtensionsFormBase.cs +++ b/ResourceManager/GitExtensionsFormBase.cs @@ -93,9 +93,9 @@ protected override void WndProc(ref Message m) if (m.Msg == NativeMethods.WM_ACTIVATEAPP && m.WParam != IntPtr.Zero) { OnApplicationActivated(); - if (WindowState == FormWindowState.Minimized && Owner is null && AppSettings.WorkaroundRestoreFromMinimize) + if (WindowState == FormWindowState.Minimized && Owner is null && AppSettings.WorkaroundActivateFromMinimize) { - // Changed behavior from .NET4 to .NET5, application occasionally requires explicit "restore" in Taskbar. + // Application occasionally requires explicit "restore" in Taskbar. // See https://github.com/gitextensions/gitextensions/pull/10119. Trace.WriteLine("WindowState is unexpectedly Minimized in OnApplicationActivated(), restoring."); WindowState = FormWindowState.Normal;