Ticket #23437: 23437.patch

File 23437.patch, 2.3 KB (added by taylor.smock, 2 years ago)
  • src/org/openstreetmap/josm/gui/MainApplication.java

    Subject: [PATCH] #23437: Detect immediate exits after loading plugins
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/gui/MainApplication.java b/src/org/openstreetmap/josm/gui/MainApplication.java
    a b  
    5454import javax.swing.Action;
    5555import javax.swing.InputMap;
    5656import javax.swing.JComponent;
     57import javax.swing.JDialog;
    5758import javax.swing.JLabel;
    5859import javax.swing.JOptionPane;
    5960import javax.swing.JPanel;
     
    183184     * Command-line arguments used to run the application.
    184185     */
    185186    private static volatile List<String> commandLineArgs;
     187    /**
     188     * The preference key for the startup failure counter
     189     */
     190    private static final String PREF_STARTUP_FAILURE_COUNTER = "josm.startup.failure.count";
    186191
    187192    /**
    188193     * The main menu bar at top of screen.
     
    873878
    874879        checkIPv6();
    875880
     881        // After IPv6 check since that may restart JOSM, must be after Preferences.main().init()
     882        final int failures = prefs.getInt(PREF_STARTUP_FAILURE_COUNTER, 0);
     883        // Always increment failures
     884        prefs.putInt(PREF_STARTUP_FAILURE_COUNTER, failures + 1);
     885        if (failures > 3) {
     886            final int selection = JOptionPane.showOptionDialog(new JDialog(),
     887                    tr("JOSM has failed to start up {0} times. Reset JOSM?", failures),
     888                    tr("Reset JOSM?"),
     889                    JOptionPane.YES_NO_OPTION,
     890                    JOptionPane.ERROR_MESSAGE,
     891                    null,
     892                    null,
     893                    null);
     894            if (selection == 0) {
     895                Preferences.main().init(true);
     896            }
     897        }
     898
    876899        processOffline(args);
    877900
    878901        PlatformManager.getPlatform().afterPrefStartupHook();
     
    10051028                splash.dispose();
    10061029            }
    10071030            mainFrame.setVisible(true);
     1031            Config.getPref().put(PREF_STARTUP_FAILURE_COUNTER, null);
    10081032        });
    10091033
    10101034        boolean maximized = Config.getPref().getBoolean("gui.maximized", false);