Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/main/java/com/laker/postman/common/window/SplashWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,18 @@ protected void process(java.util.List<String> chunks) {

@Override
protected void done() {
SwingUtilities.invokeLater(() -> {
try {
if (isDisposed) return;
try {
if (isDisposed) return;

setStatus(MessageKeys.SPLASH_STATUS_DONE);
MainFrame mainFrame = get();
setStatus(MessageKeys.SPLASH_STATUS_DONE);
MainFrame mainFrame = get();

// 启动渐隐动画关闭 SplashWindow
startFadeOutAnimation(mainFrame);
// 启动渐隐动画关闭 SplashWindow
startFadeOutAnimation(mainFrame);

} catch (Exception e) {
handleMainFrameLoadError(e);
}
});
} catch (Exception e) {
handleMainFrameLoadError(e);
}
}
};
worker.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class RequestEditSubPanel extends JPanel {
private final JTabbedPane reqTabs; // 请求选项卡面板

// 当前请求的 SwingWorker,用于支持取消
private transient SwingWorker<Void, Void> currentWorker;
private transient SwingWorker<Void, Runnable> currentWorker;
// 当前 SSE 事件源, 用于取消 SSE 请求
private transient EventSource currentEventSource;
// WebSocket连接对象
Expand Down Expand Up @@ -339,10 +339,19 @@ private void handleHttpRequest(HttpRequestItem item, PreparedRequest req, Map<St
String statusText;
HttpResponse resp;

@Override
protected void process(List<Runnable> runnables) {
for(Runnable runnable: runnables) {
runnable.run();
}
}

@Override
protected Void doInBackground() {
try {
responsePanel.setResponseTabButtonsEnable(true);
publish(() -> {
responsePanel.setResponseTabButtonsEnable(true);
});
resp = RedirectHandler.executeWithRedirects(req, 10);
if (resp != null) {
statusText = (resp.code > 0 ? String.valueOf(resp.code) : "Unknown Status");
Expand All @@ -368,7 +377,7 @@ protected void done() {
// 只有当前协议是 HTTP 且响应是 SSE 类型时,才提示切换到 SSE 协议
if (resp != null && resp.isSse && protocol == RequestItemProtocolEnum.HTTP) {
// 弹窗提示用户是否切换到SSE监听模式
SwingUtilities.invokeLater(() -> SingletonFactory.getInstance(RequestEditPanel.class).switchCurrentTabToSseProtocol());
SingletonFactory.getInstance(RequestEditPanel.class).switchCurrentTabToSseProtocol();
}
}
};
Expand All @@ -382,6 +391,13 @@ private void handleSseRequest(HttpRequestItem item, PreparedRequest req, Map<Str
StringBuilder sseBodyBuilder;
long startTime;

@Override
protected void process(List<Runnable> runnables) {
for(Runnable runnable: runnables) {
runnable.run();
}
}

@Override
protected Void doInBackground() {
try {
Expand All @@ -391,7 +407,7 @@ protected Void doInBackground() {
SseUiCallback callback = new SseUiCallback() {
@Override
public void onOpen(HttpResponse r, String headersText) {
SwingUtilities.invokeLater(() -> {
publish(() -> {
updateUIForResponse(String.valueOf(r.code), r);
// 添加连接成功消息
if (responsePanel.getSseResponsePanel() != null) {
Expand All @@ -403,7 +419,7 @@ public void onOpen(HttpResponse r, String headersText) {

@Override
public void onEvent(String id, String type, String data) {
SwingUtilities.invokeLater(() -> {
publish(() -> {
// 使用 SSEResponsePanel 来显示 SSE 消息
if (responsePanel.getSseResponsePanel() != null) {
String timestamp = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
Expand All @@ -415,7 +431,7 @@ public void onEvent(String id, String type, String data) {

@Override
public void onClosed(HttpResponse r) {
SwingUtilities.invokeLater(() -> {
publish(() -> {
updateUIForResponse(String.valueOf(r.code), r);
requestLinePanel.setSendButtonToSend(RequestEditSubPanel.this::sendRequest);
// 添加连接关闭消息
Expand All @@ -430,7 +446,7 @@ public void onClosed(HttpResponse r) {

@Override
public void onFailure(String errorMsg, HttpResponse r) {
SwingUtilities.invokeLater(() -> {
publish(() -> {
responsePanel.getStatusCodeLabel().setText(I18nUtil.getMessage(MessageKeys.SSE_FAILED, errorMsg));
responsePanel.getStatusCodeLabel().setForeground(Color.RED);
updateUIForResponse(I18nUtil.getMessage(MessageKeys.SSE_FAILED, errorMsg), r);
Expand All @@ -446,10 +462,12 @@ public void onFailure(String errorMsg, HttpResponse r) {
}
};
currentEventSource = HttpSingleRequestExecutor.executeSSE(req, new SseEventListener(callback, resp, sseBodyBuilder, startTime));
responsePanel.setResponseTabButtonsEnable(true); // 启用响应区的tab按钮
publish(() -> {
responsePanel.setResponseTabButtonsEnable(true); // 启用响应区的tab按钮
});
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
SwingUtilities.invokeLater(() -> {
publish(() -> {
responsePanel.getStatusCodeLabel().setText(I18nUtil.getMessage(MessageKeys.SSE_ERROR, ex.getMessage()));
responsePanel.getStatusCodeLabel().setForeground(Color.RED);
});
Expand Down Expand Up @@ -478,6 +496,13 @@ private void handleWebSocketRequest(HttpRequestItem item, PreparedRequest req, M
long startTime;
volatile boolean closed = false;

@Override
protected void process(List<Runnable> runnables) {
for(Runnable runnable: runnables) {
runnable.run();
}
}

@Override
protected Void doInBackground() {
try {
Expand All @@ -504,7 +529,7 @@ public void onOpen(WebSocket webSocket, Response response) {
resp.code = response.code();
resp.protocol = response.protocol().toString();
currentWebSocket = webSocket;
SwingUtilities.invokeLater(() -> {
publish(() -> {
updateUIForResponse(String.valueOf(resp.code), resp);
reqTabs.setSelectedComponent(requestBodyPanel);
requestBodyPanel.getWsSendButton().requestFocusInWindow();
Expand Down Expand Up @@ -558,7 +583,7 @@ private void handleWebSocketClose() {
closed = true;
resp.costMs = System.currentTimeMillis() - startTime;
currentWebSocket = null;
SwingUtilities.invokeLater(() -> {
publish(() -> {
updateUIForResponse("closed", resp);
requestLinePanel.setSendButtonToSend(RequestEditSubPanel.this::sendRequest);
// 断开后禁用发送和定时按钮
Expand All @@ -577,7 +602,7 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
appendWebSocketMessage(MessageType.WARNING, t.getMessage());
closed = true;
resp.costMs = System.currentTimeMillis() - startTime;
SwingUtilities.invokeLater(() -> {
publish(() -> {
String statusMsg = response != null ? I18nUtil.getMessage(MessageKeys.WEBSOCKET_FAILED, t.getMessage() + " (" + response.code() + ")")
: I18nUtil.getMessage(MessageKeys.WEBSOCKET_FAILED, t.getMessage());
responsePanel.getStatusCodeLabel().setText(statusMsg);
Expand All @@ -592,7 +617,7 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
responsePanel.setResponseTabButtonsEnable(true); // 启用响应区的tab按钮
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
SwingUtilities.invokeLater(() -> {
publish(() -> {
responsePanel.getStatusCodeLabel().setText(I18nUtil.getMessage(MessageKeys.WEBSOCKET_ERROR, ex.getMessage()));
responsePanel.getStatusCodeLabel().setForeground(Color.RED);
// 失败后禁用发送和定时按钮
Expand Down