From fa406a643f0cce51424a750d119bdc45d055e865 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 10 Jun 2024 15:51:50 +0200 Subject: [PATCH] [platform] adding the "reset settings" option to the startup error dialog (IJPL-358) GitOrigin-RevId: 1fbe38fdb7f0e9ea56703a8ddb7c7e8eb7b43bc8 --- .../openapi/application/ConfigBackup.kt | 3 ++- .../ide/bootstrap/StartupErrorReporter.java | 25 +++++++++++++++++-- .../messages/BootstrapBundle.properties | 5 ++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/ConfigBackup.kt b/platform/platform-impl/src/com/intellij/openapi/application/ConfigBackup.kt index 91465a8c22f6..dbdcb115c392 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/ConfigBackup.kt +++ b/platform/platform-impl/src/com/intellij/openapi/application/ConfigBackup.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.application import com.intellij.openapi.diagnostic.logger @@ -81,6 +81,7 @@ class ConfigBackup(private val configDir: Path) { private val LOG = logger() private const val DATE_FORMAT = "yyyy-MM-dd-HH-mm" + @JvmOverloads fun getNextBackupPath(configDir: Path, currentDate: LocalDateTime = LocalDateTime.now()): Path { val format = DateTimeFormatter.ofPattern(DATE_FORMAT) val date = currentDate.format(format) 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 4939e3a0617d..9d89437fc039 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 @@ -12,6 +12,9 @@ import com.intellij.ide.plugins.StartupAbortedException; import com.intellij.idea.AppExitCodes; import com.intellij.idea.AppMode; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ConfigBackup; +import com.intellij.openapi.application.CustomConfigMigrationOption; +import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.ControlFlowException; @@ -124,11 +127,17 @@ public final class StartupErrorReporter { catch (Throwable ignore) { } try { - var options = new String[]{BootstrapBundle.message("bootstrap.error.option.close"), BootstrapBundle.message("bootstrap.error.option.support"), BootstrapBundle.message("bootstrap.error.option.report")}; + var options = new String[]{ + BootstrapBundle.message("bootstrap.error.option.close"), + BootstrapBundle.message("bootstrap.error.option.reset"), + BootstrapBundle.message("bootstrap.error.option.report"), + BootstrapBundle.message("bootstrap.error.option.support") + }; var choice = JOptionPane.showOptionDialog(JOptionPane.getRootFrame(), prepareMessage(message), title, JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); switch (choice) { - case 1 -> supportCenter(); + case 1 -> cleanStart(); case 2 -> reportProblem(title, message); + case 3 -> supportCenter(); } } catch (Throwable t) { @@ -160,6 +169,18 @@ public final class StartupErrorReporter { } } + private static void cleanStart() { + try { + var backupPath = ConfigBackup.Companion.getNextBackupPath(PathManager.getConfigDir()); + CustomConfigMigrationOption.StartWithCleanConfig.INSTANCE.writeConfigMarkerFile(); + var message = BootstrapBundle.message("bootstrap.error.message.reset", backupPath); + JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), message, BootstrapBundle.message("bootstrap.error.title.reset"), JOptionPane.INFORMATION_MESSAGE); + } + catch (Throwable t) { + var message = BootstrapBundle.message("bootstrap.error.message.reset.failed", t); + JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), message, BootstrapBundle.message("bootstrap.error.title.reset"), JOptionPane.ERROR_MESSAGE); } + } + private static void showBrowserError(Throwable t) { var message = prepareMessage(BootstrapBundle.message("bootstrap.error.message.browser", t)); JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), message, BootstrapBundle.message("bootstrap.error.title.browser"), JOptionPane.ERROR_MESSAGE); diff --git a/platform/service-container/resources/messages/BootstrapBundle.properties b/platform/service-container/resources/messages/BootstrapBundle.properties index f5c7724b93d4..2a828558c1b2 100644 --- a/platform/service-container/resources/messages/BootstrapBundle.properties +++ b/platform/service-container/resources/messages/BootstrapBundle.properties @@ -11,10 +11,15 @@ bootstrap.error.appendix.graphics=Also, a UI exception occurred in an attempt to bootstrap.error.option.close=Close bootstrap.error.option.support=Learn More bootstrap.error.option.report=Report Problem +bootstrap.error.option.reset=Reset Settings bootstrap.error.title.browser=Cannot Open Browser bootstrap.error.message.browser=Cannot launch the default browser.\n\nThe cause: {0} +bootstrap.error.title.reset=Reset Settings +bootstrap.error.message.reset=On a next start, current settings will be backed up to the following directory:\n{0} +bootstrap.error.message.reset.failed=Cannot write the reset marker file.\n\nThe cause: {0} + bootstrap.error.message.no.graphics=Unable to detect graphics environment. bootstrap.error.essential.plugins=Missing essential {0,choice,1#plugin|2#plugins}:\n\n{1}Please reinstall the IDE.