From b213ecc6cc83119063b8b578af3024c65628adde Mon Sep 17 00:00:00 2001 From: elchananarb Date: Mon, 23 Dec 2024 21:51:46 +0200 Subject: [PATCH] fix show checkmarx window in startup --- .../Commands/AddExtensionWindowCmd.cs | 13 ++++++++++++- .../CxExtension/CxWindowPackage.cs | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ast-visual-studio-extension/CxExtension/Commands/AddExtensionWindowCmd.cs b/ast-visual-studio-extension/CxExtension/Commands/AddExtensionWindowCmd.cs index 4702110..3d66acc 100644 --- a/ast-visual-studio-extension/CxExtension/Commands/AddExtensionWindowCmd.cs +++ b/ast-visual-studio-extension/CxExtension/Commands/AddExtensionWindowCmd.cs @@ -43,8 +43,19 @@ public static async Task InitializeAsync(AsyncPackage package) OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService; Instance = new CxWindowCommand(package, commandService); } + private void Execute(object sender, EventArgs e) + { + _ = this.package.JoinableTaskFactory.RunAsync(async delegate + { + ToolWindowPane window = await this.package.ShowToolWindowAsync(typeof(CxWindow), 0, true, this.package.DisposalToken); + if ((null == window) || (null == window.Frame)) + { + throw new NotSupportedException("Cannot create tool window"); + } + }); + } - public void Execute(object sender, EventArgs e) + public void InitializeInBackground() { _ = this.package.JoinableTaskFactory.RunAsync(async delegate { diff --git a/ast-visual-studio-extension/CxExtension/CxWindowPackage.cs b/ast-visual-studio-extension/CxExtension/CxWindowPackage.cs index 212ad70..aa764c4 100644 --- a/ast-visual-studio-extension/CxExtension/CxWindowPackage.cs +++ b/ast-visual-studio-extension/CxExtension/CxWindowPackage.cs @@ -38,8 +38,10 @@ public sealed class CxWindowPackage : AsyncPackage /// CxWindowPackage GUID string. /// public const string PackageGuidString = "63d5f3b4-a254-4bef-974b-0733c306ed2c"; + private static bool isInitialized = false; + + - #region Package Members /// @@ -58,17 +60,21 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. - await this.JoinableTaskFactory.SwitchToMainThreadAsync(); // Command to create Checkmarx extension main window - await CxWindowCommand.InitializeAsync(this); // Check credentials and open window - if (CxUtils.AreCxCredentialsDefined(this)) + await this.JoinableTaskFactory.SwitchToMainThreadAsync(); + + if (CxUtils.AreCxCredentialsDefined(this) && !isInitialized) { + await CxWindowCommand.InitializeAsync(this); + isInitialized = true; await Task.Delay(1000, cancellationToken); - await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - CxWindowCommand.Instance.Execute(null, EventArgs.Empty); + CxWindowCommand.Instance.InitializeInBackground(); + return; } + await CxWindowCommand.InitializeAsync(this); + }