From 60213ad9a16612cfd0b30e6d0b90fd338392d091 Mon Sep 17 00:00:00 2001 From: Nikita Iarychenko Date: Wed, 21 May 2025 10:52:18 +0400 Subject: [PATCH] OPENIDE #180 Buttons in Internal Error dialog don't work when OpenIDE starts (cherry picked from commit f4b6817513da096f6563af79462ebe5af555f717) (cherry picked from commit f3a04446870f01a424d1d2c58ecfb15e73e89ed9) --- .../ide/bootstrap/StartupErrorReporter.java | 92 ++++++++++--------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/StartupErrorReporter.java b/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/StartupErrorReporter.java index eb5a304f0b73..ddcfe80f58a2 100644 --- a/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/StartupErrorReporter.java +++ b/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/StartupErrorReporter.java @@ -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; @@ -43,6 +48,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; @@ -148,21 +154,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) { @@ -172,6 +190,17 @@ public final class StartupErrorReporter { } } + private static JButton createTextBtn(String text, Consumer 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"); @@ -183,41 +212,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) { @@ -247,13 +252,14 @@ public final class StartupErrorReporter { var worker = new SwingWorker() { @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