forked from HMCL-dev/HMCL
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squash PR Collection commit history.
- Loading branch information
1 parent
eae2670
commit 85e1864
Showing
15 changed files
with
257 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
HMCL/src/main/java/net/burningtnt/hmclprs/PRCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
HMCL/src/main/java/net/burningtnt/hmclprs/PRCollectionConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
HMCL/src/main/java/net/burningtnt/hmclprs/hooks/EntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
HMCL/src/main/java/net/burningtnt/hmclprs/hooks/Final.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
HMCL/src/main/java/net/burningtnt/hmclprs/hooks/HookContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters