Skip to content

Commit 5632770

Browse files
committed
addition of do not show again option to prompt
1 parent c89a544 commit 5632770

File tree

4 files changed

+98
-11
lines changed

4 files changed

+98
-11
lines changed

plugin/src/software/aws/toolkits/eclipse/amazonq/util/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ private Constants() {
1515
public static final String LSP_OPT_OUT_TELEMETRY_CONFIGURATION_KEY = "optOutTelemetry";
1616
public static final String LSP_Q_CONFIGURATION_KEY = "aws.q";
1717
public static final String LSP_CW_CONFIGURATION_KEY = "aws.codeWhisperer";
18-
public static final String LAST_NOTIFIED_UPDATE_VERSION = "lastShownNotificationVersion";
18+
public static final String DO_NOT_SHOW_UPDATE_KEY = "doNotShowUpdate";
1919
public static final String PLUGIN_UPDATE_NOTIFICATION_TITLE = "Amazon Q Update Available";
20-
public static final String PLUGIN_UPDATE_NOTIFICATION_BODY = "A new version of the Amazon Q plugin is available. Please update for newest features.";
20+
public static final String PLUGIN_UPDATE_NOTIFICATION_BODY = "Amazon Q plugin version %s is available. Please update for newest features.";
2121
public static final String LSP_CW_OPT_OUT_KEY = "shareCodeWhispererContentWithAWS";
2222
public static final String LSP_CODE_REFERENCES_OPT_OUT_KEY = "includeSuggestionsWithCodeReferences";
2323
public static final String IDE_CUSTOMIZATION_NOTIFICATION_TITLE = "Amazon Q Customization";
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.eclipse.amazonq.util;
5+
6+
import org.eclipse.swt.events.MouseAdapter;
7+
import org.eclipse.swt.events.MouseEvent;
8+
import org.eclipse.swt.events.SelectionAdapter;
9+
import org.eclipse.swt.events.SelectionEvent;
10+
import org.eclipse.swt.graphics.Color;
11+
import org.eclipse.swt.graphics.Font;
12+
import org.eclipse.swt.graphics.FontData;
13+
import org.eclipse.swt.layout.GridData;
14+
import org.eclipse.swt.widgets.Button;
15+
import org.eclipse.swt.widgets.Composite;
16+
import org.eclipse.swt.widgets.Display;
17+
import org.eclipse.swt.widgets.Label;
18+
19+
import java.util.function.Consumer;
20+
import org.eclipse.swt.SWT;
21+
22+
public final class PersistentToolkitNotification extends ToolkitNotification {
23+
private final Consumer<Boolean> checkboxCallback;
24+
25+
public PersistentToolkitNotification(Display display, String title, String description, Consumer<Boolean> checkboxCallback) {
26+
super(display, title, description);
27+
this.checkboxCallback = checkboxCallback;
28+
}
29+
30+
@Override
31+
protected void createContentArea(final Composite parent) {
32+
super.createContentArea(parent);
33+
34+
Composite container = (Composite) parent.getChildren()[0];
35+
36+
// create checkbox
37+
Button doNotShowCheckbox = new Button(container, SWT.CHECK);
38+
GridData checkboxGridData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
39+
doNotShowCheckbox.setLayoutData(checkboxGridData);
40+
41+
// create checkbox button text
42+
Label checkboxLabel = new Label(container, SWT.NONE);
43+
checkboxLabel.setText("Don't show this message again");
44+
checkboxLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
45+
46+
// style button text
47+
Color grayColor = new Color(parent.getDisplay(), 128, 128, 128);
48+
checkboxLabel.setForeground(grayColor);
49+
50+
Font originalFont = checkboxLabel.getFont();
51+
FontData[] fontData = originalFont.getFontData();
52+
for (FontData fd : fontData) {
53+
fd.setHeight(fd.getHeight() - 1);
54+
}
55+
Font smallerFont = new Font(parent.getDisplay(), fontData);
56+
checkboxLabel.setFont(smallerFont);
57+
58+
checkboxLabel.addDisposeListener(e -> {
59+
smallerFont.dispose();
60+
grayColor.dispose();
61+
});
62+
63+
// make button text clickable
64+
checkboxLabel.addMouseListener(new MouseAdapter() {
65+
@Override
66+
public void mouseUp(MouseEvent e) {
67+
doNotShowCheckbox.setSelection(!doNotShowCheckbox.getSelection());
68+
if (checkboxCallback != null) {
69+
checkboxCallback.accept(doNotShowCheckbox.getSelection());
70+
}
71+
}
72+
});
73+
74+
doNotShowCheckbox.addSelectionListener(new SelectionAdapter() {
75+
@Override
76+
public void widgetSelected(SelectionEvent e) {
77+
if (checkboxCallback != null) {
78+
checkboxCallback.accept(doNotShowCheckbox.getSelection());
79+
}
80+
}
81+
});
82+
}
83+
84+
}

plugin/src/software/aws/toolkits/eclipse/amazonq/util/ToolkitNotification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.eclipse.jface.resource.ImageDescriptor;
2020
import org.eclipse.mylyn.commons.ui.dialogs.AbstractNotificationPopup;
2121

22-
public final class ToolkitNotification extends AbstractNotificationPopup {
22+
public class ToolkitNotification extends AbstractNotificationPopup {
2323

2424
private final String title;
2525
private final String description;

plugin/src/software/aws/toolkits/eclipse/amazonq/util/UpdateUtils.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static UpdateUtils getInstance() {
3333
}
3434

3535
private UpdateUtils() {
36-
mostRecentNotificationVersion = Activator.getPluginStore().getObject(Constants.LAST_NOTIFIED_UPDATE_VERSION, Version.class);
36+
mostRecentNotificationVersion = Activator.getPluginStore().getObject(Constants.DO_NOT_SHOW_UPDATE_KEY, Version.class);
3737
String localString = PluginClientMetadata.getInstance().getPluginVersion();
3838
localVersion = ArtifactUtils.parseVersion(localString.substring(0, localString.lastIndexOf(".")));
3939
}
@@ -55,11 +55,7 @@ private boolean newUpdateAvailable() {
5555

5656
public void checkForUpdate() {
5757
if (newUpdateAvailable()) {
58-
//notify user
5958
showNotification();
60-
61-
//update storage with notification version
62-
Activator.getPluginStore().putObject(Constants.LAST_NOTIFIED_UPDATE_VERSION, remoteVersion);
6359
}
6460
}
6561

@@ -106,14 +102,21 @@ private Version fetchRemoteArtifactVersion(String repositoryUrl) {
106102

107103
private void showNotification() {
108104
Display.getDefault().asyncExec(() -> {
109-
AbstractNotificationPopup notification = new ToolkitNotification(Display.getCurrent(),
105+
AbstractNotificationPopup notification = new PersistentToolkitNotification(Display.getCurrent(),
110106
Constants.PLUGIN_UPDATE_NOTIFICATION_TITLE,
111-
Constants.PLUGIN_UPDATE_NOTIFICATION_BODY);
107+
String.format(Constants.PLUGIN_UPDATE_NOTIFICATION_BODY, remoteVersion.toString()),
108+
(selected) -> {
109+
if (selected) {
110+
Activator.getPluginStore().putObject(Constants.DO_NOT_SHOW_UPDATE_KEY, remoteVersion);
111+
} else {
112+
Activator.getPluginStore().remove(Constants.DO_NOT_SHOW_UPDATE_KEY);
113+
}
114+
});
112115
notification.open();
113116
});
114117
}
115118

116119
private static boolean remoteVersionIsGreater(Version remote, Version local) {
117-
return (remote != null) && (local != null) && (remote.compareTo(local) > 0);
120+
return remote.compareTo(local) > 0;
118121
}
119122
}

0 commit comments

Comments
 (0)