Skip to content

Commit

Permalink
fix show checkmarx window in startup
Browse files Browse the repository at this point in the history
  • Loading branch information
elchananarb committed Dec 23, 2024
1 parent 6c9442c commit b213ecc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
18 changes: 12 additions & 6 deletions ast-visual-studio-extension/CxExtension/CxWindowPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public sealed class CxWindowPackage : AsyncPackage
/// CxWindowPackage GUID string.
/// </summary>
public const string PackageGuidString = "63d5f3b4-a254-4bef-974b-0733c306ed2c";
private static bool isInitialized = false;




#region Package Members

/// <summary>
Expand All @@ -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);



}
Expand Down

0 comments on commit b213ecc

Please sign in to comment.