Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Dec 7, 2023
1 parent cec85e7 commit 04860cf
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions src/main/java/viewtify/Viewtify.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import com.sun.javafx.application.PlatformImpl;

import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.binding.DoubleExpression;
Expand Down Expand Up @@ -65,9 +67,6 @@
import javafx.stage.StageStyle;
import javafx.stage.Window;
import javafx.stage.WindowEvent;

import com.sun.javafx.application.PlatformImpl;

import kiss.Decoder;
import kiss.Disposable;
import kiss.Encoder;
Expand Down Expand Up @@ -524,39 +523,25 @@ public void activate(View application) {
PlatformImpl.startup(() -> {
toolkitInitialized = true;

if (opener == null) {
activateApplication(application);
} else {
View o = I.make(opener);
Stage stage = new Stage();
stage.initStyle(StageStyle.TRANSPARENT);
Scene scene = new Scene((Parent) o.ui());
scene.setFill(null);
stage.setScene(scene);

manage("opener", scene, stage, false);

inUI(() -> {
stage.setOnHidden(e -> {
if (!Terminator.isDisposed()) {
activateApplication(application);
}
});
stage.show();
});
}

activate(application, opener != null);
}, false);
}

private void activateApplication(View application) {
/**
* Activate the specified application.
*
* @param application The application {@link View} to activate.
*/
private void activate(View application, boolean needOpener) {
boolean canUpdate = I.env("UpdateOnStartup", updateArchive != null);
boolean needUpdate = canUpdate && Update.isValid(updateArchive);

View actual = needUpdate ? new Empty() : application;
mainStage = new Stage(stageStyle);
mainStage.setWidth(width != 0 ? width : Screen.getPrimary().getBounds().getWidth() / 2);
mainStage.setHeight(height != 0 ? height : Screen.getPrimary().getBounds().getHeight() / 2);
View actual = needUpdate ? new Empty() : needOpener ? I.make(opener) : application;
mainStage = new Stage(needOpener ? StageStyle.TRANSPARENT : stageStyle);
if (!needOpener) {
mainStage.setWidth(width != 0 ? width : Screen.getPrimary().getBounds().getWidth() / 2);
mainStage.setHeight(height != 0 ? height : Screen.getPrimary().getBounds().getHeight() / 2);
}
if (needUpdate) mainStage.setOpacity(0);

Scene scene = new Scene((Parent) actual.ui());
Expand All @@ -573,6 +558,15 @@ private void activateApplication(View application) {
}
});

if (needOpener) {
mainStage.setOnHidden(e -> {
if (!Terminator.isDisposed()) {
opener = null;
activate(application, false);
}
});
}

if (closer != null) {
mainStage.setOnCloseRequest(e -> {
if (!closer.getAsBoolean()) {
Expand All @@ -585,8 +579,10 @@ private void activateApplication(View application) {
mainStage.show();

// process the unexecuted UI action
waitingActions.forEach(Runnable::run);
waitingActions = null;
if (waitingActions != null) {
waitingActions.forEach(Runnable::run);
waitingActions = null;
}

if (!isHeadless()) {
// release resources for splash screen
Expand Down

0 comments on commit 04860cf

Please sign in to comment.