Skip to content

Commit

Permalink
wip: cli settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawkyZ committed Dec 16, 2024
1 parent 73cdaa9 commit f1d42b4
Show file tree
Hide file tree
Showing 11 changed files with 585 additions and 280 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Snyk.VisualStudio.Extension.Service;

namespace Snyk.VisualStudio.Extension.Settings;

public interface ISnykCliOptionsDialogPage
{
void Initialize(ISnykServiceProvider provider);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using Snyk.VisualStudio.Extension.Service;

namespace Snyk.VisualStudio.Extension.Settings;

[Guid("D1D89CEB-7691-4A67-8579-4C3DDE776982")]
[ComVisible(true)]
public class SnykCliOptionsDialogPage : DialogPage, ISnykCliOptionsDialogPage
{
private SnykCliOptionsUserControl snykCliOptionsUserControl;
private ISnykServiceProvider serviceProvider;

public void Initialize(ISnykServiceProvider provider)
{
this.serviceProvider = provider;
this.SnykOptions = provider.Options;
}

public ISnykOptions SnykOptions { get; set; }

protected override IWin32Window Window => SnykCliOptionsUserControl;
public SnykCliOptionsUserControl SnykCliOptionsUserControl
{
get
{
if (snykCliOptionsUserControl == null)
{
snykCliOptionsUserControl = new SnykCliOptionsUserControl(serviceProvider);
}
return snykCliOptionsUserControl;
}
}

// This method is used when the user clicks "Ok"
public override void SaveSettingsToStorage()
{
HandleCliDownload();
this.SnykOptions.SaveSettings();
this.SnykOptions.InvokeSettingsChangedEvent();
}

protected override void OnClosed(EventArgs e)
{

}

private void HandleCliDownload()
{
var releaseChannel = SnykCliOptionsUserControl.GetReleaseChannel().Trim();
var downloadUrl = SnykCliOptionsUserControl.GetCliDownloadUrl().Trim();
var manageBinariesAutomatically = SnykCliOptionsUserControl.GetManageBinariesAutomatically();
if (!manageBinariesAutomatically)
{
this.SnykOptions.CurrentCliVersion = string.Empty;
this.SnykOptions.BinariesAutoUpdate = false;
serviceProvider.TasksService.CancelDownloadTask();
// Language Server restart will happen on DownloadCancelled Event.
return;
}
if (this.SnykOptions.CliReleaseChannel != releaseChannel || this.SnykOptions.CliDownloadUrl != downloadUrl || this.SnykOptions.BinariesAutoUpdate != manageBinariesAutomatically)
{
this.SnykOptions.CliDownloadUrl = downloadUrl;
this.SnykOptions.CliReleaseChannel = releaseChannel;
this.SnykOptions.BinariesAutoUpdate = manageBinariesAutomatically;
serviceProvider.TasksService.CancelDownloadTask();
this.serviceProvider.TasksService.Download();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f1d42b4

Please sign in to comment.