Skip to content

Commit

Permalink
Merge branch 'refs/heads/prs-base' into prs
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Nov 17, 2024
2 parents 383aea0 + 5311067 commit 639d5b1
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package net.burningtnt.hmclprs;

import net.burningtnt.hmclprs.hooks.EntryPoint;

import static org.jackhuang.hmcl.util.i18n.I18n.i18n;

final class PRCollectionConstants {
private PRCollectionConstants() {
public final class Constants {
private Constants() {
}

public static final FinalValue<String> DEFAULT_FULL_NAME = new FinalValue<>();

public static final FinalValue<String> DEFAULT_VERSION = new FinalValue<>();

public static final String PR_COLLECTION_SUFFIX = " (PR Collection)";

public static final String HOME_PAGE = "https://github.com/burningtnt/HMCL/pull/9";
Expand All @@ -20,12 +22,10 @@ private PRCollectionConstants() {

public static final boolean SHOULD_DISPLAY_LAUNCH_WARNING = shouldDisplayWarningMessage("hmcl.pr.warning", "HMCL_PR_WARNING");

@EntryPoint(when = EntryPoint.LifeCycle.RUNTIME)
public static String getWarningTitle() {
return i18n("prs.title");
}

@EntryPoint(when = EntryPoint.LifeCycle.RUNTIME)
public static String getWarningBody() {
return i18n("prs.warning", HOME_PAGE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.burningtnt.hmclprs.impl;
package net.burningtnt.hmclprs;

public final class FinalValue<T> {
private volatile T value;
Expand Down
145 changes: 0 additions & 145 deletions HMCL/src/main/java/net/burningtnt/hmclprs/PRCollection.java

This file was deleted.

30 changes: 0 additions & 30 deletions HMCL/src/main/java/net/burningtnt/hmclprs/hooks/EntryPoint.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.burningtnt.hmclprs.hooks;

import net.burningtnt.hmclprs.Constants;
import net.burningtnt.hmclprs.patch.Inject;
import net.burningtnt.hmclprs.patch.Redirect;
import net.burningtnt.hmclprs.patch.ValueMutation;

import javax.swing.*;

public final class PRCollectionBootstrap {
private PRCollectionBootstrap() {
}

@Inject
public static void onApplicationLaunch() {
if (Constants.SHOULD_DISPLAY_LAUNCH_WARNING && JOptionPane.showConfirmDialog(
null, Constants.getWarningBody(), Constants.getWarningTitle(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE
) != JOptionPane.OK_OPTION) {
System.exit(1);
}
}

@ValueMutation
public static String onInitApplicationName(String name) {
return name + Constants.PR_COLLECTION_SUFFIX;
}

@ValueMutation
public static String onInitApplicationFullName(String fullName) {
Constants.DEFAULT_FULL_NAME.setValue(fullName);
return fullName + Constants.PR_COLLECTION_SUFFIX;
}

@ValueMutation
public static String onInitApplicationVersion(String version) {
Constants.DEFAULT_VERSION.setValue(version);
return version + Constants.PR_COLLECTION_SUFFIX;
}

@Redirect
public static String onInitApplicationTitle() {
return Constants.DEFAULT_FULL_NAME.getValue() + " v" + Constants.DEFAULT_VERSION.getValue() + Constants.PR_COLLECTION_SUFFIX;
}

@Redirect
public static String onInitApplicationPublishURL() {
return Constants.HOME_PAGE;
}

@Redirect
public static String onInitApplicationDefaultUpdateLink() {
return Constants.UPDATE_LINK;
}

@Inject
public static void importRef(Class<?> clazz) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package net.burningtnt.hmclprs.hooks;

import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import net.burningtnt.hmclprs.Constants;
import net.burningtnt.hmclprs.patch.Inject;
import net.burningtnt.hmclprs.patch.Redirect;
import net.burningtnt.hmclprs.patch.ValueMutation;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
import org.jackhuang.hmcl.ui.animation.TransitionPane;
import org.jackhuang.hmcl.ui.construct.AnnouncementCard;
import org.jackhuang.hmcl.upgrade.RemoteVersion;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class PRCollectionRuntime {
private PRCollectionRuntime() {
}

@Redirect
public static String onGetApplicationRawVersion() {
return Constants.DEFAULT_VERSION.getValue();
}

@ValueMutation
public static String onInitDisableSelfIntegrityCheckProperty(String value) {
return value == null ? "true" : value;
}

@Redirect
public static TransitionPane onBuildAnnouncementPane(ObservableList<Node> nodes) {
if (!Constants.SHOULD_DISPLAY_LAUNCH_WARNING) {
return null;
}

VBox box = new VBox(16);
box.getChildren().add(new AnnouncementCard(Constants.getWarningTitle(), Constants.getWarningBody(), null));

TransitionPane pane = new TransitionPane();
pane.setContent(box, ContainerAnimations.NONE);

nodes.add(pane);
return pane;
}

@Redirect
public static List<String> prepareFallbackURLs(RemoteVersion rv) {
if (rv.getChannel() == null) {
return Collections.emptyList();
}

return Arrays.stream(Constants.UPDATE_FALLBACKS).parallel().map(s -> {
try {
RemoteVersion r = RemoteVersion.fetch(null, s);
FileDownloadTask.IntegrityCheck r1 = r.getIntegrityCheck(), r2 = rv.getIntegrityCheck();
if (!Objects.equals(r1.getAlgorithm(), r2.getAlgorithm()) || !Objects.equals(r1.getChecksum(), r2.getChecksum())) {
return null;
}

return r.getUrl();
} catch (IOException e) {
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
}

@Redirect
public static List<URL> onGetRemoteVersionUpdateLinks(RemoteVersion rv) {
return Stream.concat(Stream.of(rv.getUrl()), rv.prc$fallbackURL.stream()).map(s -> {
try {
return new URL(s);
} catch (MalformedURLException e) {
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
}

@Inject
public static void onCreateUpgradeDialog() {
throw new UnsupportedOperationException("UpdateDialog has been deprecated");
}
}
9 changes: 9 additions & 0 deletions HMCL/src/main/java/net/burningtnt/hmclprs/patch/Inject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.burningtnt.hmclprs.patch;

import java.lang.annotation.*;

@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface Inject {
}
9 changes: 9 additions & 0 deletions HMCL/src/main/java/net/burningtnt/hmclprs/patch/Redirect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.burningtnt.hmclprs.patch;

import java.lang.annotation.*;

@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface Redirect {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.burningtnt.hmclprs.patch;

import java.lang.annotation.*;

@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface ValueMutation {
}
Loading

0 comments on commit 639d5b1

Please sign in to comment.