[platform] adding the "reset settings" option to the startup error dialog (IJPL-358)

GitOrigin-RevId: 1fbe38fdb7f0e9ea56703a8ddb7c7e8eb7b43bc8
This commit is contained in:
Roman Shevchenko
2024-06-10 15:51:50 +02:00
committed by intellij-monorepo-bot
parent 6a3daddf48
commit fa406a643f
3 changed files with 30 additions and 3 deletions

View File

@@ -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<ConfigBackup>()
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)

View File

@@ -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);

View File

@@ -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.