fix(gui): load plugins settings in temp context without UI (#2206)
This commit is contained in:
@@ -7,16 +7,17 @@ import java.util.TreeSet;
|
||||
|
||||
import jadx.api.JadxArgs;
|
||||
import jadx.api.JadxDecompiler;
|
||||
import jadx.cli.plugins.JadxFilesGetter;
|
||||
import jadx.core.plugins.AppContext;
|
||||
import jadx.core.plugins.JadxPluginManager;
|
||||
import jadx.core.plugins.PluginContext;
|
||||
import jadx.gui.JadxWrapper;
|
||||
import jadx.gui.ui.MainWindow;
|
||||
import jadx.plugins.tools.JadxExternalPluginsLoader;
|
||||
|
||||
/**
|
||||
* Collect all plugins.
|
||||
* Init not yet loaded plugins in new temporary context.
|
||||
* Support case if decompiler in wrapper not initialized yet.
|
||||
* Support a case if decompiler in wrapper is not initialized yet.
|
||||
*/
|
||||
public class CollectPlugins {
|
||||
|
||||
@@ -31,19 +32,26 @@ public class CollectPlugins {
|
||||
mainWindow.getWrapper().getCurrentDecompiler()
|
||||
.ifPresent(decompiler -> allPlugins.addAll(decompiler.getPluginManager().getResolvedPluginContexts()));
|
||||
|
||||
// collect and init not loaded plugins in new context
|
||||
// collect and init not loaded plugins in new temp context
|
||||
try (JadxDecompiler decompiler = new JadxDecompiler(new JadxArgs())) {
|
||||
JadxPluginManager pluginManager = decompiler.getPluginManager();
|
||||
pluginManager.registerAddPluginListener(pluginContext -> {
|
||||
AppContext appContext = new AppContext();
|
||||
appContext.setGuiContext(null); // load temp plugins without UI context
|
||||
appContext.setFilesGetter(JadxFilesGetter.INSTANCE);
|
||||
pluginContext.setAppContext(appContext);
|
||||
});
|
||||
pluginManager.load(new JadxExternalPluginsLoader());
|
||||
JadxWrapper.initGuiPluginsContext(decompiler, mainWindow);
|
||||
SortedSet<PluginContext> missingPlugins = new TreeSet<>();
|
||||
for (PluginContext context : pluginManager.getAllPluginContexts()) {
|
||||
if (!allPlugins.contains(context)) {
|
||||
missingPlugins.add(context);
|
||||
}
|
||||
}
|
||||
pluginManager.init(missingPlugins);
|
||||
allPlugins.addAll(missingPlugins);
|
||||
if (!missingPlugins.isEmpty()) {
|
||||
pluginManager.init(missingPlugins);
|
||||
allPlugins.addAll(missingPlugins);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(allPlugins);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user