Skip to content

Commit

Permalink
fix: updater is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Dec 8, 2023
1 parent 0ca366e commit f66045a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
22 changes: 21 additions & 1 deletion src/main/java/viewtify/Viewtify.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

import com.sun.javafx.application.PlatformImpl;
Expand Down Expand Up @@ -433,6 +434,18 @@ public Viewtify title(String title) {
return this;
}

/**
* Configure application title.
*
* @return A title of this application.
*/
public Viewtify title(UnaryOperator<String> title) {
if (title != null) {
this.title = title.apply(this.title);
}
return this;
}

/**
* Configure application update strategy.
*
Expand Down Expand Up @@ -519,6 +532,11 @@ private void activate(View application, boolean isOperner) {
scene.setFill(null);
mainStage.setOnHidden(e -> {
if (!Terminator.isDisposed()) {
SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null && splash.isVisible()) {
splash.close();
}

opener = null;
activate(application, false);
}
Expand Down Expand Up @@ -832,7 +850,9 @@ public final static void inUI(Runnable process) {
* @param process
*/
public final static void inUI(Supplier<Disposable> process) {
inUI(() -> Terminator.add(process.get()));
inUI(() -> {
Terminator.add(process.get());
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/viewtify/update/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static String validate(String archive) {
// ====================================
Blueprint origin = Blueprint.detect();
if (!file.isAfter(origin.root)) {
return "The latest version is used, no need to update.";
// return "The latest version is used, no need to update.";
}

// We can update
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/viewtify/update/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
*/
package viewtify.update;

import javafx.scene.control.ButtonBar.ButtonData;
import javafx.stage.WindowEvent;

import kiss.I;
import kiss.Variable;
import psychopath.Progress;
Expand All @@ -21,7 +19,6 @@
import viewtify.ViewtyDialog.DialogView;
import viewtify.task.Monitor;
import viewtify.task.MonitorableTask;
import viewtify.ui.UIButton;
import viewtify.ui.UILabel;
import viewtify.ui.UIProgressBar;
import viewtify.ui.ViewDSL;
Expand Down Expand Up @@ -95,13 +92,10 @@ protected void initialize() {
stage.setOnCloseRequest(WindowEvent::consume);
});

UIButton ok = find(ButtonData.OK_DONE);

if (ok != null) ok.disableNow();
value = task != null ? task : MonitorableTask.restore(System.getenv(Updater.class.getName()));

Variable<String> mes = Variable.of("");
mes.observe().switchVariable(x -> I.translate(x)).on(Viewtify.UIThread).to(x -> message.text(x));
mes.observe().switchVariable(I::translate).on(Viewtify.UIThread).to(x -> message.text(x));

Variable<Double> per = Variable.of(0d);
per.observe().on(Viewtify.UIThread).to(x -> {
Expand All @@ -122,11 +116,6 @@ protected void initialize() {
percentage.text("");
detail.text("");
bar.value(1d);

if (ok != null) {
ok.enableNow();
if (forcibly) ok.fire();
}
});
} catch (Throwable e) {
mes.set(e.getMessage());
Expand Down

0 comments on commit f66045a

Please sign in to comment.