Skip to content

Commit

Permalink
addition of do not show again option to prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Borges committed Jan 9, 2025
1 parent 5120dd3 commit 9d3aca5
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ private Constants() {
public static final String LSP_OPT_OUT_TELEMETRY_CONFIGURATION_KEY = "optOutTelemetry";
public static final String LSP_Q_CONFIGURATION_KEY = "aws.q";
public static final String LSP_CW_CONFIGURATION_KEY = "aws.codeWhisperer";
public static final String LAST_NOTIFIED_UPDATE_VERSION = "lastShownNotificationVersion";
public static final String DO_NOT_SHOW_UPDATE_KEY = "doNotShowUpdate";
public static final String PLUGIN_UPDATE_NOTIFICATION_TITLE = "Amazon Q Update Available";
public static final String PLUGIN_UPDATE_NOTIFICATION_BODY = "A new version of the Amazon Q plugin is available. Please update for newest features.";
public static final String PLUGIN_UPDATE_NOTIFICATION_BODY = "Amazon Q plugin version %s is available. Please update for newest features.";
public static final String LSP_CW_OPT_OUT_KEY = "shareCodeWhispererContentWithAWS";
public static final String LSP_CODE_REFERENCES_OPT_OUT_KEY = "includeSuggestionsWithCodeReferences";
public static final String IDE_CUSTOMIZATION_NOTIFICATION_TITLE = "Amazon Q Customization";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.util;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

import java.util.function.Consumer;
import org.eclipse.swt.SWT;

public final class PersistentToolkitNotification extends ToolkitNotification {
private final Consumer<Boolean> checkboxCallback;

public PersistentToolkitNotification(Display display, String title, String description, Consumer<Boolean> checkboxCallback) {
super(display, title, description);
this.checkboxCallback = checkboxCallback;
}

@Override
protected void createContentArea(final Composite parent) {
super.createContentArea(parent);

Composite container = (Composite) parent.getChildren()[0];

// create checkbox
Button doNotShowCheckbox = new Button(container, SWT.CHECK);
GridData checkboxGridData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
doNotShowCheckbox.setLayoutData(checkboxGridData);

// create checkbox button text
Label checkboxLabel = new Label(container, SWT.NONE);
checkboxLabel.setText("Don't show this message again");
checkboxLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

// style button text
Color grayColor = new Color(parent.getDisplay(), 128, 128, 128);
checkboxLabel.setForeground(grayColor);

Font originalFont = checkboxLabel.getFont();
FontData[] fontData = originalFont.getFontData();
for (FontData fd : fontData) {
fd.setHeight(fd.getHeight() - 1);
}
Font smallerFont = new Font(parent.getDisplay(), fontData);
checkboxLabel.setFont(smallerFont);

checkboxLabel.addDisposeListener(e -> {
smallerFont.dispose();
grayColor.dispose();
});

// make button text clickable
checkboxLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
doNotShowCheckbox.setSelection(!doNotShowCheckbox.getSelection());
if (checkboxCallback != null) {
checkboxCallback.accept(doNotShowCheckbox.getSelection());
}
}
});

doNotShowCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (checkboxCallback != null) {
checkboxCallback.accept(doNotShowCheckbox.getSelection());
}
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.mylyn.commons.ui.dialogs.AbstractNotificationPopup;

public final class ToolkitNotification extends AbstractNotificationPopup {
public class ToolkitNotification extends AbstractNotificationPopup {

private final String title;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static UpdateUtils getInstance() {
}

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

public void checkForUpdate() {
if (newUpdateAvailable()) {
//notify user
showNotification();

//update storage with notification version
Activator.getPluginStore().putObject(Constants.LAST_NOTIFIED_UPDATE_VERSION, remoteVersion);
}
}

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

private void showNotification() {
Display.getDefault().asyncExec(() -> {
AbstractNotificationPopup notification = new ToolkitNotification(Display.getCurrent(),
AbstractNotificationPopup notification = new PersistentToolkitNotification(Display.getCurrent(),
Constants.PLUGIN_UPDATE_NOTIFICATION_TITLE,
Constants.PLUGIN_UPDATE_NOTIFICATION_BODY);
String.format(Constants.PLUGIN_UPDATE_NOTIFICATION_BODY, remoteVersion.toString()),
(selected) -> {
if (selected) {
Activator.getPluginStore().putObject(Constants.DO_NOT_SHOW_UPDATE_KEY, remoteVersion);
} else {
Activator.getPluginStore().remove(Constants.DO_NOT_SHOW_UPDATE_KEY);
}
});
notification.open();
});
}

private static boolean remoteVersionIsGreater(Version remote, Version local) {
return (remote != null) && (local != null) && (remote.compareTo(local) > 0);
return remote.compareTo(local) > 0;
}
}

0 comments on commit 9d3aca5

Please sign in to comment.