mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
OPENIDE #180 Buttons in Internal Error dialog don't work when OpenIDE starts
(cherry picked from commit f4b6817513)
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
//
|
||||
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
|
||||
// Any modifications are available on the same license terms as the original source code.
|
||||
package com.intellij.platform.ide.bootstrap;
|
||||
|
||||
import com.intellij.diagnostic.ImplementationConflictException;
|
||||
import com.intellij.diagnostic.LoadingState;
|
||||
import com.intellij.diagnostic.PluginException;
|
||||
import com.intellij.ide.BootstrapBundle;
|
||||
import com.intellij.ide.actions.RevealFileAction;
|
||||
import com.intellij.ide.actions.ShowLogAction;
|
||||
import com.intellij.ide.logsUploader.LogUploader;
|
||||
import com.intellij.ide.plugins.EssentialPluginMissingException;
|
||||
import com.intellij.ide.plugins.PluginConflictReporter;
|
||||
@@ -41,6 +46,7 @@ import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static java.util.Objects.requireNonNullElse;
|
||||
import static org.jetbrains.annotations.Nls.Capitalization.Sentence;
|
||||
@@ -146,21 +152,33 @@ public final class StartupErrorReporter {
|
||||
supportCenter();
|
||||
}
|
||||
});
|
||||
if (error != null) {
|
||||
var options = new Object[]{close, BootstrapBundle.message("bootstrap.error.option.reset"), BootstrapBundle.message("bootstrap.error.option.report"), learnMore};
|
||||
var choice = JOptionPane.showOptionDialog(
|
||||
JOptionPane.getRootFrame(), messageObj, title, JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]
|
||||
);
|
||||
switch (choice) {
|
||||
case 1 -> cleanStart();
|
||||
case 2 -> reportProblem(title, message, error);
|
||||
|
||||
var closeBtn = createTextBtn(BootstrapBundle.message("bootstrap.error.option.close"), e -> {
|
||||
Component component = SwingUtilities.getRoot((Component) e.getSource());
|
||||
if (component instanceof JDialog) {
|
||||
((JDialog) component).dispose();
|
||||
}
|
||||
});
|
||||
|
||||
if (error != null) {
|
||||
var resetBtn = createTextBtn(BootstrapBundle.message("bootstrap.error.option.reset"), e -> cleanStart());
|
||||
var showLogBtn = createTextBtn(ShowLogAction.getActionName(), e -> reportProblem(title, message, error));
|
||||
|
||||
var options = new Object[]{
|
||||
closeBtn,
|
||||
resetBtn,
|
||||
showLogBtn,
|
||||
learnMore
|
||||
};
|
||||
JOptionPane.showOptionDialog(JOptionPane.getRootFrame(), messageObj, title, JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
|
||||
}
|
||||
else {
|
||||
var options = new Object[]{close, learnMore};
|
||||
JOptionPane.showOptionDialog(
|
||||
JOptionPane.getRootFrame(), messageObj, title, JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]
|
||||
);
|
||||
var options = new Object[]{
|
||||
closeBtn,
|
||||
learnMore
|
||||
};
|
||||
JOptionPane.showOptionDialog(JOptionPane.getRootFrame(), messageObj, title, JOptionPane.DEFAULT_OPTION,
|
||||
JOptionPane.ERROR_MESSAGE, null, options, options[0]);
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
@@ -170,6 +188,17 @@ public final class StartupErrorReporter {
|
||||
}
|
||||
}
|
||||
|
||||
private static JButton createTextBtn(String text, Consumer<MouseEvent> onClick) {
|
||||
var button = new JButton(text);
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
onClick.accept(e);
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
private static void supportCenter() {
|
||||
try {
|
||||
var url = System.getProperty(SUPPORT_URL_PROPERTY, "https://jb.gg/ide/critical-startup-errors");
|
||||
@@ -181,41 +210,17 @@ public final class StartupErrorReporter {
|
||||
}
|
||||
|
||||
private static void reportProblem(String title, String description, @Nullable Throwable error) {
|
||||
if (error != null) {
|
||||
title += " (" + error.getClass().getSimpleName() + ": " + shorten(error.getMessage()) + ')';
|
||||
}
|
||||
|
||||
var uploadId = (String)null;
|
||||
if (error instanceof ExceptionWithAttachments ewa) {
|
||||
var message = prepareMessage(BootstrapBundle.message("bootstrap.error.message.confirm"));
|
||||
var ok = JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(), message, BootstrapBundle.message("bootstrap.error.option.report"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
|
||||
if (ok != JOptionPane.OK_OPTION) return;
|
||||
|
||||
try {
|
||||
uploadId = uploadLogs(ewa);
|
||||
uploadLogs(ewa);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
var buf = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(buf));
|
||||
message = prepareMessage(BootstrapBundle.message("bootstrap.error.message.no.logs", buf));
|
||||
var message = prepareMessage(BootstrapBundle.message("bootstrap.error.message.no.logs", buf));
|
||||
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), message, BootstrapBundle.message("bootstrap.error.title.no.logs"), JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (uploadId != null) {
|
||||
description += "\n\n-----\n[Upload ID: " + uploadId + ']';
|
||||
}
|
||||
|
||||
try {
|
||||
var url = System.getProperty(REPORT_URL_PROPERTY, "https://youtrack.jetbrains.com/newissue?project=IJPL&clearDraft=true&summary=$TITLE$&description=$DESCR$&c=$SUBSYSTEM$")
|
||||
.replace("$TITLE$", URLUtil.encodeURIComponent(title))
|
||||
.replace("$DESCR$", URLUtil.encodeURIComponent(description))
|
||||
.replace("$SUBSYSTEM$", URLUtil.encodeURIComponent("Subsystem: IDE. Startup"));
|
||||
Desktop.getDesktop().browse(new URI(url));
|
||||
}
|
||||
catch (Throwable t) {
|
||||
showBrowserError(t);
|
||||
}
|
||||
}
|
||||
|
||||
private static String shorten(String message) {
|
||||
@@ -245,13 +250,14 @@ public final class StartupErrorReporter {
|
||||
var worker = new SwingWorker<String, Void>() {
|
||||
@Override
|
||||
protected String doInBackground() throws Exception {
|
||||
var logs = collectLogs(error);
|
||||
try {
|
||||
return LogUploader.uploadFile(logs);
|
||||
var path = collectLogs(error);
|
||||
if (RevealFileAction.isSupported()) {
|
||||
RevealFileAction.openFile(path);
|
||||
}
|
||||
finally {
|
||||
NioFiles.deleteQuietly(logs);
|
||||
else {
|
||||
RevealFileAction.openDirectory(path);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user