4242import com .javadeobfuscator .deobfuscator .ui .component .SynchronousJFXCaller ;
4343import com .javadeobfuscator .deobfuscator .ui .component .SynchronousJFXFileChooser ;
4444import com .javadeobfuscator .deobfuscator .ui .component .WrapLayout ;
45+ import com .javadeobfuscator .deobfuscator .ui .util .ExceptionUtil ;
4546import com .javadeobfuscator .deobfuscator .ui .util .FallbackException ;
4647import com .javadeobfuscator .deobfuscator .ui .util .InvalidJarException ;
4748import com .javadeobfuscator .deobfuscator .ui .util .TransformerConfigUtil ;
@@ -64,41 +65,47 @@ public class SwingWindow
6465 private static final Map <Class <?>, String > TRANSFORMER_TO_NAME = new HashMap <>();
6566 private static final Map <String , Class <?>> NAME_TO_TRANSFORMER = new HashMap <>();
6667 private static DefaultListModel <TransformerWithConfig > transformerSelected ;
68+ private static boolean swingLafLoaded = false ;
69+ public static Thread mainThread ;
70+ private static List <ConfigItem > configFieldsList ;
6771
6872 public static void main (String [] args )
6973 {
70- try
71- {
72- SynchronousJFXCaller .init ();
73- } catch (NoClassDefFoundError e )
74+ mainThread = Thread .currentThread ();
75+ Thread loaderThread = new Thread ("Deobfuscator Jar Loader Thread" )
7476 {
75- e . printStackTrace ();
76- try
77+ @ Override
78+ public void run ()
7779 {
78- UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
79- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e2 )
80+ loadWrappers ();
81+ }
82+ };
83+ loaderThread .start ();
84+ Thread jfxInitThread = new Thread ("JavaFX Init Thread" )
85+ {
86+ @ Override
87+ public void run ()
8088 {
81- e2 .printStackTrace ();
89+ try
90+ {
91+ SynchronousJFXCaller .init ();
92+ } catch (NoClassDefFoundError e )
93+ {
94+ e .printStackTrace ();
95+ ensureSwingLafLoaded ();
96+ ExceptionUtil .showFatalError ("You need a JVM with JavaFX (an non-headless installation).\n \n " +
97+ "Could not find class " + e .getMessage ());
98+ System .exit (1 );
99+ }
82100 }
83- JOptionPane .showMessageDialog (null , "You need a JVM with JavaFX (an non-headless installation).\n \n " +
84- "Could not find class " + e .getMessage (), "Deobfuscator GUI" , JOptionPane .ERROR_MESSAGE );
85- System .exit (1 );
86- return ;
87- }
101+ };
88102 GuiConfig .read ();
89- try
90- {
91- UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
92- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e )
93- {
94- e .printStackTrace ();
95- }
103+ ensureSwingLafLoaded ();
96104 if (GuiConfig .isDarkLaf ())
97105 {
98106 installDarkLaf ();
99107 }
100- loadWrappers ();
101- List <ConfigItem > fields = new SwingConfiguration (config .get ()).fieldsList ;
108+
102109 //Initial frame
103110 JFrame frame = new JFrame ();
104111 frame .setTitle ("Deobfuscator GUI" );
@@ -134,7 +141,7 @@ public void actionPerformed(ActionEvent e)
134141 return ;
135142 }
136143 GuiConfig .setDarkLaf (false );
137- writeAndSaveGuiConfig (fields );
144+ writeAndSaveGuiConfig (configFieldsList );
138145 System .exit (0 );
139146 }
140147 }
@@ -183,7 +190,18 @@ public void actionPerformed(ActionEvent e)
183190 inputPnl .setLayout (new GridBagLayout ());
184191
185192 int gridy = 0 ;
186- for (ConfigItem i : fields )
193+
194+ try
195+ {
196+ loaderThread .join ();
197+ } catch (InterruptedException e )
198+ {
199+ ExceptionUtil .showFatalError ("" , new RuntimeException ("Couldn't wait for jar loader thread!" , e ));
200+ System .exit (1 );
201+ }
202+ configFieldsList = new SwingConfiguration (config .get ()).fieldsList ;
203+
204+ for (ConfigItem i : configFieldsList )
187205 {
188206 if (i .type != SwingConfiguration .ItemType .FILE )
189207 continue ;
@@ -245,7 +263,7 @@ public void actionPerformed(ActionEvent e)
245263 }
246264 if (!setDir && i .getDisplayName ().equals ("Output" ))
247265 {
248- Optional <ConfigItem > input = fields .stream ().filter (ci -> ci .getDisplayName ().equals ("Input" )).findAny ();
266+ Optional <ConfigItem > input = configFieldsList .stream ().filter (ci -> ci .getDisplayName ().equals ("Input" )).findAny ();
249267 if (input .isPresent ())
250268 {
251269 Object value2 = input .get ().getValue ();
@@ -300,7 +318,7 @@ public void actionPerformed(ActionEvent e)
300318 inputPnl .add (boolWrapPanel , gbc );
301319 }
302320
303- for (ConfigItem i : fields )
321+ for (ConfigItem i : configFieldsList )
304322 {
305323 if (i .type != ItemType .BOOLEAN )
306324 continue ;
@@ -530,7 +548,7 @@ public void actionPerformed(ActionEvent e)
530548
531549 tabbedPane .addTab ("Transformers" , transformersPanel );
532550
533- for (ConfigItem i : fields )
551+ for (ConfigItem i : configFieldsList )
534552 {
535553 if (i .type != ItemType .FILELIST )
536554 continue ;
@@ -668,7 +686,7 @@ public void keyPressed(KeyEvent event)
668686 tabbedPane .addTab (i .getDisplayName (), libPanel );
669687 }
670688
671- for (ConfigItem i : fields )
689+ for (ConfigItem i : configFieldsList )
672690 {
673691 if (i .type != ItemType .STRINGLIST )
674692 continue ;
@@ -879,7 +897,7 @@ public void keyPressed(KeyEvent event)
879897 submitButton .addActionListener (e13 ->
880898 {
881899 String args1 = textPane .getText ();
882- readAndApplyConfig (fields , transformerSelected , args1 );
900+ readAndApplyConfig (configFieldsList , transformerSelected , args1 );
883901 loadConfigFrame .dispose ();
884902 });
885903 loadConfigFrame .setVisible (true );
@@ -928,7 +946,7 @@ public void keyPressed(KeyEvent event)
928946 saveConfigFrame .getContentPane ().add (scrollPane , gbc_scrollPane );
929947
930948 //Write args
931- String t = createConfig (fields , transformerSelected );
949+ String t = createConfig (configFieldsList , transformerSelected );
932950 textPane .setText (t );
933951
934952 JButton copyButton = new JButton ("Copy" );
@@ -973,7 +991,7 @@ public void keyPressed(KeyEvent event)
973991 try
974992 {
975993 //Set fields
976- for (ConfigItem item : fields )
994+ for (ConfigItem item : configFieldsList )
977995 {
978996 item .clearFieldValue ();
979997 item .setFieldValue ();
@@ -1090,20 +1108,42 @@ public void windowClosing(WindowEvent e)
10901108
10911109 if (GuiConfig .getStoreConfigOnClose ())
10921110 {
1093- readAndApplyConfig (fields , transformerSelected , GuiConfig .getConfig ());
1111+ readAndApplyConfig (configFieldsList , transformerSelected , GuiConfig .getConfig ());
10941112 }
10951113 frame .addWindowListener (new WindowAdapter ()
10961114 {
10971115 @ Override
10981116 public void windowClosing (WindowEvent e )
10991117 {
1100- writeAndSaveGuiConfig (fields );
1118+ writeAndSaveGuiConfig (configFieldsList );
11011119 }
11021120 });
11031121
1122+ try
1123+ {
1124+ jfxInitThread .join ();
1125+ } catch (InterruptedException e )
1126+ {
1127+ ExceptionUtil .showFatalError ("" , new RuntimeException ("Couldn't wait for jfx init thread" , e ));
1128+ }
11041129 frame .setVisible (true );
11051130 }
11061131
1132+ public static synchronized void ensureSwingLafLoaded ()
1133+ {
1134+ if (!swingLafLoaded )
1135+ {
1136+ swingLafLoaded = true ;
1137+ try
1138+ {
1139+ UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
1140+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e )
1141+ {
1142+ e .printStackTrace ();
1143+ }
1144+ }
1145+ }
1146+
11071147 private static void installDarkLaf ()
11081148 {
11091149 ThemeSettings .getInstance ().setConfiguration (GuiConfig .getDarklafSettings ());
0 commit comments