Skip to content

Commit caa9223

Browse files
committed
fix: refactor the browserFunctions to enableDelta
1 parent 630c41c commit caa9223

5 files changed

Lines changed: 27 additions & 51 deletions

File tree

plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@ public String getNoDescriptionHtml() {
9494
return html;
9595
}
9696

97-
public String replaceCssVariablesAndScript(String html, String ideScript) {
98-
html = replaceCssVariables(html);
99-
html = html.replace("${ideScript}", ideScript);
100-
101-
return html;
102-
}
103-
10497
public String replaceCssVariables(String html) {
10598
// Build the CSS with the nonce
10699
String nonce = getNonce();
@@ -115,8 +108,7 @@ public String replaceCssVariables(String html) {
115108
getColorAsHex("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR", "#000000"));
116109

117110
html = html.replace("var(--ide-background-color)",
118-
getColorAsHex("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START", "#FFFFFF"));
119-
111+
getColorAsHex("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START", "#FFFFFF"));
120112
html = html.replace("var(--background-color)",
121113
getColorAsHex("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END", "#FFFFFF"));
122114
html = html.replace("var(--code-background-color)",

plugin/src/main/java/io/snyk/eclipse/plugin/html/StaticPageHtmlProvider.java

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package io.snyk.eclipse.plugin.html;
22

3+
import java.io.BufferedReader;
34
import java.io.IOException;
45
import java.io.InputStream;
5-
import java.nio.charset.StandardCharsets;
6+
import java.io.InputStreamReader;
67

8+
import org.eclipse.core.runtime.ILog;
79
import org.eclipse.core.runtime.Platform;
810
import org.osgi.framework.Bundle;
11+
import io.snyk.eclipse.plugin.utils.SnykLogger;
912

1013
import io.snyk.eclipse.plugin.utils.ResourceUtils;
1114

1215
public class StaticPageHtmlProvider extends BaseHtmlProvider {
1316
private static StaticPageHtmlProvider instance = new StaticPageHtmlProvider();
17+
private static ILog logger;
1418

1519
public static StaticPageHtmlProvider getInstance() {
1620
synchronized (StaticPageHtmlProvider.class) {
@@ -154,39 +158,27 @@ public String getInitHtml() {
154158
}
155159

156160
public String getSummaryInitHtml() {
157-
String htmlContent = "";
158-
try {
159-
InputStream inputStream = getClass().getResourceAsStream("/ui/html/ScanSummaryInit.html");
160-
if (inputStream != null) {
161-
htmlContent = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
162-
inputStream.close();
161+
if (logger == null) {
162+
logger = Platform.getLog(getClass());
163+
}
164+
StringBuilder content = new StringBuilder();
165+
166+
try (InputStream inputStream = getClass().getResourceAsStream("/ui/html/ScanSummaryInit.html");
167+
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
168+
169+
String line;
170+
while ((line = reader.readLine()) != null) {
171+
content.append(line).append("\n");
163172
}
164173
} catch (IOException e) {
165-
e.printStackTrace();
174+
SnykLogger.logError(e);
166175
}
167-
return replaceCssVariables(htmlContent);
168-
}
169176

170-
public String ideScript() {
171-
return """
172-
<script>
173-
document.addEventListener('DOMContentLoaded', function() {
174-
const totalIssuesRadio = document.getElementById('totalIssues');
175-
const newIssuesRadio = document.getElementById('newIssues');
176-
177-
totalIssuesRadio.addEventListener('change', function() {
178-
window.totalIssues();
179-
});
180-
181-
newIssuesRadio.addEventListener('change', function() {
182-
window.newIssues();
183-
});
184-
});
185-
</script>
186-
""";
177+
return replaceCssVariables(content.toString());
187178
}
188179

189180
public String getFormattedSummaryHtml(String summary) {
190-
return replaceCssVariablesAndScript(summary, ideScript());
181+
summary = summary.replace("${ideFunc}", "window.enableDelta(isEnabled);");
182+
return replaceCssVariables(summary);
191183
}
192184
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/SnykToolView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ protected void outputCommandResult(Object result) {
468468
SnykExtendedLanguageClient.getInstance().showMessage(messageParams);
469469
} else {
470470
SnykLogger.logError(new RuntimeException(stdOut));
471-
472471
}
473472
}
474473
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/SummaryBrowserHandler.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,19 @@ public SummaryBrowserHandler(Browser browser) {
1818

1919
public void initialize() {
2020

21-
new BrowserFunction(browser, "totalIssues") {
21+
new BrowserFunction(browser, "enableDelta") {
2222
@Override
2323
public Object function(Object[] arguments) {
24-
Preferences.getInstance().store(Preferences.ENABLE_DELTA, Boolean.FALSE.toString());
25-
updateConfiguration();
26-
27-
return null;
28-
}
29-
};
24+
boolean value = false;
25+
if (arguments.length > 0 && arguments[0] instanceof Boolean) {
26+
value = (Boolean) arguments[0];
27+
}
3028

31-
new BrowserFunction(browser, "newIssues") {
32-
@Override
33-
public Object function(Object[] arguments) {
34-
Preferences.getInstance().store(Preferences.ENABLE_DELTA, Boolean.TRUE.toString());
29+
Preferences.getInstance().store(Preferences.ENABLE_DELTA, Boolean.toString(value));
3530
updateConfiguration();
3631

3732
return null;
3833
}
39-
4034
};
4135

4236
setDefaultBrowserText();

plugin/src/main/java/io/snyk/languageserver/protocolextension/SnykExtendedLanguageClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ public void snykScan(SnykScanParam param) {
381381
this.toolView.refreshBrowser(param.getStatus());
382382
}
383383

384-
// TODO what data is returned in the SNYK_SCAN_SUMMARY?
385384
@JsonNotification(value = LsConstants.SNYK_SCAN_SUMMARY)
386385
public void updateSummaryPanel(SummaryPanelParams summary) {
387386
openToolView();

0 commit comments

Comments
 (0)