-
Notifications
You must be signed in to change notification settings - Fork 534
Expand file tree
/
Copy pathUIMain.java
More file actions
125 lines (110 loc) · 4.03 KB
/
Copy pathUIMain.java
File metadata and controls
125 lines (110 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package software.coley.recaf;
import jakarta.annotation.Nonnull;
import software.coley.fxaccess.AccessCheck;
import software.coley.recaf.launch.LaunchArguments;
import software.coley.recaf.launch.LaunchBootstrap;
import software.coley.recaf.launch.LaunchCommand;
import software.coley.recaf.services.plugin.PluginContainer;
import software.coley.recaf.services.plugin.PluginManager;
import software.coley.recaf.util.JFXValidation;
import software.coley.recaf.util.Lang;
import java.util.List;
/**
* UI-specific launch pipeline for Recaf.
*
* @author Matt Coley
*/
public class UIMain {
/**
* Delegate to the main entry point in the core module.
* <br>
* This largely exists so you can easily create IntelliJ run configurations without any effort.
* Just right-click and run this class.
*
* @param args
* Application arguments.
*/
public static void main(String[] args) {
Main.main(args);
}
/**
* Launch the UI runtime using already parsed launch arguments.
*
* @param launchArgValues
* Parsed launch arguments.
* @param args
* Raw application arguments.
*/
public static void launch(@Nonnull LaunchCommand launchArgValues, @Nonnull String[] args) {
// Add a class reference for our UI module.
// This will get Weld to discover all services/beans in both the UI and core modules.
Bootstrap.setWeldConsumer(weld -> weld.addPackage(true, UIMain.class));
// Validate the JFX environment is available if not running in headless mode.
// Abort if not available.
int validationCode = JFXValidation.validateJFX();
if (validationCode != 0) {
ExitDebugLoggingHook.exit(validationCode);
return;
}
// Initialize the CDI container.
LaunchBootstrap launchBootstrap = new LaunchBootstrap(launchArgValues, args);
Recaf recaf = launchBootstrap.bootstrap();
// Invoke the launcher handler with headless=false since we're launching the UI.
LaunchArguments launchArgs = launchBootstrap.getLaunchArguments();
launchBootstrap.setupLaunchHandler(false);
// Continue with the rest of the UI initialization and launch.
initialize(recaf, launchArgs, launchBootstrap);
}
/**
* Initialize the UI application.
*/
private static void initialize(@Nonnull Recaf recaf,
@Nonnull LaunchArguments launchArgs,
@Nonnull LaunchBootstrap launchBootstrap) {
launchBootstrap.initLogging();
initFxAccessAgent();
initTranslations();
launchBootstrap.initPlugins();
initPluginTranslations(recaf);
launchBootstrap.fireInitEvent();
RecafApplication.launch(RecafApplication.class, launchArgs.getArgs());
}
/**
* Configure the JavaFX access logging agent.
* The logging is only active when the agent is passed as a launch argument to Recaf.
* <br>
* Example usage: {@code -javaagent:javafx-access-agent.jar=software/;org/;com/;javafx/}
*/
private static void initFxAccessAgent() {
AccessCheck.addAccessCheckListener((className, methodName, lineNumber, threadName, calledMethodSignature) -> {
// Some kinds of operations are safe and can be ignored.
if (calledMethodSignature != null) {
// Skip on constructors
if (calledMethodSignature.contains("<"))
return;
// Skip on get operations
if (calledMethodSignature.contains("#get"))
return;
// Skip on things that will be operated on later
if (calledMethodSignature.contains("#setOn") || calledMethodSignature.contains("#addListener"))
return;
}
System.err.printf("[thread:%s] %s.%s (line %d) - %s\n", threadName, className, methodName, lineNumber, calledMethodSignature);
});
}
/**
* Load translations.
*/
private static void initTranslations() {
Lang.initialize();
}
/**
* Load plugins.
*/
private static void initPluginTranslations(@Nonnull Recaf recaf) {
PluginManager pluginManager = recaf.get(PluginManager.class);
List<String> localeKeys = List.copyOf(Lang.getTranslationKeys());
for (PluginContainer<?> plugin : pluginManager.getPlugins())
Lang.loadPlugin(plugin.info().id(), plugin.plugin().getClass().getClassLoader(), localeKeys);
}
}