Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add login button to plugin welcome page [IDE-798] #248

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
4 changes: 1 addition & 3 deletions plugin/OSGI-INF/l10n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ tooltip.showNetNewIssues=Show Only Net New Issues
scanWorkspace.name=snykWorkspaceScan
scanWorkspace.label=Snyk Test Workspace

snyk.trust.dialog.warning.text=When scanning project files for vulnerabilities, Snyk may automatically execute code such as invoking the package manager to get dependency information.<br><br>You should only scan projects you trust.<br><br>


snyk.panel.auth.trust.warning.text=When scanning project files, Snyk may automatically execute code such as invoking the package manager to get dependency information.<br/>You should only scan projects you trust. <a href="https://docs.snyk.io/ide-tools/jetbrains-plugins/folder-trust">More info</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jetbrains link does not look right :)

Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public String replaceCssVariables(String html) {
html = html.replace("var(--text-color)", getColorAsHex("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR", "#000000"));
html = html.replace("var(--background-color)", getColorAsHex("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END", "#FFFFFF"));
html = html.replace("var(--code-background-color)", getColorAsHex("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START", "#F0F0F0"));
html = html.replace("var(--button-color)", getColorAsHex("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START", "#F0F0F0"));
html = html.replace("var(--circle-color)", getColorAsHex("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START", "#F0F0F0"));

html = html.replace("var(--border-color)", getColorAsHex("org.eclipse.ui.workbench.ACTIVE_TAB_OUTER_KEYLINE_COLOR", "#CCCCCC"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static StaticPageHtmlProvider getInstance() {

public String getInitHtml() {
String snykWarningText = Platform.getResourceString(Platform.getBundle("io.snyk.eclipse.plugin"),
"%snyk.trust.dialog.warning.text");
"%snyk.panel.auth.trust.warning.text");

Bundle bundle = Platform.getBundle("io.snyk.eclipse.plugin");
String base64Image = ResourceUtils.getBase64Image(bundle, "logo_snyk.png");
Expand All @@ -35,35 +35,62 @@ public String getInitHtml() {
<title>Snyk for Eclipse</title>
<style>
body {
font-family: var(--default-font);
font-family: var(--default-font);
background-color: var(--background-color);
color: var(--text-color);
}
.container {
display: flex;
align-items: center;
}
.welcome-text {
width: 520px;
}
.agreement-text {
font-size: smaller;
display: inline-block;
width: 350px;
}
.logo {
margin-right: 20px;
}
a {
color: var(--link-color)
}

div {
padding: 20px
}
a {
color: var(--link-color);
}
div {
padding: 20px;
}
button {
text-align: center;
text-decoration: none;
background-color: var(--button-color);
display: inline-block;
border-color: var(--border-color);
border-style: solid;
border-radius: 5px;
font-family: inherit;
font-size: inherit;
color: inherit;
}
</style>
</head>
<body>
<div class="container">
<img src='data:image/png;base64,%s' alt='Snyk Logo'>
<div>
<div class="welcome-text">
<p><strong>Welcome to Snyk for Eclipse</strong></p>
<ol>
<li align="left">Authenticate to Snyk.io</li>
<li align="left">Analyze code for issues and vulnerabilities</li>
<li align="left">Improve your code and upgrade dependencies</li>
</ol>
<p>%s</p>
By connecting your account with Snyk, you agree to<br>
the Snyk <a href="https://snyk.io/policies/privacy/">Privacy Policy</a>,
and the Snyk <a href="https://snyk.io/policies/terms-of-service/">Terms of Service</a>.
<button type="button" onclick="window.initiateLogin()">Trust project and scan</button>
<p class="agreement-text">
By connecting your account with Snyk, you agree to
the Snyk <a href="https://snyk.io/policies/privacy/">Privacy Policy</a>,
and the Snyk <a href="https://snyk.io/policies/terms-of-service/">Terms of Service</a>.
</p>
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.concurrent.CompletableFuture;

import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
Expand All @@ -18,13 +19,13 @@
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;

import com.google.gson.Gson;

import io.snyk.eclipse.plugin.html.BaseHtmlProvider;
import io.snyk.eclipse.plugin.html.HtmlProviderFactory;
import io.snyk.eclipse.plugin.html.StaticPageHtmlProvider;
import io.snyk.eclipse.plugin.utils.SnykLogger;
import io.snyk.eclipse.plugin.wizards.SnykWizard;

@SuppressWarnings("restriction")
public class BrowserHandler {
Expand Down Expand Up @@ -66,6 +67,18 @@ public Object function(Object[] arguments) {
}
};

new BrowserFunction(browser, "initiateLogin") {
@Override
public Object function(Object[] arguments) {
SnykWizard wizard = new SnykWizard();
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(),wizard);

dialog.setBlockOnOpen(true);
dialog.open();
return null;
Comment on lines +73 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: don't duplicate the code, but move SnykExtendedLanguageClient.runSnykWizard() to a central place and use it from all places where the Wizard is launched.

}
};

browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
Expand All @@ -89,6 +102,7 @@ public void completed(ProgressEvent event) {
}
}
});

initBrowserText();
}

Expand Down Expand Up @@ -127,7 +141,6 @@ public CompletableFuture<Void> updateBrowserContent(TreeNode node) {
browser.setText(browserContent);
});
});

}

private BaseHtmlProvider getHtmlProvider(TreeNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void testHtmlProviderReplacesPlaceholders() throws Exception {
assertTrue(!htmlContent.contains("${ideScript})"));
assertTrue(!htmlContent.contains("ideNonce"));
assertTrue(!htmlContent.contains("var(--text-color)"));
assertTrue(!htmlContent.contains("var(----background-color)"));
assertTrue(!htmlContent.contains("var(--background-color)"));
assertTrue(!htmlContent.contains("var(--button-color)"));
assertTrue(!htmlContent.contains("var(--border-color)"));
assertTrue(!htmlContent.contains("var(--link-color)"));
assertTrue(!htmlContent.contains("var(--text-color)"));
Expand Down
Loading