-
Notifications
You must be signed in to change notification settings - Fork 929
优化启动器崩溃处理机制 #6825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CiiLu
wants to merge
6
commits into
HMCL-dev:main
Choose a base branch
from
CiiLu:y
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
优化启动器崩溃处理机制 #6825
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,46 +17,80 @@ | |
| */ | ||
| package org.jackhuang.hmcl.ui; | ||
|
|
||
| import javafx.application.Platform; | ||
| import javafx.geometry.Pos; | ||
| import javafx.scene.Scene; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.TextArea; | ||
| import javafx.scene.control.*; | ||
| import javafx.scene.layout.BorderPane; | ||
| import javafx.scene.layout.HBox; | ||
| import javafx.scene.layout.StackPane; | ||
| import javafx.stage.Stage; | ||
| import org.jackhuang.hmcl.Metadata; | ||
| import org.jackhuang.hmcl.countly.CrashReport; | ||
| import org.jackhuang.hmcl.upgrade.UpdateChecker; | ||
| import org.jackhuang.hmcl.util.LauncherLogExporter; | ||
| import org.jackhuang.hmcl.util.Lazy; | ||
| import org.jackhuang.hmcl.util.StringUtils; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
|
|
||
| import static org.jackhuang.hmcl.util.i18n.I18n.i18n; | ||
| import static org.jackhuang.hmcl.util.logging.Logger.LOG; | ||
|
|
||
| /** | ||
| * @author huangyuhui | ||
| */ | ||
| public class CrashWindow extends Stage { | ||
| public final class CrashWindow extends Stage { | ||
| private static final Lazy<CrashWindow> instance = new Lazy<>(CrashWindow::new); | ||
|
|
||
| public static CrashWindow getInstance() { | ||
| return instance.get(); | ||
| } | ||
|
|
||
| public CrashWindow(CrashReport report) { | ||
| private final TextArea textArea = new TextArea(); | ||
|
|
||
| private CrashWindow() { | ||
| Label lblCrash = new Label(); | ||
| if (report.getThrowable() instanceof InternalError) | ||
| lblCrash.setText(i18n("launcher.crash.java_internal_error")); | ||
| else if (UpdateChecker.isOutdated()) | ||
| lblCrash.setWrapText(true); | ||
|
|
||
| if (UpdateChecker.isOutdated()) { | ||
| lblCrash.setText(i18n("launcher.crash.hmcl_out_dated")); | ||
| else | ||
| } else { | ||
| lblCrash.setText(i18n("launcher.crash")); | ||
| lblCrash.setWrapText(true); | ||
| } | ||
|
|
||
| TextArea textArea = new TextArea(); | ||
| textArea.setText(report.getDisplayText()); | ||
| textArea.setEditable(false); | ||
| StackPane exportPane = new StackPane(); | ||
| ProgressIndicator progressIndicator = new ProgressIndicator(); | ||
| FXUtils.setLimitHeight(progressIndicator, 20); | ||
|
|
||
| Button btnExport = new Button(); | ||
| exportPane.getChildren().setAll(btnExport); | ||
| btnExport.setText(i18n("settings.launcher.launcher_log.export")); | ||
| btnExport.setOnAction(event -> { | ||
| exportPane.getChildren().setAll(progressIndicator); | ||
| try { | ||
| Path path = LauncherLogExporter.exportLogsAsZip(); | ||
| FXUtils.showFileInExplorer(path); | ||
| Alert alert = new Alert(Alert.AlertType.INFORMATION, i18n("settings.launcher.launcher_log.export.success", path)); | ||
| alert.setTitle(i18n("settings.launcher.launcher_log.export")); | ||
| alert.showAndWait(); | ||
| } catch (IOException e) { | ||
| LOG.warning("Failed to export launcher logs", e); | ||
| Alert alert = new Alert(Alert.AlertType.WARNING, i18n("settings.launcher.launcher_log.export.failed") + "\n" + StringUtils.getStackTrace(e)); | ||
| alert.setTitle(i18n("message.error")); | ||
| alert.setContentText(StringUtils.getStackTrace(e)); | ||
| alert.showAndWait(); | ||
| } | ||
| exportPane.getChildren().setAll(btnExport); | ||
| }); | ||
|
|
||
| Button btnContact = new Button(); | ||
| btnContact.setText(i18n("launcher.contact")); | ||
| btnContact.setOnAction(event -> FXUtils.openLink(Metadata.CONTACT_URL)); | ||
| HBox box = new HBox(); | ||
| HBox box = new HBox(8); | ||
| box.setStyle("-fx-padding: 8px;"); | ||
| box.getChildren().add(btnContact); | ||
| box.getChildren().setAll(exportPane, btnContact); | ||
| box.setAlignment(Pos.CENTER_RIGHT); | ||
|
|
||
| BorderPane pane = new BorderPane(); | ||
|
|
@@ -72,7 +106,12 @@ else if (UpdateChecker.isOutdated()) | |
| FXUtils.setIcon(this); | ||
| setTitle(i18n("message.error")); | ||
|
|
||
| setOnCloseRequest(e -> javafx.application.Platform.exit()); | ||
| setOnCloseRequest(e -> Platform.exit()); | ||
| } | ||
|
|
||
| public void addCrashReport(CrashReport report) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ERROR] [com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck] 'METHOD_DEF' has more than 1 empty lines before. |
||
| textArea.setText(textArea.getText() + "\n\n" + report.getDisplayText()); | ||
| textArea.setEditable(false); | ||
| this.requestFocus(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When retained logs are large, compressed, or stored on a slow filesystem, this call scans, decompresses, and recompresses up to five files and waits for
Logger.exportLogsdirectly inside the button's JavaFX action handler. The FX pulse therefore cannot render the progress indicator, the crash window remains unresponsive, and subsequent queued crash reports cannot appear until the export finishes. Dispatch the export toSchedulers.io()and return to the JavaFX executor for the dialog and button update, as the settings-page export already does.Useful? React with 👍 / 👎.