Skip to content

Commit

Permalink
Open dialogs on the same screen as Reshaper
Browse files Browse the repository at this point in the history
  • Loading branch information
ddwightx committed Nov 2, 2024
1 parent ad91c04 commit 764f27e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: Java CI with Gradle

on:
push:
branches: [ "release", "post_release" ]
branches: [ "release", "pre_release" ]
pull_request:
branches: [ "release" ]

Expand Down
2 changes: 1 addition & 1 deletion extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

group 'com.synfron.reshaper.burp'
archivesBaseName = 'reshaper-for-burp'
version '2.5.2'
version '2.5.3-pre'

targetCompatibility = '21'
sourceCompatibility = '21'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Component getHeaderBar() {
private void onAddMatchAndReplace(ActionEvent actionEvent) {
try {
MatchAndReplaceWizardModel model = new MatchAndReplaceWizardModel(this.model);
ModalPrompter.open(model, ignored -> MatchAndReplaceWizardOptionPane.showDialog(model), true);
ModalPrompter.open(model, ignored -> MatchAndReplaceWizardOptionPane.showDialog(model, this), true);
} catch (Exception e) {
Log.get(workspace).withMessage("Failed to create rule from content menu").withException(e).logErr();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ private void onPropertyChanged(PropertyChangeEvent event) {
}
}

public static void showDialog(MatchAndReplaceWizardModel model) {
public static void showDialog(MatchAndReplaceWizardModel model, Component relativeComponent) {
MatchAndReplaceWizardOptionPane optionPane = new MatchAndReplaceWizardOptionPane(model);
JDialog dialog = optionPane.createDialog("Match & Replace");
dialog.setResizable(true);

dialog.setLocationRelativeTo(relativeComponent);
dialog.setModal(false);
dialog.setVisible(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,37 @@ public static void showDialog(WhenWizardModel model) {
JDialog dialog = optionPane.createDialog("When");
dialog.setResizable(true);

Point screenCenterLocation = getSceenCenterLocation();
if (screenCenterLocation != null) {
dialog.setLocation(
screenCenterLocation.x - dialog.getPreferredSize().width / 2,
screenCenterLocation.y - dialog.getPreferredSize().height / 2
);
}
dialog.setModal(false);
dialog.setVisible(true);
}

private static Point getSceenCenterLocation() {
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
Point mouseLocation = pointerInfo.getLocation();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens = ge.getScreenDevices();

for (GraphicsDevice screen : screens) {
GraphicsConfiguration gc = screen.getDefaultConfiguration();
Rectangle bounds = gc.getBounds();
if (bounds.contains(mouseLocation)) {
Point location = bounds.getLocation();
return new Point(
location.x + bounds.width / 2,
location.y + bounds.height / 2
);
}
}
return null;
}

private void initComponent() {
bodyScrollPane = getBodyScrollPane();
container.add(bodyScrollPane, BorderLayout.CENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class WorkspaceComponent extends JPanel implements IWorkspaceHost {

public WorkspaceComponent(Workspace workspace) {
this.workspace = workspace;
this.uiMessageHandler = new UiMessageHandler(workspace.getMessageEvent());
this.uiMessageHandler = new UiMessageHandler(workspace.getMessageEvent(), this);
initComponents();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.Collections;
import java.util.List;

Expand All @@ -26,23 +25,23 @@ public class ContextMenuHandler implements ContextMenuItemsProvider {
@Override
public List<Component> provideMenuItems(ContextMenuEvent event) {
JMenuItem menuItem = new JMenuItem("Create Rule");
menuItem.addActionListener(actionEvent -> onCreateHttpRule(event.selectedRequestResponses(), actionEvent));
menuItem.addActionListener(actionEvent -> onCreateHttpRule(event.selectedRequestResponses()));
return event.selectedRequestResponses().size() == 1 ? Collections.singletonList(menuItem) : Collections.emptyList();
}

@Override
public List<Component> provideMenuItems(WebSocketContextMenuEvent event) {
JMenuItem menuItem = new JMenuItem("Create Rule");
menuItem.addActionListener(actionEvent -> onCreateWebSocketRule(event.selectedWebSocketMessages(), actionEvent));
menuItem.addActionListener(actionEvent -> onCreateWebSocketRule(event.selectedWebSocketMessages()));
return event.selectedWebSocketMessages().size() == 1 ? Collections.singletonList(menuItem) : Collections.emptyList();
}

private void onCreateWebSocketRule(List<WebSocketMessage> selectedItems, ActionEvent actionEvent) {
private void onCreateWebSocketRule(List<WebSocketMessage> selectedItems) {
WebSocketMessage webSocketMessage = selectedItems.getFirst();
openWhenWizard(new WhenWizardModel(new WebSocketEventInfo<>(Workspaces.get().getDefault(), WebSocketMessageType.Binary, WebSocketDataDirection.from(webSocketMessage.direction()), null, null, webSocketMessage.upgradeRequest(), webSocketMessage.annotations(), webSocketMessage.payload().getBytes(), new Variables())));
}

private void onCreateHttpRule(List<HttpRequestResponse> selectedItems, ActionEvent actionEvent) {
private void onCreateHttpRule(List<HttpRequestResponse> selectedItems) {
HttpRequestResponse httpRequestResponse = selectedItems.getFirst();
openWhenWizard(new WhenWizardModel(new HttpEventInfo(Workspaces.get().getDefault(), null, null, null, httpRequestResponse.request(), httpRequestResponse.response(), httpRequestResponse.annotations(), new Variables())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void onModelChanged(PropertyChangedArgs propertyChangedArgs) {
}
}

public static void createTextAreaDialog(String id, String title, String description, String text, Consumer<String> valueHandler) {
public static void createTextAreaDialog(String id, String title, String description, String text, Consumer<String> valueHandler, Component relativeComponent) {
JPanel container = new JPanel(new BorderLayout());

JScrollPane scrollPane = new JScrollPane();
Expand All @@ -60,6 +60,7 @@ public static void createTextAreaDialog(String id, String title, String descript

JOptionPane optionPane = new JOptionPane(container, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[]{ "OK", "Cancel" }, "OK");
JDialog dialog = optionPane.createDialog(title);
dialog.setLocationRelativeTo(relativeComponent);
dialog.setResizable(true);
dialogMap.put(id, dialog);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import synfron.reshaper.burp.core.events.MessageEvent;
import synfron.reshaper.burp.core.events.message.PromptRequestMessage;
import synfron.reshaper.burp.core.events.message.PromptResponseMessage;
import synfron.reshaper.burp.ui.components.workspaces.WorkspaceComponent;

public class UiMessageHandler {
private final MessageEvent messageEvent;
private final WorkspaceComponent workspaceComponent;
private final IEventListener<MessageArgs> messageListener = this::onMessage;

public UiMessageHandler(MessageEvent messageEvent) {
public UiMessageHandler(MessageEvent messageEvent, WorkspaceComponent workspaceComponent) {
this.messageEvent = messageEvent;
this.workspaceComponent = workspaceComponent;
messageEvent.add(messageListener);
}

Expand All @@ -27,7 +30,8 @@ private void onMessage(MessageArgs messageArgs) {
value -> messageEvent.invoke(new MessageArgs(this, new PromptResponseMessage(
message.getMessageId(),
value
)))
))),
workspaceComponent
);
}
case PromptCancel -> ModalPrompter.dismiss(messageArgs.getData().getMessageId());
Expand Down

0 comments on commit 764f27e

Please sign in to comment.