mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-15 06:45:42 -04:00
feat: progress bar indicating Microsoft login page loading progress
This commit is contained in:
parent
f2a86857bc
commit
94539ad77b
@ -33,9 +33,7 @@ import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.net.URISyntaxException;
|
import java.net.*;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -47,11 +45,14 @@ import static org.jackhuang.hmcl.util.Logging.LOG;
|
|||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
|
|
||||||
public final class Launcher extends Application {
|
public final class Launcher extends Application {
|
||||||
|
public static final CookieManager COOKIE_MANAGER = new CookieManager();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
Thread.currentThread().setUncaughtExceptionHandler(CRASH_REPORTER);
|
Thread.currentThread().setUncaughtExceptionHandler(CRASH_REPORTER);
|
||||||
|
|
||||||
|
CookieHandler.setDefault(COOKIE_MANAGER);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
ConfigHolder.init();
|
ConfigHolder.init();
|
||||||
|
@ -17,7 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.ui;
|
package org.jackhuang.hmcl.ui;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXProgressBar;
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.web.WebEngine;
|
import javafx.scene.web.WebEngine;
|
||||||
import javafx.scene.web.WebView;
|
import javafx.scene.web.WebView;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
@ -26,6 +30,8 @@ import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
|||||||
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
|
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
|
||||||
|
|
||||||
public class WebStage extends Stage {
|
public class WebStage extends Stage {
|
||||||
|
protected final StackPane pane = new StackPane();
|
||||||
|
protected final JFXProgressBar progressBar = new JFXProgressBar();
|
||||||
protected final WebView webView = new WebView();
|
protected final WebView webView = new WebView();
|
||||||
protected final WebEngine webEngine = webView.getEngine();
|
protected final WebEngine webEngine = webView.getEngine();
|
||||||
|
|
||||||
@ -34,10 +40,28 @@ public class WebStage extends Stage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WebStage(int width, int height) {
|
public WebStage(int width, int height) {
|
||||||
setScene(new Scene(webView, width, height));
|
setScene(new Scene(pane, width, height));
|
||||||
getScene().getStylesheets().addAll(config().getTheme().getStylesheets());
|
getScene().getStylesheets().addAll(config().getTheme().getStylesheets());
|
||||||
getIcons().add(newImage("/assets/img/icon.png"));
|
getIcons().add(newImage("/assets/img/icon.png"));
|
||||||
webView.setContextMenuEnabled(false);
|
webView.setContextMenuEnabled(false);
|
||||||
|
progressBar.progressProperty().bind(webView.getEngine().getLoadWorker().progressProperty());
|
||||||
|
|
||||||
|
progressBar.visibleProperty().bind(Bindings.createBooleanBinding(() -> {
|
||||||
|
switch (webView.getEngine().getLoadWorker().getState()) {
|
||||||
|
case SUCCEEDED:
|
||||||
|
case FAILED:
|
||||||
|
case CANCELLED:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}, webEngine.getLoadWorker().stateProperty()));
|
||||||
|
|
||||||
|
BorderPane borderPane = new BorderPane();
|
||||||
|
borderPane.setPickOnBounds(false);
|
||||||
|
borderPane.setTop(progressBar);
|
||||||
|
progressBar.prefWidthProperty().bind(borderPane.widthProperty());
|
||||||
|
pane.getChildren().setAll(webView, borderPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebView getWebView() {
|
public WebView getWebView() {
|
||||||
|
@ -25,6 +25,8 @@ import org.jackhuang.hmcl.ui.WebStage;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import static org.jackhuang.hmcl.Launcher.COOKIE_MANAGER;
|
||||||
|
|
||||||
public class MicrosoftAccountLoginStage extends WebStage implements MicrosoftService.WebViewCallback {
|
public class MicrosoftAccountLoginStage extends WebStage implements MicrosoftService.WebViewCallback {
|
||||||
public static final MicrosoftAccountLoginStage INSTANCE = new MicrosoftAccountLoginStage();
|
public static final MicrosoftAccountLoginStage INSTANCE = new MicrosoftAccountLoginStage();
|
||||||
|
|
||||||
@ -58,6 +60,8 @@ public class MicrosoftAccountLoginStage extends WebStage implements MicrosoftSer
|
|||||||
@Override
|
@Override
|
||||||
public CompletableFuture<String> show(MicrosoftService service, Predicate<String> urlTester, String initialURL) {
|
public CompletableFuture<String> show(MicrosoftService service, Predicate<String> urlTester, String initialURL) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
|
COOKIE_MANAGER.getCookieStore().removeAll();
|
||||||
|
|
||||||
webEngine.load(initialURL);
|
webEngine.load(initialURL);
|
||||||
show();
|
show();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user