Skip to content

Commit

Permalink
Squash PR Collection commit history.
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Oct 24, 2024
1 parent eae2670 commit 85e1864
Show file tree
Hide file tree
Showing 15 changed files with 257 additions and 18 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Java CI

permissions:
actions: write

on:
push:
pull_request:
Expand Down Expand Up @@ -33,3 +36,12 @@ jobs:
with:
name: HMCL-${{ env.SHORT_SHA }}
path: HMCL/build/libs
- name: Get Git Branch name
run: echo "BRANCH_NAME=$BN_TEMP" >> $GITHUB_ENV
env:
BN_TEMP: ${{ github.head_ref || github.ref_name }}
- name: Trigger HMCL Snapshot Update
if: ${{ env.BRANCH_NAME == 'prs' && github.event_name == 'push' }}
run: gh workflow --repo burningtnt/HMCL-Snapshot-Update run check.yml
env:
GH_TOKEN: ${{ secrets.HMCL_PR_COLLECTION_GITHUB_TOKEN }}
94 changes: 94 additions & 0 deletions HMCL/src/main/java/net/burningtnt/hmclprs/PRCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package net.burningtnt.hmclprs;

import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import net.burningtnt.hmclprs.hooks.EntryPoint;
import net.burningtnt.hmclprs.hooks.Final;
import net.burningtnt.hmclprs.hooks.HookContainer;
import org.jackhuang.hmcl.ui.construct.AnnouncementCard;

import javax.swing.*;

@HookContainer
public final class PRCollection {
private PRCollection() {
}

@Final
private static volatile String defaultFullName;

@Final
private static volatile String defaultVersion;

@EntryPoint(when = EntryPoint.LifeCycle.BOOTSTRAP, type = EntryPoint.Type.INJECT)
public static void onApplicationLaunch() {
if (PRCollectionConstants.SHOULD_DISPLAY_LAUNCH_WARNING && JOptionPane.showConfirmDialog(
null, PRCollectionConstants.getWarningBody(), PRCollectionConstants.getWarningTitle(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE
) != JOptionPane.OK_OPTION) {
System.exit(1);
}
}

@EntryPoint(when = EntryPoint.LifeCycle.BOOTSTRAP, type = EntryPoint.Type.VALUE_MUTATION)
public static String onInitApplicationName(String name) {
return name + PRCollectionConstants.PR_COLLECTION_SUFFIX;
}

@EntryPoint(when = EntryPoint.LifeCycle.BOOTSTRAP, type = EntryPoint.Type.VALUE_MUTATION)
public static String onInitApplicationFullName(String fullName) {
defaultFullName = fullName;
return fullName + PRCollectionConstants.PR_COLLECTION_SUFFIX;
}

@EntryPoint(when = EntryPoint.LifeCycle.BOOTSTRAP, type = EntryPoint.Type.VALUE_MUTATION)
public static String onInitApplicationVersion(String version) {
defaultVersion = version;
return version + PRCollectionConstants.PR_COLLECTION_SUFFIX;
}

@EntryPoint(when = EntryPoint.LifeCycle.BOOTSTRAP, type = EntryPoint.Type.REDIRECT)
public static String onInitApplicationTitle() {
return defaultFullName + " v" + defaultVersion + PRCollectionConstants.PR_COLLECTION_SUFFIX;
}

@EntryPoint(when = EntryPoint.LifeCycle.BOOTSTRAP, type = EntryPoint.Type.REDIRECT)
public static String onInitApplicationPublishURL() {
return PRCollectionConstants.HOME_PAGE;
}

@EntryPoint(when = EntryPoint.LifeCycle.BOOTSTRAP, type = EntryPoint.Type.REDIRECT)
public static String onInitApplicationDefaultUpdateLink() {
return PRCollectionConstants.UPDATE_LINK;
}

@EntryPoint(when = EntryPoint.LifeCycle.RUNTIME, type = EntryPoint.Type.REDIRECT)
public static String onGetApplicationRawVersion() {
return defaultVersion;
}

@EntryPoint(when = EntryPoint.LifeCycle.RUNTIME, type = EntryPoint.Type.VALUE_MUTATION)
public static String onInitDisableSelfIntegrityCheckProperty(String value) {
return value == null ? "true" : value;
}

@EntryPoint(when = EntryPoint.LifeCycle.RUNTIME, type = EntryPoint.Type.REDIRECT)
public static VBox onBuildAnnouncementPane(ObservableList<Node> nodes) {
VBox pane = new VBox(16);
if (PRCollectionConstants.SHOULD_DISPLAY_LAUNCH_WARNING) {
pane.getChildren().add(new AnnouncementCard(PRCollectionConstants.getWarningTitle(), PRCollectionConstants.getWarningBody()));
nodes.add(pane);
}
return pane;
}

@EntryPoint(when = EntryPoint.LifeCycle.RUNTIME, type = EntryPoint.Type.INJECT)
public static void onUpdateFrom(Runnable updateRunnable) {
Platform.runLater(updateRunnable);
}

@EntryPoint(when = EntryPoint.LifeCycle.RUNTIME, type = EntryPoint.Type.INJECT)
public static void importRef(Class<?> clazz) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.burningtnt.hmclprs;

import net.burningtnt.hmclprs.hooks.EntryPoint;

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

final class PRCollectionConstants {
private PRCollectionConstants() {
}

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

static final String HOME_PAGE = "https://github.com/burningtnt/HMCL/pull/9";

static final String UPDATE_LINK = "https://hmcl-snapshot-update-73w.pages.dev/redirect/v1/type/pr-collection";

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

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

@EntryPoint(when = EntryPoint.LifeCycle.RUNTIME)
static String getWarningBody() {
return i18n("prs.warning", HOME_PAGE);
}

private static boolean shouldDisplayWarningMessage(String propertyKey, String envKey) {
String p1 = System.getProperty(propertyKey);
if (p1 != null) {
switch (p1) {
case "ignore": {
return false;
}
case "display": {
return true;
}
default: {
throw new IllegalArgumentException(String.format("Property %s should only be 'ignore', 'display', or null.", propertyKey));
}
}
}

String p2 = System.getenv(envKey);
if (p2 == null) {
return true;
}
switch (p2) {
case "ignore": {
return false;
}
case "display": {
return true;
}
default: {
throw new IllegalArgumentException(String.format("Environmental argument %s should only be 'ignore', 'display', or null.", envKey));
}
}
}
}
32 changes: 32 additions & 0 deletions HMCL/src/main/java/net/burningtnt/hmclprs/hooks/EntryPoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.burningtnt.hmclprs.hooks;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface EntryPoint {
LifeCycle when();

Type type() default Type.INVALID;

enum LifeCycle {
/**
* Invoked before Application launches. Be careful while using packages from HMCL project.
*/
BOOTSTRAP,
/**
* Invoked after Application launches. All packages from HMCL project is available.
*/
RUNTIME
}

enum Type {
INJECT,
VALUE_MUTATION,
REDIRECT,
INVALID
}
}
14 changes: 14 additions & 0 deletions HMCL/src/main/java/net/burningtnt/hmclprs/hooks/Final.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.burningtnt.hmclprs.hooks;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This field should ONLY be set once when initializing the application.
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.CLASS)
public @interface Final {
}
11 changes: 11 additions & 0 deletions HMCL/src/main/java/net/burningtnt/hmclprs/hooks/HookContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.burningtnt.hmclprs.hooks;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
public @interface HookContainer {
}
2 changes: 2 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ private Main() {
}

public static void main(String[] args) {
net.burningtnt.hmclprs.PRCollection.onApplicationLaunch();

System.getProperties().putIfAbsent("java.net.useSystemProxies", "true");
System.getProperties().putIfAbsent("javafx.autoproxy.disable", "true");
System.getProperties().putIfAbsent("http.agent", "HMCL/" + Metadata.VERSION);
Expand Down
12 changes: 6 additions & 6 deletions HMCL/src/main/java/org/jackhuang/hmcl/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
public final class Metadata {
private Metadata() {}

public static final String NAME = "HMCL";
public static final String FULL_NAME = "Hello Minecraft! Launcher";
public static final String VERSION = System.getProperty("hmcl.version.override", JarUtils.getManifestAttribute("Implementation-Version", "@develop@"));
public static final String NAME = net.burningtnt.hmclprs.PRCollection.onInitApplicationName("HMCL");
public static final String FULL_NAME = net.burningtnt.hmclprs.PRCollection.onInitApplicationFullName("Hello Minecraft! Launcher");
public static final String VERSION = net.burningtnt.hmclprs.PRCollection.onInitApplicationVersion(System.getProperty("hmcl.version.override", JarUtils.getManifestAttribute("Implementation-Version", "@develop@")));

public static final String TITLE = NAME + " " + VERSION;
public static final String FULL_TITLE = FULL_NAME + " v" + VERSION;
public static final String FULL_TITLE = net.burningtnt.hmclprs.PRCollection.onInitApplicationTitle();

public static final String HMCL_UPDATE_URL = System.getProperty("hmcl.update_source.override", "https://hmcl.huangyuhui.net/api/update_link");
public static final String HMCL_UPDATE_URL = System.getProperty("hmcl.update_source.override", net.burningtnt.hmclprs.PRCollection.onInitApplicationDefaultUpdateLink());
public static final String CONTACT_URL = "https://docs.hmcl.net/help.html";
public static final String HELP_URL = "https://docs.hmcl.net";
public static final String CHANGELOG_URL = "https://docs.hmcl.net/changelog/";
public static final String PUBLISH_URL = "https://hmcl.huangyuhui.net";
public static final String PUBLISH_URL = net.burningtnt.hmclprs.PRCollection.onInitApplicationPublishURL();
public static final String EULA_URL = "https://docs.hmcl.net/eula/hmcl.html";

public static final String BUILD_CHANNEL = JarUtils.getManifestAttribute("Build-Channel", "nightly");
Expand Down
2 changes: 2 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/UpgradeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@ public UpgradeDialog(RemoteVersion remoteVersion, Runnable updateRunnable) {

setActions(openInBrowser, updateButton, cancelButton);
onEscPressed(this, cancelButton::fire);

net.burningtnt.hmclprs.PRCollection.onUpdateFrom(updateRunnable);
}
}
11 changes: 2 additions & 9 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,8 @@ public final class MainPage extends StackPane implements DecoratorPage {

setPadding(new Insets(20));

if (Metadata.isNightly() || (Metadata.isDev() && !Objects.equals(Metadata.VERSION, config().getShownTips().get(ANNOUNCEMENT)))) {
announcementPane = new VBox(16);
if (Metadata.isNightly()) {
announcementPane.getChildren().add(new AnnouncementCard(i18n("update.channel.nightly.title"), i18n("update.channel.nightly.hint")));
} else if (Metadata.isDev()) {
announcementPane.getChildren().add(new AnnouncementCard(i18n("update.channel.dev.title"), i18n("update.channel.dev.hint")));
}
getChildren().add(announcementPane);
}
announcementPane = net.burningtnt.hmclprs.PRCollection.onBuildAnnouncementPane(getChildren());
net.burningtnt.hmclprs.PRCollection.importRef(AnnouncementCard.class);

updatePane = new StackPane();
updatePane.setVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public final class IntegrityChecker {
private IntegrityChecker() {}

public static final boolean DISABLE_SELF_INTEGRITY_CHECK = "true".equals(System.getProperty("hmcl.self_integrity_check.disable"));
public static final boolean DISABLE_SELF_INTEGRITY_CHECK = "true".equals(net.burningtnt.hmclprs.PRCollection.onInitDisableSelfIntegrityCheckProperty(System.getProperty("hmcl.self_integrity_check.disable")));

private static final String SIGNATURE_FILE = "META-INF/hmcl_signature";
private static final String PUBLIC_KEY_FILE = "assets/hmcl_signature_publickey.der";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ private UpdateChecker() {}
|| Metadata.isNightly()
|| latest.getChannel() == UpdateChannel.NIGHTLY
|| latest.getChannel() != UpdateChannel.getChannel()) {
return !latest.getVersion().equals(Metadata.VERSION);
return !latest.getVersion().equals(net.burningtnt.hmclprs.PRCollection.onGetApplicationRawVersion());
} else {
return VersionNumber.compare(Metadata.VERSION, latest.getVersion()) < 0;
return VersionNumber.compare(net.burningtnt.hmclprs.PRCollection.onGetApplicationRawVersion(), latest.getVersion()) < 0;
}
},
latestVersion);
Expand Down
6 changes: 6 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1309,3 +1309,9 @@ wizard.prev=< Prev
wizard.failed=Failed
wizard.finish=Finish
wizard.next=Next >

prs.title=Warning: PR Collection is Unofficial
prs.warning=You are using an unofficial version of HMCL, including many developing features and bug fixes. \n\
The reason why the name of this application is still HMCL is for compatibility.\n\
If you don't know what you are doing, please close this application immediately and download the official build! Please use this application ONLY IF you have made sure you understand this description! \n\
Go to %s for more information (including how to suppress this warning).
6 changes: 6 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1164,3 +1164,9 @@ wizard.prev=< 上一步
wizard.failed=失敗
wizard.finish=完成
wizard.next=下一步 >

prs.title=警告:非官方的 PR Collection 版本
prs.warning=你正在使用非官方的 HMCL 版本,包含許多測試中的新功能和錯誤修復。\n\
本應用程式的名稱仍然為 HMCL,這是處於相容性的考慮因素。\n\
如果你不知道自己在做什麼,請立刻關閉本應用程式,並下載官方版本。請僅在你已經確保理解了本段文字的情況下繼續使用本應用程式!\n\
可前往 %s 以取得更多資訊(包括如何壓制該警告)。
6 changes: 6 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1165,3 +1165,9 @@ wizard.prev=< 上一步
wizard.failed=失败
wizard.finish=完成
wizard.next=下一步 >

prs.title=警告:非官方的 PR Collection 版本
prs.warning=你正在使用非官方的 HMCL 版本,包含许多测试中的新功能和错误修复。\n\
本应用的名称仍然为 HMCL,这是处于兼容性的考虑。\n\
如果你不知道自己在做什么,请立刻关闭本应用,并下载官方版本!请仅在你已经确保理解了本段文字的情况下继续使用本应用!\n\
可前往 %s 获取更多信息(包括如何压制该警告)。

0 comments on commit 85e1864

Please sign in to comment.